Browse Source

251277: making asmmanager non-singleton

tags/V1_6_3rc1
aclement 15 years ago
parent
commit
689bd19050

+ 9
- 0
ajde.core/src/org/aspectj/ajde/core/AjCompiler.java View File



import org.aspectj.ajde.core.internal.AjdeCoreBuildManager; import org.aspectj.ajde.core.internal.AjdeCoreBuildManager;
import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager; import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager;
import org.aspectj.asm.AsmManager;
import org.aspectj.bridge.IMessage; import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.Message; import org.aspectj.bridge.Message;
import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
public Object getCustomMungerFactory() { public Object getCustomMungerFactory() {
return buildManager.getCustomMungerFactory(); return buildManager.getCustomMungerFactory();
} }

public AsmManager getModel() {
return buildManager.getStructureModel();
}

// public AsmManager getStructureModel() {
// return buildManager.getStructureModel();
// }
} }

+ 11
- 2
ajde.core/src/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java View File

AsmManager.attemptIncrementalModelRepairs = true; AsmManager.attemptIncrementalModelRepairs = true;
} }


// public AsmManager getStructureModel() {
// return ajBuildManager.
// }

/** /**
* Execute a full or incremental build * Execute a full or incremental build
* *
// No existing state so we must do a full build // No existing state so we must do a full build
fullBuild = true; fullBuild = true;
} else { } else {
AsmManager.getDefault().setRelationshipMap(existingState.getRelationshipMap());
AsmManager.getDefault().setHierarchy(existingState.getStructureModel());
AsmManager.setLastActiveStructureModel(existingState.getStructureModel());
// AsmManager.getDefault().setRelationshipMap(existingState.getRelationshipMap());
// AsmManager.getDefault().setHierarchy(existingState.getStructureModel());
} }
} }
try { try {
public void cleanupEnvironment() { public void cleanupEnvironment() {
ajBuildManager.cleanupEnvironment(); ajBuildManager.cleanupEnvironment();
} }

public AsmManager getStructureModel() {
return ajBuildManager.getStructureModel();
}
} }

+ 48
- 54
ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java View File

import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.TestCase; import junit.framework.TestCase;


import org.aspectj.asm.AsmManager;
import org.aspectj.tools.ajc.Ajc; import org.aspectj.tools.ajc.Ajc;


/** /**
* Testcase class to be used by all ajde.core tests. Provides
* helper methods to set up the environment in a sandbox
* as well as to drive a build.
* Testcase class to be used by all ajde.core tests. Provides helper methods to set up the environment in a sandbox as well as to
* drive a build.
*/ */
public class AjdeCoreTestCase extends TestCase { public class AjdeCoreTestCase extends TestCase {


public final static String testdataSrcDir = "../ajde.core/testdata";
public final static String testdataSrcDir = "../ajde.core/testdata";
protected static File sandboxDir; protected static File sandboxDir;
private String projectDir; private String projectDir;
private AjCompiler compiler;
private AjCompiler compiler;


protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
// Create a sandbox in which to work // Create a sandbox in which to work
sandboxDir = Ajc.createEmptySandbox(); sandboxDir = Ajc.createEmptySandbox();
// AMC - added this next line as a temporary workaround for
// AMC - added this next line as a temporary workaround for
// listener leakage in AsmManager induced by the Ajde test suite. // listener leakage in AsmManager induced by the Ajde test suite.
AsmManager.getDefault().removeAllListeners();
// AsmManager.getDefault().removeAllListeners();
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
super.tearDown(); super.tearDown();
compiler.clearLastState(); compiler.clearLastState();
compiler = null; compiler = null;
} }
/** /**
* Fill in the working directory with the project files and
* creates a compiler instance for this project
* Fill in the working directory with the project files and creates a compiler instance for this project
*/ */
public void initialiseProject(String projectName) throws IOException { public void initialiseProject(String projectName) throws IOException {
File projectSrc=new File(testdataSrcDir + File.separatorChar + projectName);
File destination=new File(getWorkingDir(),projectName);
if (!destination.exists()) {destination.mkdir();}
copy(projectSrc,destination);
projectDir = destination.getCanonicalPath();//getAbsolutePath();
compiler = new AjCompiler(
projectDir,
new TestCompilerConfiguration(projectDir),
new TestBuildProgressMonitor(),
new TestMessageHandler());
File projectSrc = new File(testdataSrcDir + File.separatorChar + projectName);
File destination = new File(getWorkingDir(), projectName);
if (!destination.exists()) {
destination.mkdir();
}
copy(projectSrc, destination);
projectDir = destination.getCanonicalPath();// getAbsolutePath();

compiler = new AjCompiler(projectDir, new TestCompilerConfiguration(projectDir), new TestBuildProgressMonitor(),
new TestMessageHandler());
} }
/** /**
* @return the working directory * @return the working directory
*/ */
protected File getWorkingDir() {
return sandboxDir;
protected File getWorkingDir() {
return sandboxDir;
} }
/** /**
* @return the absolute path of the project directory
* for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject
* @return the absolute path of the project directory for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject
*/ */
protected String getAbsoluteProjectDir() { protected String getAbsoluteProjectDir() {
return projectDir; return projectDir;
} }
/** /**
* Copy the contents of some directory to another location - the
* copy is recursive.
* Copy the contents of some directory to another location - the copy is recursive.
*/ */
private void copy(File from, File to) { private void copy(File from, File to) {
String contents[] = from.list(); String contents[] = from.list();
if (contents==null) return;
if (contents == null)
return;
for (int i = 0; i < contents.length; i++) { for (int i = 0; i < contents.length; i++) {
String string = contents[i]; String string = contents[i];
File f = new File(from,string);
File t = new File(to,string);
File f = new File(from, string);
File t = new File(to, string);
if (f.isDirectory()) { if (f.isDirectory()) {
t.mkdir(); t.mkdir();
copy(f,t);
copy(f, t);
} else if (f.isFile()) { } else if (f.isFile()) {
try { try {
org.aspectj.util.FileUtil.copyFile(f,t);
org.aspectj.util.FileUtil.copyFile(f, t);
} catch (IOException e) { } catch (IOException e) {
throw new AssertionFailedError("Unable to copy " + f + " to " + t); throw new AssertionFailedError("Unable to copy " + f + " to " + t);
} }
}
}
} }
} }
protected File openFile(String path) { protected File openFile(String path) {
return new File(projectDir + File.separatorChar + path); return new File(projectDir + File.separatorChar + path);
} }
public void doBuild() { public void doBuild() {
doBuild(true); doBuild(true);
} }
public void doBuild(boolean buildFresh) { public void doBuild(boolean buildFresh) {
if (buildFresh) { if (buildFresh) {
compiler.buildFresh(); compiler.buildFresh();
compiler.build(); compiler.build();
} }
} }
public AjCompiler getCompiler() { public AjCompiler getCompiler() {
return compiler; return compiler;
} }
public boolean checkFor(String what) { public boolean checkFor(String what) {
List ll = ((TestMessageHandler)compiler.getMessageHandler()).getMessages();
List ll = ((TestMessageHandler) compiler.getMessageHandler()).getMessages();
for (Iterator iter = ll.iterator(); iter.hasNext();) { for (Iterator iter = ll.iterator(); iter.hasNext();) {
Object element = iter.next();
Object element = iter.next();
if (element.toString().indexOf(what) != -1) if (element.toString().indexOf(what) != -1)
return true; return true;
} }
return false; return false;
} }
public void dumpTaskData() { public void dumpTaskData() {
List ll = ((TestMessageHandler)compiler.getMessageHandler()).getMessages();
List ll = ((TestMessageHandler) compiler.getMessageHandler()).getMessages();
for (Iterator iter = ll.iterator(); iter.hasNext();) { for (Iterator iter = ll.iterator(); iter.hasNext();) {
Object element = iter.next();
System.out.println("RecordedMessage>"+element);
Object element = iter.next();
System.out.println("RecordedMessage>" + element);
} }
} }
public List getSourceFileList(String[] files) { public List getSourceFileList(String[] files) {
List sourceFiles = new ArrayList(); List sourceFiles = new ArrayList();
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
} }
return sourceFiles; return sourceFiles;
} }
} }

