Browse Source

Fix and tests for pr77269: incorrect structure model for inner types. (Patch from Helen Hawkins).

tags/preDefaultReweavable
aclement 18 years ago
parent
commit
4573068062

+ 10
- 3
asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java View File

@@ -153,7 +153,7 @@ public class AspectJElementHierarchy implements IHierarchy {
// this searches each file for a class
for (Iterator it = packageNode.getChildren().iterator(); it.hasNext(); ) {
IProgramElement fileNode = (IProgramElement)it.next();
IProgramElement cNode = findClassInNodes(fileNode.getChildren(), typeName);
IProgramElement cNode = findClassInNodes(fileNode.getChildren(), typeName, typeName);
if (cNode != null) {
ret = cNode;
typeMap.put(key,ret);
@@ -163,7 +163,7 @@ public class AspectJElementHierarchy implements IHierarchy {
return ret;
}
private IProgramElement findClassInNodes(Collection nodes, String name) {
private IProgramElement findClassInNodes(Collection nodes, String name, String typeName) {
String baseName;
String innerName;
int dollar = name.indexOf('$');
@@ -179,9 +179,16 @@ public class AspectJElementHierarchy implements IHierarchy {
IProgramElement classNode = (IProgramElement)j.next();
if (baseName.equals(classNode.getName())) {
if (innerName == null) return classNode;
else return findClassInNodes(classNode.getChildren(), innerName);
else return findClassInNodes(classNode.getChildren(), innerName, typeName);
} else if (name.equals(classNode.getName())) {
return classNode;
} else if (typeName.equals(classNode.getBytecodeSignature())) {
return classNode;
} else if (classNode.getChildren() != null && !classNode.getChildren().isEmpty()){
IProgramElement node = findClassInNodes(classNode.getChildren(),name, typeName);
if (node != null) {
return node;
}
}
}
return null;

+ 15
- 1
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java View File

@@ -331,7 +331,21 @@ public class AsmHierarchyBuilder extends ASTVisitor {
new ArrayList());
peNode.setSourceSignature(genSourceSignature(memberTypeDeclaration));
peNode.setFormalComment(generateJavadocComment(memberTypeDeclaration));
// if we're something like 'new Runnable(){..}' then set the
// bytecodeSignature to be the typename so we can match it later
// when creating the structure model
if (peNode.getBytecodeSignature() == null
&& memberTypeDeclaration.binding != null
&& memberTypeDeclaration.binding.constantPoolName() != null) {
StringTokenizer st = new StringTokenizer(
new String(memberTypeDeclaration.binding.constantPoolName()),"/");
while(st.hasMoreTokens()) {
String s = st.nextToken();
if (!st.hasMoreTokens()) {
peNode.setBytecodeSignature(s);
}
}
}

((IProgramElement)stack.peek()).addChild(peNode);
stack.push(peNode);

+ 24
- 0
tests/bugs150/pr77269/pack/pr77269.aj View File

@@ -0,0 +1,24 @@
package pack;
class Test {
public void testMethod() {
new Runnable() {
public void run() {
}
};
class C {
public void m(){
}
}
}
}

aspect A {
pointcut p() : execution(* run(..));
before() : p() {
}

}

+ 19
- 0
tests/bugs150/pr77269/pack/pr77269c.aj View File

@@ -0,0 +1,19 @@
package pack;

class Test {
public void testMethod() {
new Runnable() {
public void run() {
someMethod();
}
};
}
public void someMethod() {
}
}

aspect A {
declare warning : call(void someMethod(..)) : "blah blah blah";
}

+ 23
- 0
tests/bugs150/pr77269b.aj View File

@@ -0,0 +1,23 @@
class Test {
public void testMethod() {
new Runnable() {
public void run() {
}
};
class C {
public void m(){
}
}
}
}

aspect A {
pointcut p() : execution(* m(..));
before() : p() {
}

}

+ 105
- 0
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java View File

@@ -14,6 +14,8 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import junit.framework.Test;

@@ -23,6 +25,10 @@ import org.aspectj.apache.bcel.classfile.Signature;
import org.aspectj.apache.bcel.util.ClassPath;
import org.aspectj.apache.bcel.util.SyntheticRepository;
import org.aspectj.asm.AsmManager;
import org.aspectj.asm.IHierarchy;
import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.IRelationship;
import org.aspectj.asm.internal.Relationship;
import org.aspectj.testing.XMLBasedAjcTestCase;
import org.aspectj.util.LangUtil;

@@ -490,6 +496,105 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
runTest("debug info in around advice inlining");
}
public void testAdviceInStructureModelWithAnonymousInnerClass_pr77269() {
//AsmManager.setReporting("c:/debug.txt",true,true,true,true);
runTest("advice in structure model with anonymous inner class");
IHierarchy top = AsmManager.getDefault().getHierarchy();
// checking that the run() method inside anonymous inner class is in
// the structure model
IProgramElement anonRunMethodIPE = top.findElementForLabel(top.getRoot(),
IProgramElement.Kind.METHOD,"run()");
assertNotNull("Couldn't find 'run()' element in the tree",anonRunMethodIPE);
List l = AsmManager.getDefault().getRelationshipMap().get(anonRunMethodIPE);
assertNotNull("Should have some relationships but does not",l);
assertTrue("Should have one relationship but has " + l.size(),l.size()==1);
Relationship rel = (Relationship)l.get(0);
List targets = rel.getTargets();
assertTrue("Should have one target but has" + targets.size(),
targets.size()==1);
IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0));
assertEquals("target of relationship should be 'before(): p..' but is "
+ target.toLabelString(),"before(): p..",target.toLabelString());

IProgramElement adviceIPE = top.findElementForLabel(top.getRoot(),
IProgramElement.Kind.ADVICE,"before(): p..");
assertNotNull("Couldn't find 'before(): p..' element in the tree",adviceIPE);
l = AsmManager.getDefault().getRelationshipMap().get(adviceIPE);
assertNotNull("Should have some relationships but does not",l);
assertTrue("Should have a relationship but does not ",l.size()>0);
for (Iterator iter = l.iterator(); iter.hasNext();) {
IRelationship element = (IRelationship) iter.next();
if (element.getName().equals("advises")) {
rel = (Relationship) element;
break;
}
}
targets = rel.getTargets();
assertTrue("Should have one target but has" + targets.size(),
targets.size()==1);
target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0));
assertEquals("target of relationship should be 'run()' but is "
+ target.toLabelString(),"run()",target.toLabelString());
}
public void testAdviceInStructureModelWithNamedInnerClass_pr77269() {
//AsmManager.setReporting("c:/debug.txt",true,true,true,true);
runTest("advice in structure model with named inner class");
IHierarchy top = AsmManager.getDefault().getHierarchy();
// checking that the m() method inside named inner class is in
// the structure model
IProgramElement namedMethodIPE = top.findElementForLabel(top.getRoot(),
IProgramElement.Kind.METHOD,"m()");
assertNotNull("Couldn't find 'm()' element in the tree",namedMethodIPE);
List l = AsmManager.getDefault().getRelationshipMap().get(namedMethodIPE);
assertNotNull("Should have some relationships but does not",l);
assertTrue("Should have one relationship but has " + l.size(),l.size()==1);
Relationship rel = (Relationship)l.get(0);
List targets = rel.getTargets();
assertTrue("Should have one target but has" + targets.size(),
targets.size()==1);
IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0));
assertEquals("target of relationship should be 'before(): p..' but is "
+ target.toLabelString(),"before(): p..",target.toLabelString());

