@@ -808,6 +808,7 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC | |||
TypeDeclaration typeDecl = ((SourceTypeBinding)mbs[0].declaringClass).scope.referenceContext; | |||
AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(mbs[0]); | |||
toAdd = methodDecl.annotations; // this is what to add | |||
toAdd[0] = createAnnotationCopy(toAdd[0]); | |||
if (toAdd[0].resolvedType!=null) // pr148536 | |||
abits = toAdd[0].resolvedType.getAnnotationTagBits(); | |||
} | |||
@@ -945,6 +946,32 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC | |||
// ann.memberValuePairs = mvps; | |||
return ann; | |||
} | |||
/** Create a copy of an annotation, not deep but deep enough so we don't copy across fields that will get us into trouble like 'recipient' */ | |||
private static Annotation createAnnotationCopy(Annotation ann) { | |||
NormalAnnotation ann2 = new NormalAnnotation(ann.type,ann.sourceStart); | |||
ann2.memberValuePairs = ann.memberValuePairs(); | |||
ann2.resolvedType = ann.resolvedType; | |||
ann2.bits = ann.bits; | |||
return ann2; | |||
// String name = annX.getTypeName(); | |||
// TypeBinding tb = factory.makeTypeBinding(annX.getSignature()); | |||
// String theName = annX.getSignature().getBaseName(); | |||
// char[][] typeName = CharOperation.splitOn('.',name.replace('$','.').toCharArray()); //pr149293 - not bulletproof... | |||
// long[] positions = new long[typeName.length]; | |||
// for (int i = 0; i < positions.length; i++) positions[i]=pos; | |||
// TypeReference annType = new QualifiedTypeReference(typeName,positions); | |||
// NormalAnnotation ann = new NormalAnnotation(annType,pos); | |||
// ann.resolvedType=tb; // yuck - is this OK in all cases? | |||
// // We don't need membervalues... | |||
//// Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos); | |||
//// MemberValuePair[] mvps = new MemberValuePair[2]; | |||
//// mvps[0] = new MemberValuePair("value".toCharArray(),pos,pos,pcExpr); | |||
//// Expression argNamesExpr = new StringLiteral(argNames.toCharArray(),pos,pos); | |||
//// mvps[1] = new MemberValuePair("argNames".toCharArray(),pos,pos,argNamesExpr); | |||
//// ann.memberValuePairs = mvps; | |||
// return ann; | |||
} | |||
private boolean isAnnotationTargettingSomethingOtherThanAnnotationOrNormal(long abits) { | |||
return (abits & (TagBits.AnnotationForAnnotationType | TagBits.AnnotationForType))==0; |
@@ -38,7 +38,6 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Wildcard; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.impl.Constant; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.impl.ReferenceContext; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ArrayBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.BaseTypes; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Binding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding; | |||
@@ -49,6 +48,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SyntheticFieldBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.WildcardBinding; | |||
@@ -72,6 +72,10 @@ import org.aspectj.weaver.UnresolvedType; | |||
import org.aspectj.weaver.UnresolvedTypeVariableReferenceType; | |||
import org.aspectj.weaver.World; | |||
import org.aspectj.weaver.UnresolvedType.TypeKind; | |||
import sun.reflect.generics.reflectiveObjects.NotImplementedException; | |||
import com.sun.org.apache.xml.internal.utils.UnImplNode; | |||
/** | |||
* @author Jim Hugunin | |||
@@ -612,15 +616,15 @@ public class EclipseFactory { | |||
private TypeBinding makeTypeBinding1(UnresolvedType typeX) { | |||
if (typeX.isPrimitiveType()) { | |||
if (typeX == ResolvedType.BOOLEAN) return BaseTypes.BooleanBinding; | |||
if (typeX == ResolvedType.BYTE) return BaseTypes.ByteBinding; | |||
if (typeX == ResolvedType.CHAR) return BaseTypes.CharBinding; | |||
if (typeX == ResolvedType.DOUBLE) return BaseTypes.DoubleBinding; | |||
if (typeX == ResolvedType.FLOAT) return BaseTypes.FloatBinding; | |||
if (typeX == ResolvedType.INT) return BaseTypes.IntBinding; | |||
if (typeX == ResolvedType.LONG) return BaseTypes.LongBinding; | |||
if (typeX == ResolvedType.SHORT) return BaseTypes.ShortBinding; | |||
if (typeX == ResolvedType.VOID) return BaseTypes.VoidBinding; | |||
if (typeX == ResolvedType.BOOLEAN) return TypeBinding.BOOLEAN; | |||
if (typeX == ResolvedType.BYTE) return TypeBinding.BYTE; | |||
if (typeX == ResolvedType.CHAR) return TypeBinding.CHAR; | |||
if (typeX == ResolvedType.DOUBLE) return TypeBinding.DOUBLE; | |||
if (typeX == ResolvedType.FLOAT) return TypeBinding.FLOAT; | |||
if (typeX == ResolvedType.INT) return TypeBinding.INT; | |||
if (typeX == ResolvedType.LONG) return TypeBinding.LONG; | |||
if (typeX == ResolvedType.SHORT) return TypeBinding.SHORT; | |||
if (typeX == ResolvedType.VOID) return TypeBinding.VOID; | |||
throw new RuntimeException("weird primitive type " + typeX); | |||
} else if (typeX.isArray()) { | |||
int dim = 0; | |||
@@ -721,6 +725,21 @@ public class EclipseFactory { | |||
return internalMakeFieldBinding(member,null); | |||
} | |||
// OPTIMIZE tidy this up, must be able to optimize for the synthetic case, if we passed in the binding for the declaring type, that would make things easier | |||
/** | |||
* Build a new Eclipse SyntheticFieldBinding for an AspectJ ResolvedMember. | |||
*/ | |||
public SyntheticFieldBinding createSyntheticFieldBinding(SourceTypeBinding owningType,ResolvedMember member) { | |||
SyntheticFieldBinding sfb = new SyntheticFieldBinding(member.getName().toCharArray(), | |||
makeTypeBinding(member.getReturnType()), | |||
member.getModifiers() | Flags.AccSynthetic, | |||
owningType, | |||
Constant.NotAConstant, | |||
-1); // index filled in later | |||
owningType.addSyntheticField(sfb); | |||
return sfb; | |||
} | |||
/** | |||
* Take a normal AJ member and convert it into an eclipse fieldBinding. | |||
* Taking into account any aliases that it may include due to being | |||
@@ -744,11 +763,21 @@ public class EclipseFactory { | |||
} | |||
currentType = declaringType; | |||
FieldBinding fb = new FieldBinding(member.getName().toCharArray(), | |||
FieldBinding fb = null; | |||
if (member.getName().startsWith(NameMangler.PREFIX)) { | |||
fb = new SyntheticFieldBinding(member.getName().toCharArray(), | |||
makeTypeBinding(member.getReturnType()), | |||
member.getModifiers() | Flags.AccSynthetic, | |||
currentType, | |||
Constant.NotAConstant,-1); // index filled in later | |||
} else { | |||
fb = new FieldBinding(member.getName().toCharArray(), | |||
makeTypeBinding(member.getReturnType()), | |||
member.getModifiers(), | |||
currentType, | |||
Constant.NotAConstant); | |||
} | |||
typeVariableToTypeBinding.clear(); | |||
currentType = null; | |||
@@ -806,7 +835,7 @@ public class EclipseFactory { | |||
if (member.getTypeVariables()!=null) { | |||
if (member.getTypeVariables().length==0) { | |||
tvbs = MethodBinding.NoTypeVariables; | |||
tvbs = Binding.NO_TYPE_VARIABLES; | |||
} else { | |||
tvbs = makeTypeVariableBindingsFromAJTypeVariables(member.getTypeVariables()); | |||
// QQQ do we need to bother fixing up the declaring element here? | |||
@@ -892,12 +921,14 @@ public class EclipseFactory { | |||
// } else { | |||
// declaringElement = makeTypeBinding((UnresolvedType)tVar.getDeclaringElement()); | |||
// } | |||
tvBinding = new TypeVariableBinding(tv.getName().toCharArray(),declaringElement,tv.getRank()); | |||
tvBinding = new TypeVariableBinding(tv.getName().toCharArray(),null,tv.getRank()); | |||
typeVariableToTypeBinding.put(tv.getName(),tvBinding); | |||
tvBinding.superclass=(ReferenceBinding)makeTypeBinding(tv.getUpperBound()); | |||
tvBinding.firstBound=(ReferenceBinding)makeTypeBinding(tv.getFirstBound()); | |||
if (tv.getAdditionalInterfaceBounds()==null) { | |||
tvBinding.superInterfaces=TypeVariableBinding.NoSuperInterfaces; | |||
tvBinding.superInterfaces=TypeVariableBinding.NO_SUPERINTERFACES; | |||
} else { | |||
TypeBinding tbs[] = makeTypeBindings(tv.getAdditionalInterfaceBounds()); | |||
ReferenceBinding[] rbs= new ReferenceBinding[tbs.length]; | |||
@@ -929,7 +960,7 @@ public class EclipseFactory { | |||
tvBinding.superclass=(ReferenceBinding)makeTypeBinding(tv.getUpperBound()); | |||
tvBinding.firstBound=(ReferenceBinding)makeTypeBinding(tv.getFirstBound()); | |||
if (tv.getAdditionalInterfaceBounds()==null) { | |||
tvBinding.superInterfaces=TypeVariableBinding.NoSuperInterfaces; | |||
tvBinding.superInterfaces=TypeVariableBinding.NO_SUPERINTERFACES; | |||
} else { | |||
TypeBinding tbs[] = makeTypeBindings(tv.getAdditionalInterfaceBounds()); | |||
ReferenceBinding[] rbs= new ReferenceBinding[tbs.length]; |
@@ -21,6 +21,7 @@ import org.aspectj.org.eclipse.jdt.core.compiler.IProblem; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.problem.ProblemHandler; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.util.Util; | |||
public class EclipseSourceLocation implements ISourceLocation { | |||
private static String NO_CONTEXT = "USE_NULL--NO_CONTEXT_AVAILABLE"; | |||
@@ -75,7 +76,7 @@ public class EclipseSourceLocation implements ISourceLocation { | |||
public int getLine() { | |||
if (-1 == startLine && result!=null) { | |||
startLine = ProblemHandler.searchLineNumber(result.lineSeparatorPositions, startPos); | |||
startLine = Util.getLineNumber(startPos,result.lineSeparatorPositions,0,result.lineSeparatorPositions.length-1); | |||
} | |||
return startLine; | |||
} | |||
@@ -101,7 +102,7 @@ public class EclipseSourceLocation implements ISourceLocation { | |||
public int getEndLine() { | |||
if (-1 == endLine) { | |||
endLine = ProblemHandler.searchLineNumber(result.lineSeparatorPositions, endPos); | |||
endLine = Util.getLineNumber(endPos,result.lineSeparatorPositions,0,result.lineSeparatorPositions.length-1); | |||
} | |||
return endLine; | |||
} |
@@ -14,13 +14,15 @@ | |||
package org.aspectj.ajdt.internal.compiler.lookup; | |||
import java.lang.reflect.Modifier; | |||
import java.util.Map; | |||
import org.aspectj.bridge.ISourceLocation; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.env.IConstants; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding; | |||
import org.aspectj.weaver.ConcreteTypeMunger; | |||
import org.aspectj.weaver.NewConstructorTypeMunger; | |||
import org.aspectj.weaver.NewFieldTypeMunger; | |||
@@ -28,6 +30,7 @@ import org.aspectj.weaver.NewMethodTypeMunger; | |||
import org.aspectj.weaver.ResolvedMember; | |||
import org.aspectj.weaver.ResolvedType; | |||
import org.aspectj.weaver.ResolvedTypeMunger; | |||
import org.aspectj.weaver.World; | |||
public class EclipseTypeMunger extends ConcreteTypeMunger { | |||
@@ -127,11 +130,11 @@ public class EclipseTypeMunger extends ConcreteTypeMunger { | |||
// retain *only* the visibility modifiers and abstract when putting methods on an interface... | |||
if (sourceType.isInterface()) { | |||
boolean isAbstract = (binding.modifiers & IConstants.AccAbstract) != 0; | |||
binding.modifiers = (binding.modifiers & (IConstants.AccPublic | IConstants.AccProtected | IConstants.AccPrivate)); | |||
if (isAbstract) binding.modifiers |= IConstants.AccAbstract; | |||
boolean isAbstract = (binding.modifiers & ClassFileConstants.AccAbstract) != 0; | |||
binding.modifiers = (binding.modifiers & (ClassFileConstants.AccPublic | ClassFileConstants.AccProtected | ClassFileConstants.AccPrivate)); | |||
if (isAbstract) binding.modifiers |= ClassFileConstants.AccAbstract; | |||
} | |||
if (munger.getSignature().isVarargsMethod()) binding.modifiers |= IConstants.AccVarargs; | |||
if (munger.getSignature().isVarargsMethod()) binding.modifiers |= ClassFileConstants.AccVarargs; | |||
findOrCreateInterTypeMemberFinder(sourceType).addInterTypeMethod(binding); | |||
return true; | |||
} | |||
@@ -141,6 +144,20 @@ public class EclipseTypeMunger extends ConcreteTypeMunger { | |||
if (shouldTreatAsPublic()) { | |||
MethodBinding binding = world.makeMethodBinding(munger.getSignature(),munger.getTypeVariableAliases()); | |||
findOrCreateInterTypeMemberFinder(sourceType).addInterTypeMethod(binding); | |||
TypeVariableBinding[] typeVariables = binding.typeVariables; | |||
for (int i = 0; i < typeVariables.length; i++) { | |||
TypeVariableBinding tv = typeVariables[i]; | |||
String name = new String(tv.sourceName); | |||
TypeVariableBinding[] tv2 = sourceMethod.binding.typeVariables; | |||
for (int j = 0; j < tv2.length; j++) { | |||
TypeVariableBinding typeVariable = tv2[j]; | |||
if (new String(tv2[j].sourceName).equals(name)) typeVariables[i].declaringElement = binding; | |||
} | |||
} | |||
for (int i = 0; i < typeVariables.length; i++) { | |||
if (typeVariables[i].declaringElement==null) throw new RuntimeException("Declaring element not set"); | |||
} | |||
//classScope.referenceContext.binding.addMethod(binding); | |||
} else { | |||
InterTypeMethodBinding binding = | |||
@@ -202,4 +219,8 @@ public class EclipseTypeMunger extends ConcreteTypeMunger { | |||
return new EclipseTypeMunger(world,munger.parameterizedFor(target),aspectType,sourceMethod); | |||
} | |||
public ConcreteTypeMunger parameterizeWith(Map m,World w) { | |||
return new EclipseTypeMunger(world,munger.parameterizeWith(m,w),aspectType,sourceMethod); | |||
} | |||
} |