View | Details | Raw Unified | Return to bug 110465 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java (-4 / +19 lines)
Lines 20-25 Link Here
20
import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
20
import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
21
import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
21
import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
22
import org.aspectj.ajdt.internal.compiler.ast.InterTypeConstructorDeclaration;
22
import org.aspectj.ajdt.internal.compiler.ast.InterTypeConstructorDeclaration;
23
import org.aspectj.ajdt.internal.compiler.ast.InterTypeDeclaration;
23
import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
24
import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
24
import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
25
import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
25
import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
26
import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
Lines 204-210 Link Here
204
			return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration);
205
			return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration);
205
		}
206
		}
206
		MethodDeclaration methodDecl = new MethodDeclaration(this.ast);
207
		MethodDeclaration methodDecl = new MethodDeclaration(this.ast);
207
		setModifiers(methodDecl, methodDeclaration);
208
		boolean isConstructor = methodDeclaration.isConstructor();
208
		boolean isConstructor = methodDeclaration.isConstructor();
209
		methodDecl.setConstructor(isConstructor);
209
		methodDecl.setConstructor(isConstructor);
210
		
210
		
Lines 225-236 Link Here
225
		}
225
		}
226
		/////////////////////////
226
		/////////////////////////
227
		
227
		
228
		// set modifiers after checking whether we're an itd, otherwise
229
		// the modifiers are not set on the correct object.
230
		setModifiers(methodDecl, methodDeclaration);
231
232
		// for ITD's use the declaredSelector
228
		final SimpleName methodName = new SimpleName(this.ast);
233
		final SimpleName methodName = new SimpleName(this.ast);
229
		methodName.internalSetIdentifier(new String(methodDeclaration.selector));
234
		if (methodDeclaration instanceof InterTypeDeclaration) {
235
			InterTypeDeclaration itd = (InterTypeDeclaration) methodDeclaration;
236
			methodName.internalSetIdentifier(new String(itd.getDeclaredSelector()));
237
		} else {
238
			methodName.internalSetIdentifier(new String(methodDeclaration.selector));
239
		}
230
		int start = methodDeclaration.sourceStart;
240
		int start = methodDeclaration.sourceStart;
231
		int end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd);
241
		int end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd);
232
		methodName.setSourceRange(start, end - start + 1);
242
		methodName.setSourceRange(start, end - start + 1);
233
		methodDecl.setName(methodName);
243
		methodDecl.setName(methodName);
244
		
234
		org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
245
		org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
