aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core/src
diff options
context:
space:
mode:
authorjhugunin <jhugunin>2003-07-22 20:57:17 +0000
committerjhugunin <jhugunin>2003-07-22 20:57:17 +0000
commit026b2728aef846823419ebffceb57fe8161e3d15 (patch)
tree4388f34ab63d11eccb6a89917f0a07713f70ea61 /org.aspectj.ajdt.core/src
parent27ad07f5c1a4ad27fab06e1ebb91874355d90546 (diff)
downloadaspectj-026b2728aef846823419ebffceb57fe8161e3d15.tar.gz
aspectj-026b2728aef846823419ebffceb57fe8161e3d15.zip
tests and fix for Bugzilla Bug 39993
ajc stack trace on declaring hashcode() method in aspect added extra error-test for using super inside an inter-type declaration on an interface with multiple parents -- the correct parent is either hard or impossible to determine in that case
Diffstat (limited to 'org.aspectj.ajdt.core/src')
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterSuperFixerVisitor.java84
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterSuperReference.java36
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java13
3 files changed, 133 insertions, 0 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterSuperFixerVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterSuperFixerVisitor.java
new file mode 100644
index 000000000..bde3fd4e3
--- /dev/null
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterSuperFixerVisitor.java
@@ -0,0 +1,84 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.ajdt.internal.compiler.ast;
+
+import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
+import org.aspectj.ajdt.internal.compiler.lookup.EclipseSourceLocation;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.ISourceLocation;
+import org.eclipse.jdt.internal.compiler.AbstractSyntaxTreeVisitorAdapter;
+import org.eclipse.jdt.internal.compiler.ast.Expression;
+import org.eclipse.jdt.internal.compiler.ast.FieldReference;
+import org.eclipse.jdt.internal.compiler.ast.MessageSend;
+import org.eclipse.jdt.internal.compiler.ast.SuperReference;
+import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
+import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
+import org.eclipse.jdt.internal.compiler.lookup.Scope;
+import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
+
+/**
+ * Walks the body of inter-type declarations and replaces SuperReference with InterSuperReference
+ *
+ * @author Jim Hugunin
+ */
+
+public class InterSuperFixerVisitor extends AbstractSyntaxTreeVisitorAdapter {
+ InterTypeDeclaration dec;
+ ReferenceBinding onType;
+ TypeBinding superType;
+
+ EclipseFactory world;
+ public InterSuperFixerVisitor(InterTypeDeclaration dec, EclipseFactory world, Scope scope) {
+ this.dec = dec;
+ this.onType = dec.onTypeBinding;
+ this.world = world;
+
+ if (onType.superclass() != null) {
+ superType = onType.superclass();
+ } else if (onType.superInterfaces() == null || onType.superInterfaces().length == 0) {
+ superType = scope.getJavaLangObject();
+ } else if (onType.superInterfaces().length == 1) {
+ superType = onType.superInterfaces()[0];
+ } else {
+ superType = null;
+ }
+ }
+
+ public void endVisit(FieldReference ref, BlockScope scope) {
+ ref.receiver = fixReceiver(ref.receiver, scope);
+ }
+ public void endVisit(MessageSend send, BlockScope scope) {
+ send.receiver = fixReceiver(send.receiver, scope);
+ }
+
+ private Expression fixReceiver(Expression expression, BlockScope scope) {
+ if (expression instanceof SuperReference) {
+ SuperReference superRef = (SuperReference) expression;
+ if (superType == null) {
+ ISourceLocation location =
+ new EclipseSourceLocation(scope.problemReporter().referenceContext.compilationResult(),
+ expression.sourceStart, expression.sourceEnd);
+
+ world.showMessage(IMessage.ERROR, "multiple supertypes for this interface", location, null);
+ dec.ignoreFurtherInvestigation = true;
+ }
+ //FIXME note error
+ expression = new InterSuperReference(superRef, superType);
+ }
+ return expression;
+ }
+
+
+
+}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterSuperReference.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterSuperReference.java
new file mode 100644
index 000000000..f0ed406e0
--- /dev/null
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterSuperReference.java
@@ -0,0 +1,36 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.ajdt.internal.compiler.ast;
+
+import org.eclipse.jdt.internal.compiler.ast.SuperReference;
+import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
+import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
+
+/**
+ * Used to represent super references inside of inter-type declarations. Special mechanism
+ * needed for handling in an interface context.
+ *
+ * @author Jim Hugunin
+ */
+public class InterSuperReference extends SuperReference {
+ public InterSuperReference(SuperReference template, TypeBinding myType) {
+ super(template.sourceStart, template.sourceEnd);
+ this.resolvedType = myType;
+ }
+
+ public TypeBinding resolveType(BlockScope scope) {
+ return resolvedType;
+ }
+
+}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java
index 6c7d43b3d..7274367b3 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java
@@ -17,6 +17,7 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
+import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
import org.aspectj.ajdt.internal.compiler.lookup.EclipseTypeMunger;
import org.aspectj.ajdt.internal.compiler.lookup.InterTypeScope;
import org.aspectj.ajdt.internal.core.builder.EclipseSourceContext;
@@ -63,10 +64,22 @@ public abstract class InterTypeDeclaration extends MethodDeclaration {
ClassScope newParent = new InterTypeScope(upperScope, onTypeBinding);
scope.parent = newParent;
this.scope.isStatic = Modifier.isStatic(declaredModifiers);
+ fixSuperCallsForInterfaceContext(upperScope);
+ if (ignoreFurtherInvestigation) return;
+
super.resolve(newParent);
fixSuperCallsInBody();
}
+ private void fixSuperCallsForInterfaceContext(ClassScope scope) {
+ if (onTypeBinding.isInterface()) {
+ InterSuperFixerVisitor v =
+ new InterSuperFixerVisitor(this,
+ EclipseFactory.fromScopeLookupEnvironment(scope), scope);
+ this.traverse(v, scope);
+ }
+ }
+
/**
* Called from AspectDeclarations.buildInterTypeAndPerClause
*/