}
if (packageNode == null) return null;
}
- // !!! this searches each file for a class
+
+ // this searches each file for a class
for (Iterator it = packageNode.getChildren().iterator(); it.hasNext(); ) {
ProgramElementNode fileNode = (ProgramElementNode)it.next();
- for (Iterator j = fileNode.getChildren().iterator(); j.hasNext(); ) {
- ProgramElementNode classNode = (ProgramElementNode)j.next();
- if (classNode instanceof ProgramElementNode && className.equals(classNode.getName())) {
- return (ProgramElementNode)classNode;
- }
+ ProgramElementNode ret = findClassInNodes(fileNode.getChildren(), className);
+ if (ret != null) return ret;
+ }
+
+ return null;
+ }
+
+ private ProgramElementNode findClassInNodes(Collection nodes, String name) {
+ String baseName;
+ String innerName;
+ int dollar = name.indexOf('$');
+ if (dollar == -1) {
+ baseName = name;
+ innerName = null;
+ } else {
+ baseName = name.substring(0, dollar);
+ innerName = name.substring(dollar+1);
+ }
+
+
+ for (Iterator j = nodes.iterator(); j.hasNext(); ) {
+ ProgramElementNode classNode = (ProgramElementNode)j.next();
+// System.err.println("checking: " + classNode + " for " + baseName);
+// System.err.println("children: " + classNode.getChildren());
+ if (baseName.equals(classNode.getName())) {
+ if (innerName == null) return classNode;
+ else return findClassInNodes(classNode.getChildren(), innerName);
+ } else if (name.equals(classNode.getName())) {
+ return classNode;
}
}
return null;
public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) {
String name = new String(typeDeclaration.name);
+ //System.err.println("type with name: " + name);
ProgramElementNode.Kind kind = ProgramElementNode.Kind.CLASS;
if (typeDeclaration instanceof AspectDeclaration) kind = ProgramElementNode.Kind.ASPECT;
else if (typeDeclaration.isInterface()) kind = ProgramElementNode.Kind.INTERFACE;
// ??? share impl with visit(TypeDeclaration, ..) ?
public boolean visit(MemberTypeDeclaration memberTypeDeclaration, ClassScope scope) {
String name = new String(memberTypeDeclaration.name);
+ //System.err.println("member type with name: " + name);
+
ProgramElementNode.Kind kind = ProgramElementNode.Kind.CLASS;
if (memberTypeDeclaration instanceof AspectDeclaration) kind = ProgramElementNode.Kind.ASPECT;
else if (memberTypeDeclaration.isInterface()) kind = ProgramElementNode.Kind.INTERFACE;
stack.pop();
}
+ public boolean visit(LocalTypeDeclaration memberTypeDeclaration, BlockScope scope) {
+ String name = new String(memberTypeDeclaration.name);
+ String fullName = new String(memberTypeDeclaration.binding.constantPoolName());
+ int dollar = fullName.indexOf('$');
+ fullName = fullName.substring(dollar+1);
+//
+// System.err.println("member type with name: " + name + ", " +
+// new String(fullName));
+
+ ProgramElementNode.Kind kind = ProgramElementNode.Kind.CLASS;
+ if (memberTypeDeclaration.isInterface()) kind = ProgramElementNode.Kind.INTERFACE;
+
+ ProgramElementNode peNode = new ProgramElementNode(
+ fullName,
+ kind,
+ makeLocation(memberTypeDeclaration),
+ memberTypeDeclaration.modifiers,
+ "",
+ new ArrayList());
+
+ //??? we add this to the compilation unit
+ findEnclosingClass(stack).addChild(peNode);
+ stack.push(peNode);
+ return true;
+ }
+ public void endVisit(LocalTypeDeclaration memberTypeDeclaration, BlockScope scope) {
+ stack.pop();
+ }
+
+ public boolean visit(AnonymousLocalTypeDeclaration memberTypeDeclaration, BlockScope scope) {
+ return visit((LocalTypeDeclaration)memberTypeDeclaration, scope);
+ }
+
+ public void endVisit(AnonymousLocalTypeDeclaration memberTypeDeclaration, BlockScope scope) {
+ stack.pop();
+ }
+
+ private StructureNode findEnclosingClass(Stack stack) {
+ for (int i = stack.size()-1; i >= 0; i--) {
+ ProgramElementNode pe = (ProgramElementNode)stack.get(i);
+ if (pe.getProgramElementKind() == ProgramElementNode.Kind.CLASS) {
+ return pe;
+ }
+
+ }
+ return (StructureNode)stack.peek();
+ }
+
// !!! improve name and type generation
public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
ProgramElementNode.Kind kind = ProgramElementNode.Kind.METHOD;
methodDeclaration.modifiers,
"",
new ArrayList());
-
- Member member = EclipseWorld.makeResolvedMember(methodDeclaration.binding);
- peNode.setBytecodeName(member.getName());
- peNode.setBytecodeSignature(member.getSignature());
+ if (methodDeclaration.binding != null) {
+ Member member = EclipseWorld.makeResolvedMember(methodDeclaration.binding);
+ peNode.setBytecodeName(member.getName());
+ peNode.setBytecodeSignature(member.getSignature());
+ }
((StructureNode)stack.peek()).addChild(peNode);
stack.push(peNode);
private static ProgramElementNode getNode(StructureModel model, Advice a) {
//ResolvedTypeX inAspect = a.getConcreteAspect();
Member member = a.getSignature();
+ if (a.getSignature() == null) return null;
return lookupMember(model, member);
}
Member enclosingMember = shadow.getEnclosingCodeSignature();
ProgramElementNode enclosingNode = lookupMember(model, enclosingMember);
+ if (enclosingNode == null) {
+ Lint.Kind err = shadow.getIWorld().getLint().shadowNotInStructure;
+ if (err.isEnabled()) {
+ err.signal(shadow.toString(), shadow.getSourceLocation());
+ }
+ return null;
+ }
Member shadowSig = shadow.getSignature();
if (!shadowSig.equals(enclosingMember)) {
"",
new ArrayList());
- System.err.println(peNode.getSourceLocation());
+ //System.err.println(peNode.getSourceLocation());
peNode.setBytecodeName(shadowSig.getName());
peNode.setBytecodeSignature(shadowSig.getSignature());
enclosingNode.addChild(peNode);
if (classNode == null) return null; // XXX remove this check
for (Iterator it = classNode.getChildren().iterator(); it.hasNext(); ) {
ProgramElementNode node = (ProgramElementNode)it.next();
+ //System.err.println("checking: " + member.getName() + " with " + node.getBytecodeName() + ", " + node.getBytecodeSignature());
if (member.getName().equals(node.getBytecodeName()) &&
member.getSignature().equals(node.getBytecodeSignature()))
{
return node;
}
}
- return null;
+ // if we can't find the member, we'll just put it in the class
+ //??? is this what the IDEs want
+ return classNode;
}
public final Kind typeNotExposedToWeaver =
new Kind("typeNotExposedToWeaver", "this affected type is not exposed to the weaver: {0}");
+ public final Kind shadowNotInStructure =
+ new Kind("shadowNotInStructure", "the shadow for this join point is not exposed in the structure model: {0}");
+
public Lint(World world) {
this.world = world;
}
}
+ public boolean isSynthetic() {
+ return signature.indexOf("$ajc") != -1;
+ }
+
public final boolean isFinal() {
return Modifier.isFinal(getModifiers());
}
ShadowMunger munger = (ShadowMunger) iter.next();
munger.implementOn(this);
if (world.getModel() != null) {
- System.err.println("munger: " + munger + " on " + this);
+ //System.err.println("munger: " + munger + " on " + this);
AsmAdaptor.noteMunger(world.getModel(), this, munger);
}
}
unresolvableMember = warning
-typeNotExposedToWeaver = warning
\ No newline at end of file
+typeNotExposedToWeaver = warning
+
+shadowNotInStructure = ignore
\ No newline at end of file
// non-private for testing
LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType) throws IOException {
+ if (classType.isSynthetic()) {
+ dumpUnchanged(classFile);
+ return null;
+ }
+
JavaClass javaClass = classType.getJavaClass();
List shadowMungers = fastMatch(shadowMungerList, javaClass);
List typeMungers = fastMatch(classType.getInterTypeMungers(), javaClass);