IProgramElement adviceIPE = top.findElementForLabel(top.getRoot(),
IProgramElement.Kind.ADVICE,"before(): p..");
assertNotNull("Couldn't find 'before(): p..' element in the tree",adviceIPE);
l = AsmManager.getDefault().getRelationshipMap().get(adviceIPE);
assertNotNull("Should have some relationships but does not",l);
assertTrue("Should have a relationship but does not ",l.size()>0);
for (Iterator iter = l.iterator(); iter.hasNext();) {
IRelationship element = (IRelationship) iter.next();
if (element.getName().equals("advises")) {
rel = (Relationship) element;
break;
}
}
targets = rel.getTargets();
assertTrue("Should have one target but has" + targets.size(),
targets.size()==1);
target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0));
assertEquals("target of relationship should be 'm()' but is "
+ target.toLabelString(),"m()",target.toLabelString());
}
public void testDWInStructureModelWithAnonymousInnerClass_pr77269() {
// AsmManager.setReporting("c:/debug.txt",true,true,true,true);
runTest("declare warning in structure model with anonymous inner class");
IHierarchy top = AsmManager.getDefault().getHierarchy();
IProgramElement pe = top.findElementForLabel(top.getRoot(),
IProgramElement.Kind.CODE,"method-call(void pack.Test.someMethod())");
assertNotNull("Couldn't find 'method-call(void pack.Test.someMethod())' element in the tree",pe);
}
// helper methods.....
public SyntheticRepository createRepos(File cpentry) {

+ 22
- 0
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml View File

@@ -643,6 +643,24 @@
</compile>
<run class="pr100195"/>
</ajc-test>

<ajc-test dir="bugs150/pr77269" title="advice in structure model with anonymous inner class">
<compile files="pack/pr77269.aj" options="-emacssym">
</compile>
</ajc-test>

<ajc-test dir="bugs150" title="advice in structure model with named inner class">
<compile files="pr77269b.aj" options="-emacssym">
</compile>
</ajc-test>

<ajc-test dir="bugs150/pr77269" title="declare warning in structure model with anonymous inner class">
<compile files="pack/pr77269c.aj" options="-emacssym">
<message kind="warning" line="8" text="blah blah blah"/>
</compile>
</ajc-test>


<!-- ============================================================================ -->
<!-- ============================================================================ -->
@@ -4881,6 +4899,10 @@
<compile files="pr92311.aj"/>
</ajc-test>
<ajc-test dir="bugs150" title="ITD varargs problem">
<compile files="pr110906.aj"/>
</ajc-test>
<ajc-test dir="bugs150" title="generic itds and abstract method error">
<compile files="pr102357.aj"/>
<run class="pr102357"/>

Loading…
Cancel
Save