+ 10
- 9
ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmDeclarationsTests.java View File



public class AsmDeclarationsTests extends AjdeCoreTestCase { public class AsmDeclarationsTests extends AjdeCoreTestCase {


private AsmManager manager = null;
private IHierarchy model = null; private IHierarchy model = null;


private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" }; private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" };
compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration(); compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
compilerConfig.setProjectSourceFiles(getSourceFileList(files)); compilerConfig.setProjectSourceFiles(getSourceFileList(files));
doBuild(); doBuild();
model = AsmManager.getDefault().getHierarchy();
manager = AsmManager.lastActiveStructureModel;
model = AsmManager.lastActiveStructureModel.getHierarchy();
} }


protected void tearDown() throws Exception { protected void tearDown() throws Exception {
} }


public void testAspectAccessibility() { public void testAspectAccessibility() {
IProgramElement packageAspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage");
IProgramElement packageAspect = model.findElementForType(null, "AdviceNamingCoverage");
assertNotNull(packageAspect); assertNotNull(packageAspect);
assertEquals(IProgramElement.Accessibility.PACKAGE, packageAspect.getAccessibility()); assertEquals(IProgramElement.Accessibility.PACKAGE, packageAspect.getAccessibility());
assertEquals("aspect should not have public in it's signature", "aspect AdviceNamingCoverage", packageAspect assertEquals("aspect should not have public in it's signature", "aspect AdviceNamingCoverage", packageAspect
} }


public void testStaticModifiers() { public void testStaticModifiers() {
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "ModifiersCoverage");
IProgramElement aspect = model.findElementForType(null, "ModifiersCoverage");
assertNotNull(aspect); assertNotNull(aspect);


IProgramElement staticA = model.findElementForSignature(aspect, IProgramElement.Kind.FIELD, "staticA"); IProgramElement staticA = model.findElementForSignature(aspect, IProgramElement.Kind.FIELD, "staticA");
IProgramElement finalA = model.findElementForSignature(aspect, IProgramElement.Kind.FIELD, "finalA"); IProgramElement finalA = model.findElementForSignature(aspect, IProgramElement.Kind.FIELD, "finalA");
assertTrue(!finalA.getModifiers().contains(IProgramElement.Modifiers.STATIC)); assertTrue(!finalA.getModifiers().contains(IProgramElement.Modifiers.STATIC));
assertTrue(finalA.getModifiers().contains(IProgramElement.Modifiers.FINAL)); assertTrue(finalA.getModifiers().contains(IProgramElement.Modifiers.FINAL));

} }


public void testFileInPackageAndDefaultPackage() { public void testFileInPackageAndDefaultPackage() {
IProgramElement node = model.getRoot(); IProgramElement node = model.getRoot();
assertNotNull(node); assertNotNull(node);


IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "DeclareCoverage");
IProgramElement aspect = model.findElementForType(null, "DeclareCoverage");
assertNotNull(aspect); assertNotNull(aspect);


String label = "declare error: \"Illegal construct..\""; String label = "declare error: \"Illegal construct..\"";
IProgramElement node = model.getRoot(); IProgramElement node = model.getRoot();
assertNotNull(node); assertNotNull(node);


IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "InterTypeDecCoverage");
IProgramElement aspect = model.findElementForType(null, "InterTypeDecCoverage");
assertNotNull(aspect); assertNotNull(aspect);


String fieldMsg = "Point.xxx"; String fieldMsg = "Point.xxx";
IProgramElement node = model.getRoot(); IProgramElement node = model.getRoot();
assertNotNull(node); assertNotNull(node);


IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage");
IProgramElement aspect = model.findElementForType(null, "AdviceNamingCoverage");
assertNotNull(aspect); assertNotNull(aspect);


String ptct = "named()"; String ptct = "named()";
IProgramElement node = model.getRoot(); IProgramElement node = model.getRoot();
assertNotNull(node); assertNotNull(node);


IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AbstractAspect");
IProgramElement aspect = model.findElementForType(null, "AbstractAspect");
assertNotNull(aspect); assertNotNull(aspect);


String abst = "abPtct()"; String abst = "abPtct()";
IProgramElement node = model.getRoot(); IProgramElement node = model.getRoot();
assertNotNull(node); assertNotNull(node);


IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage");
IProgramElement aspect = model.findElementForType(null, "AdviceNamingCoverage");
assertNotNull(aspect); assertNotNull(aspect);


String anon = "before(): <anonymous pointcut>"; String anon = "before(): <anonymous pointcut>";

+ 104
- 112
ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmRelationshipsTests.java View File



import org.aspectj.ajde.core.AjdeCoreTestCase; import org.aspectj.ajde.core.AjdeCoreTestCase;
import org.aspectj.ajde.core.TestCompilerConfiguration; import org.aspectj.ajde.core.TestCompilerConfiguration;
import org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder;
import org.aspectj.asm.AsmManager; import org.aspectj.asm.AsmManager;
import org.aspectj.asm.IProgramElement; import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.IRelationship; import org.aspectj.asm.IRelationship;


private AsmManager manager = null; private AsmManager manager = null;


private String[] files = new String[]{
"ModelCoverage.java",
"pkg" + File.separator + "InPackage.java"
};
private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" };

private TestCompilerConfiguration compilerConfig; private TestCompilerConfiguration compilerConfig;


protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
initialiseProject("coverage"); initialiseProject("coverage");
compilerConfig = (TestCompilerConfiguration) getCompiler()
.getCompilerConfiguration();
compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
compilerConfig.setProjectSourceFiles(getSourceFileList(files)); compilerConfig.setProjectSourceFiles(getSourceFileList(files));
doBuild(); doBuild();
manager = AsmManager.getDefault();
manager = AsmManager.lastActiveStructureModel;
} }


