diff options
author | mkersten <mkersten> | 2003-08-08 11:02:53 +0000 |
---|---|---|
committer | mkersten <mkersten> | 2003-08-08 11:02:53 +0000 |
commit | f1deb9c11024ecebab2e0aa17a260821375c25bd (patch) | |
tree | 9c3434439dddfb2e90a40187c8255ff80a2b147f /org.aspectj.ajdt.core | |
parent | 3e5974557278e81a9891edd4269eca39a8d42f43 (diff) | |
download | aspectj-f1deb9c11024ecebab2e0aa17a260821375c25bd.tar.gz aspectj-f1deb9c11024ecebab2e0aa17a260821375c25bd.zip |
Reimplemented ASM API as described in bug "41254: revise asm and create interfaces". Containment hierarchy is done and tests added. Relationships are not done yet. All clients except AJDT ported. More UI porting in Swing clients required.
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java | 15 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java | 33 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java (renamed from org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java) | 188 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java | 40 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java | 81 | ||||
-rw-r--r-- | org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AsmBuilderTest.java | 2 |
6 files changed, 178 insertions, 181 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java index e9f9f0402..244ab288c 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java @@ -15,19 +15,16 @@ package org.aspectj.ajdt.internal.compiler.lookup; import java.util.*; -import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration; -import org.aspectj.ajdt.internal.compiler.ast.AstUtil; -import org.aspectj.ajdt.internal.core.builder.AjBuildManager; -import org.aspectj.ajdt.internal.core.builder.AsmBuilder; +import org.aspectj.ajdt.internal.compiler.ast.*; +import org.aspectj.ajdt.internal.core.builder.*; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.IMessage.Kind; import org.aspectj.weaver.*; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ast.*; -import org.eclipse.jdt.internal.compiler.impl.Constant; -import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; +import org.eclipse.jdt.internal.compiler.impl.*; import org.eclipse.jdt.internal.compiler.lookup.*; -import org.eclipse.jdt.core.compiler.CharOperation; - + /** * * @author Jim Hugunin @@ -300,7 +297,7 @@ public class EclipseFactory { public void finishedCompilationUnit(CompilationUnitDeclaration unit) { if (buildManager.doGenerateModel()) { - AsmBuilder.build(unit, buildManager.getStructureModel()); + AsmHierarchyBuilder.build(unit, buildManager.getStructureModel()); } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index ab0551dbe..162f852d0 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -13,33 +13,24 @@ package org.aspectj.ajdt.internal.core.builder; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.util.*; -import java.util.jar.Attributes; -import java.util.jar.JarFile; -import java.util.jar.Manifest; +import java.util.jar.*; import org.aspectj.ajdt.internal.compiler.AjCompiler; -import org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment; -import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory; +import org.aspectj.ajdt.internal.compiler.lookup.*; import org.aspectj.ajdt.internal.compiler.parser.AjParser; import org.aspectj.ajdt.internal.compiler.problem.AjProblemReporter; -import org.aspectj.asm.ProgramElementNode; -import org.aspectj.asm.StructureModel; -import org.aspectj.asm.StructureModelManager; +import org.aspectj.asm.*; +import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.*; import org.aspectj.weaver.World; -import org.aspectj.weaver.bcel.BcelWeaver; -import org.aspectj.weaver.bcel.BcelWorld; -import org.aspectj.weaver.bcel.UnwovenClassFile; -import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.core.compiler.IProblem; +import org.aspectj.weaver.bcel.*; +import org.eclipse.jdt.core.compiler.*; import org.eclipse.jdt.internal.compiler.*; -import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.batch.*; import org.eclipse.jdt.internal.compiler.batch.FileSystem; -import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; -import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.env.*; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; @@ -177,15 +168,15 @@ public class AjBuildManager { private void setupModel() { String rootLabel = "<root>"; StructureModel model = StructureModelManager.getDefault().getStructureModel(); - ProgramElementNode.Kind kind = ProgramElementNode.Kind.FILE_JAVA; + IProgramElement.Kind kind = IProgramElement.Kind.FILE_JAVA; if (buildConfig.getConfigFile() != null) { rootLabel = buildConfig.getConfigFile().getName(); model.setConfigFile( buildConfig.getConfigFile().getAbsolutePath() ); - kind = ProgramElementNode.Kind.FILE_LST; + kind = IProgramElement.Kind.FILE_LST; } - model.setRoot(new ProgramElementNode(rootLabel, kind, new ArrayList())); + model.setRoot(new ProgramElement(rootLabel, kind, new ArrayList())); HashMap modelFileMap = new HashMap(); model.setFileMap(new HashMap()); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java index 3c3528975..1cdc99870 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java @@ -16,33 +16,32 @@ package org.aspectj.ajdt.internal.core.builder; import java.io.*; import java.util.*; -import org.aspectj.ajdt.internal.compiler.ast.*; +import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration; import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory; import org.aspectj.asm.*; +import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.*; import org.aspectj.util.LangUtil; -import org.aspectj.weaver.*; -import org.aspectj.weaver.patterns.*; +import org.aspectj.weaver.Member; import org.eclipse.jdt.internal.compiler.*; import org.eclipse.jdt.internal.compiler.ast.*; import org.eclipse.jdt.internal.compiler.lookup.*; import org.eclipse.jdt.internal.compiler.problem.ProblemHandler; -public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { +public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { - public static void build( + public static void build( CompilationUnitDeclaration unit, StructureModel structureModel) { LangUtil.throwIaxIfNull(unit, "unit"); - - new AsmBuilder(unit.compilationResult()).internalBuild(unit, structureModel); + new AsmHierarchyBuilder(unit.compilationResult()).internalBuild(unit, structureModel); } private final Stack stack; private final CompilationResult currCompilationResult; private AsmNodeFormatter formatter = new AsmNodeFormatter(); - protected AsmBuilder(CompilationResult result) { + protected AsmHierarchyBuilder(CompilationResult result) { LangUtil.throwIaxIfNull(result, "result"); currCompilationResult = result; stack = new Stack(); @@ -55,7 +54,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { private void internalBuild( CompilationUnitDeclaration unit, StructureModel structureModel) { - LangUtil.throwIaxIfNull(structureModel, "structureModel"); + LangUtil.throwIaxIfNull(structureModel, "structureModel"); if (!currCompilationResult.equals(unit.compilationResult())) { throw new IllegalArgumentException("invalid unit: " + unit); } @@ -67,67 +66,27 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { // -- create node to add final File file = new File(new String(unit.getFileName())); - final ProgramElementNode cuNode; + final IProgramElement cuNode; { // AMC - use the source start and end from the compilation unit decl int startLine = getStartLine(unit); int endLine = getEndLine(unit); ISourceLocation sourceLocation = new SourceLocation(file, startLine, endLine); - cuNode = new ProgramElementNode( + cuNode = new ProgramElement( new String(file.getName()), - ProgramElementNode.Kind.FILE_JAVA, + IProgramElement.Kind.FILE_JAVA, sourceLocation, 0, "", new ArrayList()); } - // -- get node (package or root) to add to - final StructureNode addToNode; - { - ImportReference currentPackage = unit.currentPackage; - if (null == currentPackage) { - addToNode = structureModel.getRoot(); - } else { - String pkgName; - { - StringBuffer nameBuffer = new StringBuffer(); - final char[][] importName = currentPackage.getImportName(); - final int last = importName.length-1; - for (int i = 0; i < importName.length; i++) { - nameBuffer.append(new String(importName[i])); - if (i < last) { - nameBuffer.append('.'); - } - } - pkgName = nameBuffer.toString(); - } - - ProgramElementNode pkgNode = null; - for (Iterator it = structureModel.getRoot().getChildren().iterator(); - it.hasNext(); ) { - ProgramElementNode currNode = (ProgramElementNode)it.next(); - if (pkgName.equals(currNode.getName())) { - pkgNode = currNode; - break; // any reason not to quit when found? - } - } - if (pkgNode == null) { - // note packages themselves have no source location - pkgNode = new ProgramElementNode( - pkgName, - ProgramElementNode.Kind.PACKAGE, - new ArrayList()); - structureModel.getRoot().addChild(pkgNode); - } - addToNode = pkgNode; - } - } + final IProgramElement addToNode = genAddToNode(unit, structureModel); // -- remove duplicates before adding (XXX use them instead?) for (ListIterator itt = addToNode.getChildren().listIterator(); itt.hasNext(); ) { - ProgramElementNode child = (ProgramElementNode)itt.next(); + IProgramElement child = (IProgramElement)itt.next(); ISourceLocation childLoc = child.getSourceLocation(); if (null == childLoc) { // XXX ok, packages have null source locations @@ -149,15 +108,66 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { + " creating path for " + file ); // XXX signal IOException when canonicalizing file path } - } + + } + + /** + * Get/create teh node (package or root) to add to. + */ + private IProgramElement genAddToNode( + CompilationUnitDeclaration unit, + StructureModel structureModel) { + final IProgramElement addToNode; + { + ImportReference currentPackage = unit.currentPackage; + if (null == currentPackage) { + addToNode = structureModel.getRoot(); + } else { + String pkgName; + { + StringBuffer nameBuffer = new StringBuffer(); + final char[][] importName = currentPackage.getImportName(); + final int last = importName.length-1; + for (int i = 0; i < importName.length; i++) { + nameBuffer.append(new String(importName[i])); + if (i < last) { + nameBuffer.append('.'); + } + } + pkgName = nameBuffer.toString(); + } + + IProgramElement pkgNode = null; + for (Iterator it = structureModel.getRoot().getChildren().iterator(); + it.hasNext(); ) { + IProgramElement currNode = (IProgramElement)it.next(); + if (pkgName.equals(currNode.getName())) { + pkgNode = currNode; + break; + } + } + if (pkgNode == null) { + // note packages themselves have no source location + pkgNode = new ProgramElement( + pkgName, + IProgramElement.Kind.PACKAGE, + new ArrayList() + ); + structureModel.getRoot().addChild(pkgNode); + } + addToNode = pkgNode; + } + } + return addToNode; + } public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { String name = new String(typeDeclaration.name); - ProgramElementNode.Kind kind = ProgramElementNode.Kind.CLASS; - if (typeDeclaration instanceof AspectDeclaration) kind = ProgramElementNode.Kind.ASPECT; - else if (typeDeclaration.isInterface()) kind = ProgramElementNode.Kind.INTERFACE; + IProgramElement.Kind kind = IProgramElement.Kind.CLASS; + if (typeDeclaration instanceof AspectDeclaration) kind = IProgramElement.Kind.ASPECT; + else if (typeDeclaration.isInterface()) kind = IProgramElement.Kind.INTERFACE; - ProgramElementNode peNode = new ProgramElementNode( + IProgramElement peNode = new ProgramElement( name, kind, makeLocation(typeDeclaration), @@ -166,7 +176,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { // peNode.setFullSignature(typeDeclaration.()); - ((StructureNode)stack.peek()).addChild(peNode); + ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); return true; } @@ -179,11 +189,11 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { 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; + IProgramElement.Kind kind = IProgramElement.Kind.CLASS; + if (memberTypeDeclaration instanceof AspectDeclaration) kind = IProgramElement.Kind.ASPECT; + else if (memberTypeDeclaration.isInterface()) kind = IProgramElement.Kind.INTERFACE; - ProgramElementNode peNode = new ProgramElementNode( + IProgramElement peNode = new ProgramElement( name, kind, makeLocation(memberTypeDeclaration), @@ -193,7 +203,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { peNode.setFullSignature(memberTypeDeclaration.toString()); - ((StructureNode)stack.peek()).addChild(peNode); + ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); return true; } @@ -216,10 +226,10 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { // System.err.println("member type with name: " + name + ", " + // new String(fullName)); - ProgramElementNode.Kind kind = ProgramElementNode.Kind.CLASS; - if (memberTypeDeclaration.isInterface()) kind = ProgramElementNode.Kind.INTERFACE; + IProgramElement.Kind kind = IProgramElement.Kind.CLASS; + if (memberTypeDeclaration.isInterface()) kind = IProgramElement.Kind.INTERFACE; - ProgramElementNode peNode = new ProgramElementNode( + IProgramElement peNode = new ProgramElement( fullName, kind, makeLocation(memberTypeDeclaration), @@ -244,21 +254,21 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { stack.pop(); } - private StructureNode findEnclosingClass(Stack stack) { + private IProgramElement findEnclosingClass(Stack stack) { for (int i = stack.size()-1; i >= 0; i--) { - ProgramElementNode pe = (ProgramElementNode)stack.get(i); - if (pe.getProgramElementKind() == ProgramElementNode.Kind.CLASS) { + IProgramElement pe = (IProgramElement)stack.get(i); + if (pe.getKind() == IProgramElement.Kind.CLASS) { return pe; } } - return (StructureNode)stack.peek(); + return (IProgramElement)stack.peek(); } public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { - ProgramElementNode peNode = new ProgramElementNode( + IProgramElement peNode = new ProgramElement( "", - ProgramElementNode.Kind.ERROR, + IProgramElement.Kind.ERROR, makeLocation(methodDeclaration), methodDeclaration.modifiers, "", @@ -268,9 +278,9 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { genBytecodeInfo(methodDeclaration, peNode); // TODO: should improve determining what the main method is - if (peNode.getProgramElementKind().equals(ProgramElementNode.Kind.METHOD)) { + if (peNode.getKind().equals(IProgramElement.Kind.METHOD)) { if (peNode.getName().equals("main")) { - ((ProgramElementNode)stack.peek()).setRunnable(true); + ((IProgramElement)stack.peek()).setRunnable(true); } } @@ -278,7 +288,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { return true; } - private void genBytecodeInfo(MethodDeclaration methodDeclaration, ProgramElementNode peNode) { + private void genBytecodeInfo(MethodDeclaration methodDeclaration, IProgramElement peNode) { if (methodDeclaration.binding != null) { String memberName = ""; String memberBytecodeSignature = ""; @@ -293,7 +303,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { peNode.setBytecodeName(memberName); peNode.setBytecodeSignature(memberBytecodeSignature); } - ((StructureNode)stack.peek()).addChild(peNode); + ((IProgramElement)stack.peek()).addChild(peNode); } public void endVisit(MethodDeclaration methodDeclaration, ClassScope scope) { @@ -301,14 +311,14 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { } public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { - ProgramElementNode peNode = new ProgramElementNode( + IProgramElement peNode = new ProgramElement( new String(fieldDeclaration.name), - ProgramElementNode.Kind.FIELD, + IProgramElement.Kind.FIELD, makeLocation(fieldDeclaration), fieldDeclaration.modifiers, "", new ArrayList()); - ((StructureNode)stack.peek()).addChild(peNode); + ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); return true; } @@ -325,7 +335,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { // 0, // "", // new ArrayList()); -// ((StructureNode)stack.peek()).addChild(0, peNode); +// ((IProgramElement)stack.peek()).addChild(0, peNode); // stack.push(peNode); // return true; // } @@ -338,14 +348,14 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { stack.push(null); // a little wierd but does the job return true; } - ProgramElementNode peNode = new ProgramElementNode( + IProgramElement peNode = new ProgramElement( new String(constructorDeclaration.selector), - ProgramElementNode.Kind.CONSTRUCTOR, + IProgramElement.Kind.CONSTRUCTOR, makeLocation(constructorDeclaration), constructorDeclaration.modifiers, "", new ArrayList()); - ((StructureNode)stack.peek()).addChild(peNode); + ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); return true; } @@ -361,7 +371,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { // clinit.modifiers, // "", // new ArrayList()); -// ((StructureNode)stack.peek()).addChild(peNode); +// ((IProgramElement)stack.peek()).addChild(peNode); // stack.push(peNode); // return false; // } @@ -376,14 +386,14 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter { if (initializer == inInitializer) return false; inInitializer = initializer; - ProgramElementNode peNode = new ProgramElementNode( + IProgramElement peNode = new ProgramElement( "...", - ProgramElementNode.Kind.INITIALIZER, + IProgramElement.Kind.INITIALIZER, makeLocation(initializer), initializer.modifiers, "", new ArrayList()); - ((StructureNode)stack.peek()).addChild(peNode); + ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); initializer.block.traverse(this, scope); stack.pop(); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java index b7425d426..e2025743e 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java @@ -13,7 +13,7 @@ package org.aspectj.ajdt.internal.core.builder; import java.util.Iterator; import org.aspectj.ajdt.internal.compiler.ast.*; -import org.aspectj.asm.ProgramElementNode; +import org.aspectj.asm.IProgramElement; import org.aspectj.weaver.*; import org.aspectj.weaver.patterns.*; import org.eclipse.jdt.internal.compiler.ast.*; @@ -31,10 +31,10 @@ public class AsmNodeFormatter { public static final int MAX_MESSAGE_LENGTH = 18; public static final String DEC_LABEL = "declare"; - public void genLabelAndKind(MethodDeclaration methodDeclaration, ProgramElementNode node) { + public void genLabelAndKind(MethodDeclaration methodDeclaration, IProgramElement node) { if (methodDeclaration instanceof AdviceDeclaration) { AdviceDeclaration ad = (AdviceDeclaration)methodDeclaration; - node.setKind( ProgramElementNode.Kind.ADVICE); + node.setKind( IProgramElement.Kind.ADVICE); String label = ""; label += ad.kind.toString(); label += "(" + genArguments(ad) + "): "; @@ -66,12 +66,12 @@ public class AsmNodeFormatter { } } else { label += POINTCUT_ABSTRACT; - } + } node.setName(label); } else if (methodDeclaration instanceof PointcutDeclaration) { PointcutDeclaration pd = (PointcutDeclaration)methodDeclaration; - node.setKind( ProgramElementNode.Kind.POINTCUT); + node.setKind( IProgramElement.Kind.POINTCUT); String label = translatePointcutName(new String(methodDeclaration.selector)); label += "(" + genArguments(pd) + ")"; node.setName(label); @@ -83,29 +83,29 @@ public class AsmNodeFormatter { DeclareErrorOrWarning deow = (DeclareErrorOrWarning)declare.declare; if (deow.isError()) { - node.setKind( ProgramElementNode.Kind.DECLARE_ERROR); + node.setKind( IProgramElement.Kind.DECLARE_ERROR); label += DECLARE_ERROR; } else { - node.setKind( ProgramElementNode.Kind.DECLARE_WARNING); + node.setKind( IProgramElement.Kind.DECLARE_WARNING); label += DECLARE_WARNING; } node.setName(label + "\"" + genDeclareMessage(deow.getMessage()) + "\"") ; } else if (declare.declare instanceof DeclareParents) { - node.setKind( ProgramElementNode.Kind.DECLARE_PARENTS); + node.setKind( IProgramElement.Kind.DECLARE_PARENTS); DeclareParents dp = (DeclareParents)declare.declare; node.setName(label + DECLARE_PARENTS + genTypePatternLabel(dp.getChild())); } else if (declare.declare instanceof DeclareSoft) { - node.setKind( ProgramElementNode.Kind.DECLARE_SOFT); + node.setKind( IProgramElement.Kind.DECLARE_SOFT); DeclareSoft ds = (DeclareSoft)declare.declare; node.setName(label + DECLARE_SOFT + genTypePatternLabel(ds.getException())); } else if (declare.declare instanceof DeclarePrecedence) { - node.setKind( ProgramElementNode.Kind.DECLARE_PRECEDENCE); + node.setKind( IProgramElement.Kind.DECLARE_PRECEDENCE); DeclarePrecedence ds = (DeclarePrecedence)declare.declare; node.setName(label + DECLARE_PRECEDENCE + genPrecedenceListLabel(ds.getPatterns())); } else { - node.setKind( ProgramElementNode.Kind.ERROR); + node.setKind( IProgramElement.Kind.ERROR); node.setName(DECLARE_UNKNONWN); } @@ -113,23 +113,29 @@ public class AsmNodeFormatter { InterTypeDeclaration itd = (InterTypeDeclaration)methodDeclaration; String label = itd.onType.toString() + "." + new String(itd.getDeclaredSelector()); if (methodDeclaration instanceof InterTypeFieldDeclaration) { - node.setKind(ProgramElementNode.Kind.INTER_TYPE_FIELD); + node.setKind(IProgramElement.Kind.INTER_TYPE_FIELD); } else if (methodDeclaration instanceof InterTypeMethodDeclaration) { - node.setKind(ProgramElementNode.Kind.INTER_TYPE_METHOD); + node.setKind(IProgramElement.Kind.INTER_TYPE_METHOD); InterTypeMethodDeclaration itmd = (InterTypeMethodDeclaration)methodDeclaration; label += "(" + genArguments(itd) + ")"; } else if (methodDeclaration instanceof InterTypeConstructorDeclaration) { - node.setKind(ProgramElementNode.Kind.INTER_TYPE_CONSTRUCTOR); + node.setKind(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); InterTypeConstructorDeclaration itcd = (InterTypeConstructorDeclaration)methodDeclaration; } else { - node.setKind(ProgramElementNode.Kind.ERROR); + node.setKind(IProgramElement.Kind.ERROR); } node.setName(label); node.setReturnType(itd.returnType.toString()); } else { - node.setKind(ProgramElementNode.Kind.METHOD); - node.setName(new String(methodDeclaration.selector)); + if (methodDeclaration.isConstructor()) { + node.setKind(IProgramElement.Kind.CONSTRUCTOR); + } else { + node.setKind(IProgramElement.Kind.METHOD); + } + String label = new String(methodDeclaration.selector); + label += "(" + genArguments(methodDeclaration) + ")"; + node.setName(label); } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java index 8f662e160..74a394da4 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java @@ -14,20 +14,10 @@ package org.aspectj.ajdt.internal.core.builder; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.aspectj.asm.AdviceAssociation; -import org.aspectj.asm.IntroductionAssociation; -import org.aspectj.asm.LinkNode; -import org.aspectj.asm.ProgramElementNode; -import org.aspectj.asm.RelationNode; -import org.aspectj.asm.StructureModelManager; +import java.io.*; +import java.util.*; + +import org.aspectj.asm.*; //import org.aspectj.ajde.compiler.AjdeCompiler; /** @@ -48,7 +38,7 @@ public class EmacsStructureModelManager { //Set fileSet = StructureModelManager.INSTANCE.getStructureModel().getFileMap().entrySet(); Set fileSet = StructureModelManager.getDefault().getStructureModel().getFileMapEntrySet(); for (Iterator it = fileSet.iterator(); it.hasNext(); ) { - ProgramElementNode peNode = (ProgramElementNode)((Map.Entry)it.next()).getValue(); + IProgramElement peNode = (IProgramElement)((Map.Entry)it.next()).getValue(); dumpStructureToFile(peNode); } } catch (IOException ioe) { @@ -64,10 +54,10 @@ public class EmacsStructureModelManager { // writer.flush(); // } - private void dumpStructureToFile(ProgramElementNode node) throws IOException { - String s = node.getKind(); - if (! (s.equals(ProgramElementNode.Kind.FILE_ASPECTJ.toString()) - || s.equals(ProgramElementNode.Kind.FILE_JAVA.toString()))) { + private void dumpStructureToFile(IProgramElement node) throws IOException { + String s = node.getKind().toString(); + if (! (s.equals(IProgramElement.Kind.FILE_ASPECTJ.toString()) + || s.equals(IProgramElement.Kind.FILE_JAVA.toString()))) { throw new IllegalArgumentException("externalize file, not " + node); } // source files have source locations @@ -98,43 +88,46 @@ public class EmacsStructureModelManager { this.writer = writer; } - private void printDecls(ProgramElementNode node) { + private void printDecls(IProgramElement node) { print("("); for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { // this ignores relations on the compile unit Object nodeObject = it.next(); - if (nodeObject instanceof ProgramElementNode) { - ProgramElementNode child = (ProgramElementNode)nodeObject; +// throw new RuntimeException("unimplemented"); +// if (nodeObject instanceof IProgramElement) { + IProgramElement child = (IProgramElement)nodeObject; printDecl(child, true); - } else if (nodeObject instanceof LinkNode) { - LinkNode child = (LinkNode)nodeObject; - printDecl(child.getProgramElementNode(), false); - } +// } +// else if (nodeObject instanceof LinkNode) { +// LinkNode child = (LinkNode)nodeObject; +// printDecl(child.getProgramElementNode(), false); +// } } print(") "); } - private void printDecls(RelationNode node) { - for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { + private void printDecls(IRelationship node) { + for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) { // this ignores relations on the compile unit Object nodeObject = it.next(); - if (nodeObject instanceof LinkNode) { - LinkNode child = (LinkNode)nodeObject; - if (//!child.getProgramElementNode().getKind().equals("stmnt") && - !child.getProgramElementNode().getKind().equals("<undefined>")) { - printDecl(child.getProgramElementNode(), false); + throw new RuntimeException("unimplemented"); +// if (nodeObject instanceof LinkNode) { +// LinkNode child = (LinkNode)nodeObject; +// if (//!child.getProgramElementNode().getKind().equals("stmnt") && +// !child.getProgramElementNode().getKind().equals("<undefined>")) { // printDecl(child.getProgramElementNode(), false); - } - } +//// printDecl(child.getProgramElementNode(), false); +// } +// } } } /** * @param structureNode can be a ProgramElementNode or a LinkNode */ - private void printDecl(ProgramElementNode node, boolean recurse) { + private void printDecl(IProgramElement node, boolean recurse) { if (node == null || node.getSourceLocation() == null) return; - String kind = node.getKind().toLowerCase(); + String kind = node.getKind().toString().toLowerCase(); print("("); print("(" + node.getSourceLocation().getLine() + " . " + node.getSourceLocation().getColumn() + ") "); print("(" + node.getSourceLocation().getLine() + " . " + node.getSourceLocation().getColumn() + ") "); @@ -161,13 +154,13 @@ public class EmacsStructureModelManager { print("nil"); } else { print("("); - if (node instanceof ProgramElementNode) { - java.util.List relations = ((ProgramElementNode)node).getRelations(); + if (node instanceof IProgramElement) { + java.util.List relations = ((IProgramElement)node).getRelations(); if (relations != null) { for (Iterator it = relations.iterator(); it.hasNext(); ) { - RelationNode relNode = (RelationNode)it.next(); - if (relNode.getRelation().getAssociationName().equals(AdviceAssociation.NAME) || - relNode.getRelation().getAssociationName().equals(IntroductionAssociation.NAME)) { + IRelationship relNode = (IRelationship)it.next(); + if (relNode.getKind() == IRelationship.Kind.ADVICE || + relNode.getKind() == IRelationship.Kind.DECLARE) { printDecls(relNode); // 6 } } @@ -182,8 +175,8 @@ public class EmacsStructureModelManager { while (it3.hasNext()) { // this ignores relations on the compile unit Object nodeObject = it3.next(); - if (nodeObject instanceof ProgramElementNode) { - ProgramElementNode currNode = (ProgramElementNode)nodeObject; + if (nodeObject instanceof IProgramElement) { + IProgramElement currNode = (IProgramElement)nodeObject; if (//!currNode.isStmntKind() && !currNode.getKind().equals("<undefined>")) { printDecl(currNode, true); diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AsmBuilderTest.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AsmBuilderTest.java index 759dbcb82..983f69f96 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AsmBuilderTest.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AsmBuilderTest.java @@ -60,7 +60,7 @@ public class AsmBuilderTest extends TestCase { BlockScope scope = null; try { - new AsmBuilder(new CompilationResult(cu, 0, 0, 0)).visit(local, scope); + new AsmHierarchyBuilder(new CompilationResult(cu, 0, 0, 0)).visit(local, scope); } catch (Exception e) { assertTrue(e instanceof EmptyStackException); } |