Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4476d0c45f7bedc11191c5ab4bfc686648321258 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**********************************************************************
 * This file is part of "Object Teams Development Tooling"-Software
 * 
 * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
 * for its Fraunhofer Institute and Computer Architecture and Software
 * Technology (FIRST), Berlin, Germany and Technical University Berlin,
 * Germany.
 * 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Please visit http://www.eclipse.org/objectteams for updates and contact.
 * 
 * Contributors:
 * 	  Fraunhofer FIRST - Initial API and implementation
 * 	  Technical University Berlin - Initial API and implementation
 **********************************************************************/
package org.eclipse.objectteams.otdt.ui.tests.dom.converter;


import java.util.Iterator;
import java.util.List;

import junit.framework.Test;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTMatcher;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.TSuperConstructorInvocation;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.objectteams.otdt.ui.tests.dom.FileBasedDOMTest;


/**
 * @author mkr
 * @version $Id: TSuperConstructorInvocationTest.java 23496 2010-02-05 23:20:15Z stephan $
 */
public class TSuperConstructorInvocationTest extends FileBasedDOMTest
{
    public static final String TEST_PROJECT = "DOM_AST";
    private static final int JAVA_LANGUAGE_SPEC_LEVEL = AST.JLS4;

    /** Java class used for all within tests */
    private TypeDeclaration _role;
    private TypeDeclaration _typeDecl;
    private MethodDeclaration _constructor0;
    private MethodDeclaration _constructor1;
    private Statement _tsuper0;
    private Statement _tsuper1;
    
    
    private TSuperConstructorInvocation _testObj;

    public TSuperConstructorInvocationTest(String name)
	{
		super(name);
	}
	
	public static Test suite()
	{
		return new Suite(TSuperConstructorInvocationTest.class);
	}
	
	public void setUpSuite() throws Exception
	{
		setTestProjectDir(TEST_PROJECT);
		super.setUpSuite();
		ICompilationUnit _teamClass = getCompilationUnit(
	                                      getTestProjectDir(),
	                                      "src",
	                                      "tsupercall.teampkg",
	                                      "Team1.java");
		ASTParser parser = ASTParser.newParser(JAVA_LANGUAGE_SPEC_LEVEL);
		parser.setProject( getJavaProject(TEST_PROJECT) );
		parser.setSource(_teamClass);
        parser.setResolveBindings(true);
        
		ASTNode root = parser.createAST( new NullProgressMonitor() );        
        CompilationUnit compUnit = (CompilationUnit) root;
        _typeDecl = (TypeDeclaration)compUnit.types().get(0);

        _role = _typeDecl.getTypes()[0];
        _constructor0 = _role.getMethods()[0];
        _constructor1 = _role.getMethods()[1];
        _tsuper0 = (Statement)_constructor0.getBody().statements().get(0);
        _tsuper1 = (Statement)_constructor1.getBody().statements().get(0);

	}

	protected void setUp() throws Exception 
	{
		super.setUp();
	}

    
    public void testInstanceType1()
    {
        assertTrue("tsuper call not an instance of TSuperConstructorInvocation",
                   _tsuper0 instanceof TSuperConstructorInvocation);
    }

    public void testInstanceType2()
    {
        assertTrue("tsuper call not an instance of TSuperConstructorInvocation",
                   _tsuper1 instanceof TSuperConstructorInvocation);
    }

    public void testNodeType1()
    {
        _testObj = (TSuperConstructorInvocation)_tsuper1;
        
        int actual = _testObj.getNodeType();
        
        assertEquals("tsuper call has wrong node type",
                     ASTNode.TSUPER_CONSTRUCTOR_INVOCATION,
                     actual);
    }

   
    public void testGetArguments2_TwoArgs()
    {
        _testObj = (TSuperConstructorInvocation)_tsuper1;
        
        List actual = _testObj.getArguments();
        
        assertEquals("tsuper call has wrong number of arguments",
                     2,
                     actual.size());
    }

    public void testGetArguments1_NoArgs()
    {
        _testObj = (TSuperConstructorInvocation)_tsuper0;
        
        List actual = _testObj.getArguments();
        
        assertEquals("tsuper call has wrong number of arguments",
                     0,
                     actual.size());
    }

    public void testChildNodesHaveCorrectParent1()
    {
        _testObj = (TSuperConstructorInvocation)_tsuper1;
        
        List childNodes = _testObj.getArguments();

        for (Iterator iter = childNodes.iterator(); iter.hasNext();) 
        {
            Expression curChild = (Expression) iter.next();
            assertEquals("tsuper call arguments have wrong parent node",
                         _testObj,
                         curChild.getParent());
        }

    }
     
    public void testSubtreeMatch1()
    {
        _testObj = (TSuperConstructorInvocation)_tsuper1;
        
        boolean actual = _testObj.subtreeMatch(new ASTMatcher(), _testObj);

        assertTrue("tsuper call message sends don't match", actual);
 
    }

    public void testToString1()
    {
        _testObj = (TSuperConstructorInvocation)_tsuper1;
        
        String actual = _testObj.toString();
        String expected = "tsuper(arg0, arg1)";
        
        assertEquals(
            "tsuper call message send: wrong naive flat string representation",
            expected, 
            actual);
    }
    
    public void testResolveBinding()
    {
        _testObj = (TSuperConstructorInvocation)_tsuper1;
        
        ITypeBinding itb = _typeDecl.resolveBinding();
        ITypeBinding tsuperRoleClass = null;
        for (ITypeBinding role : itb.getSuperclass().getDeclaredTypes()) {
        	if (role.isClass() && role.getName().equals("Role0")) {
        		tsuperRoleClass = role;
        		break;
        	}
        }
        assertNotNull("tsuper Role not found", tsuperRoleClass);
        IMethodBinding tSuperConstructor =
            tsuperRoleClass.getDeclaredMethods()[1];
        
        IMethodBinding expected = tSuperConstructor;
        IMethodBinding actual = _testObj.resolveConstructorBinding();
        assertEquals(expected, actual);
    }
        
    
}

Back to the top