protected void tearDown() throws Exception { protected void tearDown() throws Exception {
compilerConfig = null; compilerConfig = null;
manager = null; manager = null;
} }
// see pr148027
public void testUsesPointcut() {
if (!AsmHierarchyBuilder.shouldAddUsesPointcut) return;
IProgramElement ptUsage = AsmManager.getDefault().getHierarchy().findElementForType(null, "PointcutUsage");
assertNotNull(ptUsage);
IProgramElement pts = AsmManager.getDefault().getHierarchy().findElementForType(null, "Pointcuts");
assertNotNull(pts);
IProgramElement pUsesA = manager.getHierarchy().findElementForLabel(
ptUsage,
IProgramElement.Kind.POINTCUT,
"usesA()"/*Point"*/);
assertNotNull(pUsesA);

IProgramElement ptsA = manager.getHierarchy().findElementForLabel(
pts,
IProgramElement.Kind.POINTCUT,
"a()"/*Point"*/);
assertNotNull(ptsA);
assertTrue(AsmManager.getDefault().getRelationshipMap().get(pUsesA).size()>0);
assertTrue(AsmManager.getDefault().getRelationshipMap().get(ptsA).size()>0);
}
public void testDeclareParents() {
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "DeclareCoverage");

IProgramElement dp = manager.getHierarchy().findElementForLabel(
aspect,
IProgramElement.Kind.DECLARE_PARENTS,
"declare parents: implements Serializable"/*Point"*/);