235
		if (thrownExceptions != null) {
246
		if (thrownExceptions != null) {
236
			int thrownExceptionsLength = thrownExceptions.length;
247
			int thrownExceptionsLength = thrownExceptions.length;
Lines 3580-3586 Link Here
3580
		// ajh02: method added
3591
		// ajh02: method added
3581
		switch(this.ast.apiLevel) {
3592
		switch(this.ast.apiLevel) {
3582
			case AST.JLS2_INTERNAL :
3593
			case AST.JLS2_INTERNAL :
3583
				fieldDeclaration.internalSetModifiers(fieldDecl.modifiers & CompilerModifiers.AccJustFlag);
3594
				fieldDeclaration.internalSetModifiers(fieldDecl.declaredModifiers & CompilerModifiers.AccJustFlag);
3584
				if (fieldDecl.annotations != null) {
3595
				if (fieldDecl.annotations != null) {
3585
					fieldDeclaration.setFlags(fieldDeclaration.getFlags() | ASTNode.MALFORMED);
3596
					fieldDeclaration.setFlags(fieldDeclaration.getFlags() | ASTNode.MALFORMED);
3586
				}
3597
				}
Lines 3615-3621 Link Here
3615
	protected void setModifiers(MethodDeclaration methodDecl, AbstractMethodDeclaration methodDeclaration) {
3626
	protected void setModifiers(MethodDeclaration methodDecl, AbstractMethodDeclaration methodDeclaration) {
3616
		switch(this.ast.apiLevel) {
3627
		switch(this.ast.apiLevel) {
3617
			case AST.JLS2_INTERNAL :
3628
			case AST.JLS2_INTERNAL :
3618
				methodDecl.internalSetModifiers(methodDeclaration.modifiers & CompilerModifiers.AccJustFlag);
3629
				if (methodDeclaration instanceof InterTypeDeclaration) {
3630
					methodDecl.internalSetModifiers(((InterTypeDeclaration)methodDeclaration).declaredModifiers & CompilerModifiers.AccJustFlag);
3631
				} else {
3632
					methodDecl.internalSetModifiers(methodDeclaration.modifiers & CompilerModifiers.AccJustFlag);
3633
				}
3619
				if (methodDeclaration.annotations != null) {
3634
				if (methodDeclaration.annotations != null) {
3620
					methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
3635
					methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
3621
				}
3636
				}
(-)testsrc/org/aspectj/tools/ajc/AjcTests.java (+1 lines)
Lines 27-32 Link Here
27
        TestSuite suite = new TestSuite(AjcTests.class.getName());
27
        TestSuite suite = new TestSuite(AjcTests.class.getName());
28
        suite.addTestSuite(org.aspectj.tools.ajc.MainTest.class);
28
        suite.addTestSuite(org.aspectj.tools.ajc.MainTest.class);
29
        suite.addTestSuite(ASTVisitorTest.class);
29
        suite.addTestSuite(ASTVisitorTest.class);
30
        suite.addTestSuite(ASTitdTest.class);
30
        return suite;
31
        return suite;
31
    }
32
    }
32
33
(-)testsrc/org/aspectj/tools/ajc/ASTitdTest.java (+94 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2005 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: IBM Corporation - initial API and implementation 
9
 * 				 Helen Hawkins   - iniital version
10
 *******************************************************************/
11
package org.aspectj.tools.ajc;
12
13
import java.lang.reflect.Modifier;
14
import java.util.HashMap;
15
16
import junit.framework.TestCase;
17
18
import org.aspectj.org.eclipse.jdt.core.dom.AST;
19
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
20
import org.aspectj.org.eclipse.jdt.core.dom.AjASTVisitor;
21
import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;
22
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration;
23
import org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration;
24
import org.aspectj.org.eclipse.jdt.core.dom.MethodDeclaration;
25
26
public class ASTitdTest extends TestCase {
27
28
	public void testAspectWithPublicMethodITD() {
29
		checkNameAndModifiers("aspect A{ public void B.x(){} }","name = x, modifier = public");
30
	}
31
32
	public void testAspectWithPrivateMethodITD() {
33
		checkNameAndModifiers("aspect A{ private void B.x(){} }","name = x, modifier = private");
34
	}
35
36
	public void testAspectWithPublicAbstractMethodITD() {
37
		checkNameAndModifiers("aspect A{ public abstract void B.x(){} }","name = x, modifier = public abstract");
38
	}
39
40
	public void testAspectWithConstructorITD() {
41
		checkNameAndModifiers("class A {}aspect B {public A.new(){}}","name = A_new, modifier = public");
42
	}
43
	
44
	public void testAspectWithPublicFieldITD() {
45
		checkNameAndModifiers("class A {}aspect B {public int A.a;}","name = a, modifier = public");
46
	}
47
	
48
	private void checkNameAndModifiers(String source, String expectedOutput){
49
		ASTParser parser = ASTParser.newParser(AST.JLS2); // ajh02: need to use 2 for returnType - in 3 it has "returnType2"
50
		parser.setCompilerOptions(new HashMap());//JavaCore.getOptions());
51
		parser.setSource(source.toCharArray());
52
		CompilationUnit cu2 = (CompilationUnit) parser.createAST(null);
53
		ITDTestVisitor visitor = new ITDTestVisitor();
54
		cu2.accept(visitor);
55
		String result = visitor.toString();
56
		//System.err.println("actual:\n" + result);
57
		assertTrue("Expected:\n"+ expectedOutput + "====Actual:\n" + result,
58
				expectedOutput.equals(result));
59
	}
60
	
61
}
62
63
class ITDTestVisitor extends AjASTVisitor {
64
65
	StringBuffer b = new StringBuffer();
66
	boolean visitDocTags;
67
	
68
	ITDTestVisitor() {
69
		this(false);
70
	}
71
	
72
	public String toString(){
73
		return b.toString();
74
	}
75
	
76
	ITDTestVisitor(boolean visitDocTags) {
77
		super(visitDocTags);
78
		this.visitDocTags = visitDocTags;
79
	}
80
	
81
	public boolean visit(MethodDeclaration node) {
82
		if (node instanceof InterTypeMethodDeclaration) 
83
			return visit((InterTypeMethodDeclaration)node);
84
		return true;
85
	}
86
	public boolean visit(InterTypeFieldDeclaration node) {
87
		b.append("name = " + node.fragments().get(0) + ", modifier = " + Modifier.toString(node.getModifiers()));
88
		return true;
89
	}
90
	public boolean visit(InterTypeMethodDeclaration node) {
91
		b.append("name = " + node.getName() + ", modifier = " + Modifier.toString(node.getModifiers()));
92
		return true;
93
	}	
94
}

Return to bug 110465