Fixes #162. Contains regression test Bugs1919Tests.testInterfaceInnerAspectImplicitlyStatic. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>tags/V1_9_20
} | } | ||||
if (this.enclosingType != null) { | if (this.enclosingType != null) { | ||||
if (!Modifier.isStatic(modifiers)) { | |||||
if ( | |||||
!Modifier.isStatic(modifiers) && | |||||
// Inner classes/aspects of interfaces are implicitly static, | |||||
// see https://github.com/eclipse/org.aspectj/issues/162 | |||||
(this.enclosingType.modifiers & ClassFileConstants.AccInterface) == 0 | |||||
) { | |||||
scope.problemReporter().signalError(sourceStart, sourceEnd, "inner aspects must be static"); | scope.problemReporter().signalError(sourceStart, sourceEnd, "inner aspects must be static"); | ||||
ignoreFurtherInvestigation = true; | ignoreFurtherInvestigation = true; | ||||
return; | return; |
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral; | import org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral; | ||||
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; | import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; | ||||
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference; | import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference; | ||||
import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; | |||||
import org.aspectj.org.eclipse.jdt.internal.compiler.impl.Constant; | import org.aspectj.org.eclipse.jdt.internal.compiler.impl.Constant; | ||||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Binding; | import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Binding; | ||||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.BlockScope; | import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.BlockScope; | ||||
private void validateAspectDeclaration(TypeDeclaration typeDecl) { | private void validateAspectDeclaration(TypeDeclaration typeDecl) { | ||||
if (typeStack.size() > 1) { | if (typeStack.size() > 1) { | ||||
// it's a nested aspect | // it's a nested aspect | ||||
if (!Modifier.isStatic(typeDecl.modifiers)) { | |||||
if ( | |||||
!Modifier.isStatic(typeDecl.modifiers) && | |||||
// Inner classes/aspects of interfaces are implicitly static, | |||||
// see https://github.com/eclipse/org.aspectj/issues/162 | |||||
(typeDecl.enclosingType.modifiers & ClassFileConstants.AccInterface) == 0 | |||||
) { | |||||
typeDecl.scope.problemReporter().signalError(typeDecl.sourceStart, typeDecl.sourceEnd, | typeDecl.scope.problemReporter().signalError(typeDecl.sourceStart, typeDecl.sourceEnd, | ||||
"inner aspects must be static"); | "inner aspects must be static"); | ||||
return; | return; |
import org.aspectj.lang.annotation.Aspect; | |||||
import org.aspectj.lang.annotation.Before; | |||||
import org.aspectj.lang.JoinPoint; | |||||
/** | |||||
* https://github.com/eclipse/org.aspectj/issues/162 | |||||
*/ | |||||
public interface InterfaceWithInnerClass { | |||||
public class ImplicitlyStatic { | |||||
public int getNumber() { | |||||
return 11; | |||||
} | |||||
public static void main(String[] args) { | |||||
System.out.println(new ImplicitlyStatic().getNumber()); | |||||
} | |||||
} | |||||
/*static*/ aspect MyAspect { | |||||
before() : execution(* main(..)) { | |||||
System.out.println(thisJoinPoint); | |||||
} | |||||
} | |||||
@Aspect | |||||
/*static*/ class MyAnnotationAspect { | |||||
@Before("execution(* getNumber(..))") | |||||
public void myAdvice(JoinPoint thisJoinPoint){ | |||||
System.out.println(thisJoinPoint); | |||||
} | |||||
} | |||||
} |
runTest("parenthesised expression with AspectJ keyword"); | runTest("parenthesised expression with AspectJ keyword"); | ||||
} | } | ||||
public void testInterfaceInnerAspectImplicitlyStatic() { | |||||
runTest("inner aspect of interface is implicitly static"); | |||||
} | |||||
public static Test suite() { | public static Test suite() { | ||||
return XMLBasedAjcTestCase.loadSuite(Bugs1919Tests.class); | return XMLBasedAjcTestCase.loadSuite(Bugs1919Tests.class); | ||||
} | } |
</run> | </run> | ||||
</ajc-test> | </ajc-test> | ||||
<!-- | |||||
'inner aspects must be static' when compiling an interface with an inner aspect which was not explicitly declared | |||||
static, see https://github.com/eclipse/org.aspectj/issues/162 | |||||
--> | |||||
<ajc-test dir="bugs1919/github_162" vm="1.5" title="inner aspect of interface is implicitly static"> | |||||
<compile files="InterfaceWithInnerClass.java" options="-1.5 -showWeaveInfo"> | |||||
<message kind="weave" text="method-execution(int InterfaceWithInnerClass$ImplicitlyStatic.getNumber())' in Type 'InterfaceWithInnerClass$ImplicitlyStatic'"/> | |||||
<message kind="weave" text="method-execution(void InterfaceWithInnerClass$ImplicitlyStatic.main(java.lang.String[]))' in Type 'InterfaceWithInnerClass$ImplicitlyStatic'"/> | |||||
</compile> | |||||
<run class="InterfaceWithInnerClass$ImplicitlyStatic"> | |||||
<stdout> | |||||
<line text="execution(void InterfaceWithInnerClass.ImplicitlyStatic.main(String[]))"/> | |||||
<line text="execution(int InterfaceWithInnerClass.ImplicitlyStatic.getNumber())"/> | |||||
<line text="11"/> | |||||
</stdout> | |||||
</run> | |||||
</ajc-test> | |||||
</suite> | </suite> |