// // see pr148027
// public void testUsesPointcut() {
// if (!AsmHierarchyBuilder.shouldAddUsesPointcut) return;
//
// IProgramElement ptUsage = AsmManager.getDefault().getHierarchy().findElementForType(null, "PointcutUsage");
// assertNotNull(ptUsage);
// IProgramElement pts = AsmManager.getDefault().getHierarchy().findElementForType(null, "Pointcuts");
// assertNotNull(pts);
//
// IProgramElement pUsesA = manager.getHierarchy().findElementForLabel(
// ptUsage,
// IProgramElement.Kind.POINTCUT,
// "usesA()"/*Point"*/);
// assertNotNull(pUsesA);
//
// IProgramElement ptsA = manager.getHierarchy().findElementForLabel(
// pts,
// IProgramElement.Kind.POINTCUT,
// "a()"/*Point"*/);
// assertNotNull(ptsA);
//
// assertTrue(AsmManager.getDefault().getRelationshipMap().get(pUsesA).size()>0);
// assertTrue(AsmManager.getDefault().getRelationshipMap().get(ptsA).size()>0);
// }

public void testDeclareParents() {
IProgramElement aspect = manager.getHierarchy().findElementForType(null, "DeclareCoverage");

IProgramElement dp = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.DECLARE_PARENTS,
"declare parents: implements Serializable"/* Point" */);

assertNotNull(dp); assertNotNull(dp);
/*List relations = */manager.getRelationshipMap().get(dp);
List rels = AsmManager.getDefault().getRelationshipMap().get(dp);
assertTrue(rels.size()>0);
// assertTrue(rel.getTargets().size() > 0);
//
// checkDeclareMapping("DeclareCoverage", "Point", ,
// "Point", "matched by", "matches declare",
// IProgramElement.Kind.DECLARE_PARENTS);
/* List relations = */manager.getRelationshipMap().get(dp);
List rels = manager.getRelationshipMap().get(dp);
assertTrue(rels.size() > 0);
// assertTrue(rel.getTargets().size() > 0);
//
// checkDeclareMapping("DeclareCoverage", "Point", ,
// "Point", "matched by", "matches declare",
// IProgramElement.Kind.DECLARE_PARENTS);
} }
public void testDeclareWarningAndError() {
checkDeclareMapping("DeclareCoverage", "Point", "declare warning: \"Illegal call.\"",
"method-call(void Point.setX(int))", "matched by", "matches declare", IProgramElement.Kind.DECLARE_WARNING);
public void testDeclareWarningAndError() {
checkDeclareMapping("DeclareCoverage", "Point", "declare warning: \"Illegal call.\"", "method-call(void Point.setX(int))",
"matched by", "matches declare", IProgramElement.Kind.DECLARE_WARNING);
} }
public void testInterTypeDeclarations() {
checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.xxx", "Point",
"declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_FIELD);
checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.check(int,Line)",
"Point", "declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_METHOD);
public void testInterTypeDeclarations() {
checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.xxx", "Point", "declared on", "aspect declarations",
IProgramElement.Kind.INTER_TYPE_FIELD);
checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.check(int,Line)", "Point", "declared on",
"aspect declarations", IProgramElement.Kind.INTER_TYPE_METHOD);
} }


public void testAdvice() {
checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..",
"setX(int)", "advises", "advised by");
checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..",
"field-get(int Point.x)", "advises");
checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..",
"field-set(int Point.x)", "advises");
public void testAdvice() {
checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", "setX(int)", "advises", "advised by");
checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", "field-get(int Point.x)", "advises");
checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", "field-set(int Point.x)", "advises");
} }


private void checkDeclareMapping(String fromType, String toType, String from, String to,
String forwardRelName, String backRelName, IProgramElement.Kind kind) {
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);
private void checkDeclareMapping(String fromType, String toType, String from, String to, String forwardRelName,
String backRelName, IProgramElement.Kind kind) {
IProgramElement aspect = manager.getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);
String beforeExec = from; String beforeExec = from;
IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, kind, beforeExec); IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, kind, beforeExec);
assertNotNull(beforeExecNode); assertNotNull(beforeExecNode);
IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.DECLARE, forwardRelName); IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.DECLARE, forwardRelName);
assertTrue(rel.getTargets().size() > 0); assertTrue(rel.getTargets().size() > 0);
String handle = (String)rel.getTargets().get(0);
assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);
String handle = (String) rel.getTargets().get(0);
assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);


IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType);
IProgramElement clazz = manager.getHierarchy().findElementForType(null, toType);
assertNotNull(clazz); assertNotNull(clazz);
String set = to; String set = to;
IProgramElement setNode = manager.getHierarchy().findElementForLabel(clazz, IProgramElement.Kind.CODE, set); IProgramElement setNode = manager.getHierarchy().findElementForLabel(clazz, IProgramElement.Kind.CODE, set);
assertNotNull(setNode); assertNotNull(setNode);
IRelationship rel2 = manager.getRelationshipMap().get(setNode, IRelationship.Kind.DECLARE, backRelName); IRelationship rel2 = manager.getRelationshipMap().get(setNode, IRelationship.Kind.DECLARE, backRelName);
String handle2 = (String)rel2.getTargets().get(0);
String handle2 = (String) rel2.getTargets().get(0);
assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from); assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from);
} }
private void checkUniDirectionalMapping(String fromType, String toType, String from,
String to, String relName) {
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);

private void checkUniDirectionalMapping(String fromType, String toType, String from, String to, String relName) {

IProgramElement aspect = manager.getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);
String beforeExec = from; String beforeExec = from;
IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
IProgramElement beforeExecNode = manager.getHierarchy()
.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
assertNotNull(beforeExecNode); assertNotNull(beforeExecNode);
IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName); IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName);
for (Iterator it = rel.getTargets().iterator(); it.hasNext(); ) {
String currHandle = (String)it.next();
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) return;
for (Iterator it = rel.getTargets().iterator(); it.hasNext();) {
String currHandle = (String) it.next();
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to))
return;
} }
fail(); // didn't find it fail(); // didn't find it
} }


private void checkMapping(String fromType, String toType, String from, String to,
String forwardRelName, String backRelName) {
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);
private void checkMapping(String fromType, String toType, String from, String to, String forwardRelName, String backRelName) {

IProgramElement aspect = manager.getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);
String beforeExec = from; String beforeExec = from;
IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
IProgramElement beforeExecNode = manager.getHierarchy()
.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
assertNotNull(beforeExecNode); assertNotNull(beforeExecNode);
IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, forwardRelName); IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, forwardRelName);
String handle = (String)rel.getTargets().get(0);
assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);
String handle = (String) rel.getTargets().get(0);
assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);


IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType);
IProgramElement clazz = manager.getHierarchy().findElementForType(null, toType);
assertNotNull(clazz); assertNotNull(clazz);
String set = to; String set = to;
IProgramElement setNode = manager.getHierarchy().findElementForLabel(clazz, IProgramElement.Kind.METHOD, set); IProgramElement setNode = manager.getHierarchy().findElementForLabel(clazz, IProgramElement.Kind.METHOD, set);
assertNotNull(setNode); assertNotNull(setNode);
IRelationship rel2 = manager.getRelationshipMap().get(setNode, IRelationship.Kind.ADVICE, backRelName); IRelationship rel2 = manager.getRelationshipMap().get(setNode, IRelationship.Kind.ADVICE, backRelName);
String handle2 = (String)rel2.getTargets().get(0);
String handle2 = (String) rel2.getTargets().get(0);
assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from); assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from);
} }


private void checkInterTypeMapping(String fromType, String toType, String from,
String to, String forwardRelName, String backRelName, IProgramElement.Kind declareKind) {
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);
private void checkInterTypeMapping(String fromType, String toType, String from, String to, String forwardRelName,
String backRelName, IProgramElement.Kind declareKind) {
IProgramElement aspect = manager.getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);
String beforeExec = from; String beforeExec = from;
IProgramElement fromNode = manager.getHierarchy().findElementForLabel(aspect, declareKind, beforeExec); IProgramElement fromNode = manager.getHierarchy().findElementForLabel(aspect, declareKind, beforeExec);
assertNotNull(fromNode); assertNotNull(fromNode);
IRelationship rel = manager.getRelationshipMap().get(fromNode, IRelationship.Kind.DECLARE_INTER_TYPE, forwardRelName); IRelationship rel = manager.getRelationshipMap().get(fromNode, IRelationship.Kind.DECLARE_INTER_TYPE, forwardRelName);
String handle = (String)rel.getTargets().get(0);
assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);
String handle = (String) rel.getTargets().get(0);
assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);


IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType);
IProgramElement clazz = manager.getHierarchy().findElementForType(null, toType);
assertNotNull(clazz); assertNotNull(clazz);
// String set = to;
// String set = to;
IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName); IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName);
// String handle2 = (String)rel2.getTargets().get(0);
for (Iterator it = rel2.getTargets().iterator(); it.hasNext(); ) {
String currHandle = (String)it.next();
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) return;
// String handle2 = (String)rel2.getTargets().get(0);
for (Iterator it = rel2.getTargets().iterator(); it.hasNext();) {
String currHandle = (String) it.next();
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from))
return;
} }
fail(); // didn't find it fail(); // didn't find it
} }

+ 53
- 60
ajde.core/testsrc/org/aspectj/ajde/core/tests/model/SavedModelConsistencyTests.java View File



public class SavedModelConsistencyTests extends AjdeCoreTestCase { public class SavedModelConsistencyTests extends AjdeCoreTestCase {


private String[] files = new String[]{
"ModelCoverage.java",
"pkg" + File.separator + "InPackage.java"
};
private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" };

private TestMessageHandler handler; private TestMessageHandler handler;
private TestCompilerConfiguration compilerConfig; private TestCompilerConfiguration compilerConfig;


super.setUp(); super.setUp();
initialiseProject("coverage"); initialiseProject("coverage");
handler = (TestMessageHandler) getCompiler().getMessageHandler(); handler = (TestMessageHandler) getCompiler().getMessageHandler();
compilerConfig = (TestCompilerConfiguration) getCompiler()
.getCompilerConfiguration();
compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
compilerConfig.setProjectSourceFiles(getSourceFileList(files)); compilerConfig.setProjectSourceFiles(getSourceFileList(files));
// In order to get a model on the disk to read in, do a build with the right flag set ! // In order to get a model on the disk to read in, do a build with the right flag set !
try { try {
AsmManager.dumpModelPostBuild=true;
AsmManager.dumpModelPostBuild = true;
doBuild(); doBuild();
} finally { } finally {
AsmManager.dumpModelPostBuild=false;
AsmManager.dumpModelPostBuild = false;
} }
assertTrue("Expected no compiler errors but found "
+ handler.getErrors(), handler.getErrors().isEmpty());
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());
} }


protected void tearDown() throws Exception { protected void tearDown() throws Exception {
handler = null; handler = null;
compilerConfig = null; compilerConfig = null;
} }
public void testInterfaceIsSameInBoth() { public void testInterfaceIsSameInBoth() {
AsmManager.getDefault().readStructureModel(getAbsoluteProjectDir());
IHierarchy model = AsmManager.getDefault().getHierarchy();
assertTrue("model exists", model != null);
assertTrue("root exists", model.getRoot() != null); // TODO-path
AsmManager asm = AsmManager.createNewStructureModel();
asm.readStructureModel(getAbsoluteProjectDir());

IHierarchy model = asm.getHierarchy();
assertTrue("model exists", model != null);

assertTrue("root exists", model.getRoot() != null); // TODO-path
File testFile = openFile("ModelCoverage.java"); File testFile = openFile("ModelCoverage.java");
assertTrue("Expected " + testFile.getAbsolutePath() + " to exist, but it did not", testFile.exists()); assertTrue("Expected " + testFile.getAbsolutePath() + " to exist, but it did not", testFile.exists());
IProgramElement nodePreBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);
IProgramElement nodePreBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);
doBuild(); doBuild();
assertTrue("Expected no compiler errors but found "
+ handler.getErrors(), handler.getErrors().isEmpty());
IProgramElement nodePostBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);
assertTrue("Nodes should be identical: Prebuild kind = "+nodePreBuild.getKind()+
" Postbuild kind = "+nodePostBuild.getKind(),
nodePreBuild.getKind().equals(nodePostBuild.getKind()));
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());

IProgramElement nodePostBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);

assertTrue("Nodes should be identical: Prebuild kind = " + nodePreBuild.getKind() + " Postbuild kind = "
+ nodePostBuild.getKind(), nodePreBuild.getKind().equals(nodePostBuild.getKind()));

} }

public void testModelIsSamePreAndPostBuild() { public void testModelIsSamePreAndPostBuild() {
AsmManager.getDefault().readStructureModel(getAbsoluteProjectDir());
IHierarchy model = AsmManager.getDefault().getHierarchy();
assertTrue("model exists", model != null);
final List preBuildKinds = new ArrayList();
AsmManager asm = AsmManager.createNewStructureModel();
asm.readStructureModel(getAbsoluteProjectDir());
// AsmManager.getDefault().readStructureModel(getAbsoluteProjectDir());
IHierarchy model = asm.getHierarchy();
assertTrue("model exists", model != null);

final List preBuildKinds = new ArrayList();
HierarchyWalker walker = new HierarchyWalker() { HierarchyWalker walker = new HierarchyWalker() {
public void preProcess(IProgramElement node) {
preBuildKinds.add(node.getKind());
}
};
AsmManager.getDefault().getHierarchy().getRoot().walk(walker);
assertFalse("Expected there to be build kinds but didn't "
+ "find any", preBuildKinds.isEmpty());
public void preProcess(IProgramElement node) {
preBuildKinds.add(node.getKind());
}
};
asm.getHierarchy().getRoot().walk(walker);
assertFalse("Expected there to be build kinds but didn't " + "find any", preBuildKinds.isEmpty());

doBuild(); doBuild();
assertTrue("Expected no compiler errors but found "
+ handler.getErrors(), handler.getErrors().isEmpty());
final List postBuildKinds = new ArrayList();
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());

final List postBuildKinds = new ArrayList();
HierarchyWalker walker2 = new HierarchyWalker() { HierarchyWalker walker2 = new HierarchyWalker() {
public void preProcess(IProgramElement node) {
postBuildKinds.add(node.getKind());
}
};
AsmManager.getDefault().getHierarchy().getRoot().walk(walker2);
assertFalse("Expected there to be build kinds but didn't "
+ "find any", preBuildKinds.isEmpty());

assertTrue("Lists should be the same: PRE"+preBuildKinds.toString()
+" POST"+postBuildKinds.toString(),preBuildKinds.equals(postBuildKinds));
public void preProcess(IProgramElement node) {
postBuildKinds.add(node.getKind());
}
};
asm.getHierarchy().getRoot().walk(walker2);
assertFalse("Expected there to be build kinds but didn't " + "find any", preBuildKinds.isEmpty());

assertTrue("Lists should be the same: PRE" + preBuildKinds.toString() + " POST" + postBuildKinds.toString(), preBuildKinds
.equals(postBuildKinds));

} }
} }

+ 59
- 65
ajde.core/testsrc/org/aspectj/ajde/core/tests/model/StructureModelTests.java View File



private AsmManager manager = null; private AsmManager manager = null;


private String[] files = new String[]{
"figures" + File.separator + "Debug.java",
"figures" + File.separator + "Figure.java",
"figures" + File.separator + "FigureElement.java",
"figures" + File.separator + "Main.java",
"figures" + File.separator + "composites" + File.separator + "Line.java",
private final String[] files = new String[] { "figures" + File.separator + "Debug.java",
"figures" + File.separator + "Figure.java", "figures" + File.separator + "FigureElement.java",
"figures" + File.separator + "Main.java", "figures" + File.separator + "composites" + File.separator + "Line.java",
"figures" + File.separator + "composites" + File.separator + "Square.java", "figures" + File.separator + "composites" + File.separator + "Square.java",
"figures" + File.separator + "primitives" + File.separator + "planar" + File.separator + "Point.java", "figures" + File.separator + "primitives" + File.separator + "planar" + File.separator + "Point.java",
"figures" + File.separator + "primitives" + File.separator + "solid" + File.separator + "SolidPoint.java"
};
"figures" + File.separator + "primitives" + File.separator + "solid" + File.separator + "SolidPoint.java" };

private TestCompilerConfiguration compilerConfig; private TestCompilerConfiguration compilerConfig;


protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
initialiseProject("figures-coverage"); initialiseProject("figures-coverage");
compilerConfig = (TestCompilerConfiguration) getCompiler()
.getCompilerConfiguration();
compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
compilerConfig.setProjectSourceFiles(getSourceFileList(files)); compilerConfig.setProjectSourceFiles(getSourceFileList(files));
doBuild(); doBuild();
manager = AsmManager.getDefault();
manager = AsmManager.lastActiveStructureModel;
} }


protected void tearDown() throws Exception { protected void tearDown() throws Exception {
compilerConfig = null; compilerConfig = null;
manager = null; manager = null;
} }
public void testRootForSourceFile() throws IOException { public void testRootForSourceFile() throws IOException {
File testFile = openFile("figures" + File.separator + "Figure.java");
IProgramElement node = manager.getHierarchy().findElementForSourceFile(
testFile.getAbsolutePath());
assertTrue("find result", node != null) ;
String child = ((IProgramElement)node.getChildren().get(1)).getName();
assertTrue("expected Figure got child " + child, child.equals("Figure"));
File testFile = openFile("figures" + File.separator + "Figure.java");
IProgramElement node = manager.getHierarchy().findElementForSourceFile(testFile.getAbsolutePath());
assertTrue("find result", node != null);
String child = ((IProgramElement) node.getChildren().get(1)).getName();
assertTrue("expected Figure got child " + child, child.equals("Figure"));
} }


public void testPointcutName() throws IOException { public void testPointcutName() throws IOException {
File testFile = openFile("figures" + File.separator + "Main.java");
IProgramElement node = manager.getHierarchy().findElementForSourceFile(
testFile.getAbsolutePath());
assertTrue("find result", node != null) ;
IProgramElement pNode = (IProgramElement)(node).getChildren().get(2);
IProgramElement pointcut = (IProgramElement)pNode.getChildren().get(0);
File testFile = openFile("figures" + File.separator + "Main.java");
IProgramElement node = manager.getHierarchy().findElementForSourceFile(testFile.getAbsolutePath());
assertTrue("find result", node != null);
IProgramElement pNode = (IProgramElement) (node).getChildren().get(2);
IProgramElement pointcut = (IProgramElement) pNode.getChildren().get(0);
assertTrue("kind", pointcut.getKind().equals(IProgramElement.Kind.POINTCUT)); assertTrue("kind", pointcut.getKind().equals(IProgramElement.Kind.POINTCUT));
assertTrue("found node: " + pointcut.getName(), pointcut.toLabelString().equals("testptct()")); assertTrue("found node: " + pointcut.getName(), pointcut.toLabelString().equals("testptct()"));
} }


public void testFileNodeFind() throws IOException { public void testFileNodeFind() throws IOException {
File testFile = openFile("figures" + File.separator + "Main.java"); File testFile = openFile("figures" + File.separator + "Main.java");
// System.err.println(((IProgramElement)((IProgramElement)Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot().getChildren().get(0)).getChildren().get(3)).getSourceLocation().getSourceFile().getAbsolutePath());
// System.err.println(testFile.getAbsolutePath());
IProgramElement node = manager.getHierarchy().findElementForSourceLine(
testFile.getAbsolutePath(), 1);
assertTrue("find result", node != null) ;
assertEquals("find result has children", 3, node.getChildren().size()) ;

// System.err.println(((IProgramElement)((IProgramElement)Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot().getChildren().get(0)).getChildren().get(3)).getSourceLocation().getSourceFile().getAbsolutePath());
// System.err.println(testFile.getAbsolutePath());

IProgramElement node = manager.getHierarchy().findElementForSourceLine(testFile.getAbsolutePath(), 1);
assertTrue("find result", node != null);
assertEquals("find result has children", 3, node.getChildren().size());
assertTrue("found node: " + node.getName(), node.getKind().equals(IProgramElement.Kind.FILE_JAVA)); assertTrue("found node: " + node.getName(), node.getKind().equals(IProgramElement.Kind.FILE_JAVA));
} }
/**
* @todo add negative test to make sure things that aren't runnable aren't annotated
*/
/**
* @todo add negative test to make sure things that aren't runnable aren't annotated
*/
public void testMainClassNodeInfo() throws IOException { public void testMainClassNodeInfo() throws IOException {
IHierarchy model = manager.getHierarchy();
assertTrue("model exists", model != null);
IHierarchy model = manager.getHierarchy();
assertTrue("model exists", model != null);
assertTrue("root exists", model.getRoot() != null); assertTrue("root exists", model.getRoot() != null);
File testFile = openFile("figures" + File.separator + "Main.java"); File testFile = openFile("figures" + File.separator + "Main.java");
IProgramElement node = model.findElementForSourceLine(testFile.getAbsolutePath(), 11);
assertTrue("find result", node != null);
IProgramElement node = model.findElementForSourceLine(testFile.getAbsolutePath(), 11);
assertTrue("find result", node != null);
IProgramElement pNode = node.getParent(); IProgramElement pNode = node.getParent();
if (null == pNode) {
assertTrue("null parent of " + node, false);
}
if (null == pNode) {
assertTrue("null parent of " + node, false);
}
assertTrue("found node: " + pNode.getName(), pNode.isRunnable()); assertTrue("found node: " + pNode.getName(), pNode.isRunnable());
}
}
/** /**
* Integrity could be checked somewhere in the API. * Integrity could be checked somewhere in the API.
*/
*/
public void testModelIntegrity() { public void testModelIntegrity() {
IProgramElement modelRoot = manager.getHierarchy().getRoot(); IProgramElement modelRoot = manager.getHierarchy().getRoot();
assertTrue("root exists", modelRoot != null);
assertTrue("root exists", modelRoot != null);
try { try {
testModelIntegrityHelper(modelRoot); testModelIntegrityHelper(modelRoot);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.toString(), false);
assertTrue(e.toString(), false);
} }
} }


private void testModelIntegrityHelper(IProgramElement node) throws Exception { private void testModelIntegrityHelper(IProgramElement node) throws Exception {
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
IProgramElement child = (IProgramElement)it.next();
for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
IProgramElement child = (IProgramElement) it.next();
if (node == child.getParent()) { if (node == child.getParent()) {
testModelIntegrityHelper(child); testModelIntegrityHelper(child);
} else { } else {
throw new Exception("parent-child check failed for child: " + child.toString()); throw new Exception("parent-child check failed for child: " + child.toString());
} }
}
}
}

public void testNoChildIsNull() {
HierarchyWalker walker = new HierarchyWalker() {
public void preProcess(IProgramElement node) {
if (node.getChildren() == null)
return;
for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
if (it.next() == null)
throw new NullPointerException("null child on node: " + node.getName());
}
}
};
manager.getHierarchy().getRoot().walk(walker);
} }
public void testNoChildIsNull() {
HierarchyWalker walker = new HierarchyWalker() {
public void preProcess(IProgramElement node) {
if (node.getChildren() == null) return;
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
if (it.next() == null) throw new NullPointerException("null child on node: " + node.getName());
}
}
};
manager.getHierarchy().getRoot().walk(walker);
}
} }

Loading…
Cancel
Save