]> source.dussan.org Git - aspectj.git/commitdiff
251277: making asmmanager non-singleton
authoraclement <aclement>
Mon, 20 Oct 2008 04:42:20 +0000 (04:42 +0000)
committeraclement <aclement>
Mon, 20 Oct 2008 04:42:20 +0000 (04:42 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/IncrementalStateManager.java

index 2e8f9291a02c611d39eecb6b840e42eb4729ebb6..ac479d6ff22c6cf265a4671dc27267201124e9ea 100644 (file)
@@ -83,16 +83,16 @@ public class EclipseFactory {
        public static boolean DEBUG = false;
        public static int debug_mungerCount = -1;
 
-       private AjBuildManager buildManager;
-       private LookupEnvironment lookupEnvironment;
-       private boolean xSerializableAspects;
-       private World world;
+       private final AjBuildManager buildManager;
+       private final LookupEnvironment lookupEnvironment;
+       private final boolean xSerializableAspects;
+       private final World world;
        public Collection finishedTypeMungers = null;
 
        // We can get clashes if we don't treat raw types differently - we end up looking
        // up a raw and getting the generic type (pr115788)
-       private Map/* UnresolvedType, TypeBinding */typexToBinding = new HashMap();
-       private Map/* UnresolvedType, TypeBinding */rawTypeXToBinding = new HashMap();
+       private final Map/* UnresolvedType, TypeBinding */typexToBinding = new HashMap();
+       private final Map/* UnresolvedType, TypeBinding */rawTypeXToBinding = new HashMap();
 
        // XXX currently unused
        // private Map/*TypeBinding, ResolvedType*/ bindingToResolvedTypeX = new HashMap();
@@ -471,7 +471,7 @@ public class EclipseFactory {
         * Before converting the parts of a methodbinding (params, return type) we store the type variables in this structure, then
         * should any component of the method binding refer to them, we grab them from the map.
         */
-       private Map typeVariablesForThisMember = new HashMap();
+       private final Map typeVariablesForThisMember = new HashMap();
 
        /**
         * This is a map from typevariablebindings (eclipsey things) to the names the user originally specified in their ITD. For
@@ -911,7 +911,7 @@ public class EclipseFactory {
        // map back to the same type binding - this is important later when Eclipse code is processing
        // a methodbinding trying to come up with possible bindings for the type variables.
        // key is currently the name of the type variable...is that ok?
-       private Map typeVariableToTypeBinding = new HashMap();
+       private final Map typeVariableToTypeBinding = new HashMap();
 
        // /**
        // * Converts from an TypeVariableReference to a TypeVariableBinding. A TypeVariableReference
index c5abd85ac84d25cb2be6fcdd735780852f3ac0e6..c4533f5f556c0f4fcf4a59cb7d24cfd897b22e26 100644 (file)
@@ -134,7 +134,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
        private Map /* String -> List<UCF> */binarySourcesForTheNextCompile = new HashMap();
 
        // FIXME asc should this really be in here?
-       private IHierarchy structureModel;
+       // private AsmManager structureModel;
        public AjBuildConfig buildConfig;
        private boolean ignoreOutxml;
        private boolean wasFullBuild = true; // true if last build was a full build rather than an incremental build
@@ -257,7 +257,8 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                        if (isFullBuild) {
                                // System.err.println("XXXX batch: " + buildConfig.getFiles());
                                if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) {
-                                       getWorld().setModel(AsmManager.getDefault().getHierarchy());
+                                       AsmManager.setLastActiveStructureModel(state.getStructureModel());
+                                       getWorld().setModel(state.getStructureModel());
                                        // in incremental build, only get updated model?
                                }
                                binarySourcesForTheNextCompile = state.getBinaryFilesToCompile(true);
@@ -265,13 +266,15 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                                state.clearBinarySourceFiles(); // we don't want these hanging around...
                                if (!proceedOnError() && handler.hasErrors()) {
                                        CompilationAndWeavingContext.leavingPhase(ct);
-                                       if (AsmManager.isReporting())
-                                               AsmManager.getDefault().reportModelInfo("After a batch build");
+                                       if (AsmManager.isReporting()) {
+                                               state.getStructureModel().reportModelInfo("After a batch build");
+                                       }
                                        return false;
                                }
 
-                               if (AsmManager.isReporting())
-                                       AsmManager.getDefault().reportModelInfo("After a batch build");
+                               if (AsmManager.isReporting()) {
+                                       state.getStructureModel().reportModelInfo("After a batch build");
+                               }
 
                        } else {
                                // done already?
@@ -279,13 +282,15 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                                // bcelWorld.setModel(StructureModelManager.INSTANCE.getStructureModel());
                                // }
                                // System.err.println("XXXX start inc ");
+                               AsmManager.setLastActiveStructureModel(state.getStructureModel());
                                binarySourcesForTheNextCompile = state.getBinaryFilesToCompile(true);
                                Set files = state.getFilesToCompile(true);
-                               if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode())
+                               if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) {
                                        if (AsmManager.attemptIncrementalModelRepairs) {
-                                               AsmManager.getDefault().resetDeltaProcessing();
-                                               AsmManager.getDefault().processDelta(files, state.getAddedFiles(), state.getDeletedFiles());
+                                               state.getStructureModel().resetDeltaProcessing();
+                                               state.getStructureModel().processDelta(files, state.getAddedFiles(), state.getDeletedFiles());
                                        }
+                               }
                                boolean hereWeGoAgain = !(files.isEmpty() && binarySourcesForTheNextCompile.isEmpty());
                                for (int i = 0; (i < 5) && hereWeGoAgain; i++) {
                                        if (state.listenerDefined())
@@ -317,27 +322,28 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                                        if (hereWeGoAgain) {
                                                if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode())
                                                        if (AsmManager.attemptIncrementalModelRepairs)
-                                                               AsmManager.getDefault().processDelta(files, state.getAddedFiles(), state.getDeletedFiles());
+                                                               state.getStructureModel().processDelta(files, state.getAddedFiles(), state.getDeletedFiles());
                                        }
                                }
                                if (!files.isEmpty()) {
                                        CompilationAndWeavingContext.leavingPhase(ct);
                                        return batchBuild(buildConfig, baseHandler);
                                } else {
-                                       if (AsmManager.isReporting())
-                                               AsmManager.getDefault().reportModelInfo("After an incremental build");
+                                       if (AsmManager.isReporting()) {
+                                               state.getStructureModel().reportModelInfo("After an incremental build");
+                                       }
                                }
                        }
 
                        // XXX not in Mik's incremental
                        if (buildConfig.isEmacsSymMode()) {
-                               new org.aspectj.ajdt.internal.core.builder.EmacsStructureModelManager().externalizeModel();
+                               new org.aspectj.ajdt.internal.core.builder.EmacsStructureModelManager().externalizeModel(state.getStructureModel());
                        }
 
                        // for bug 113554: support ajsym file generation for command line builds
                        if (buildConfig.isGenerateCrossRefsMode()) {
                                File configFileProxy = new File(buildConfig.getOutputDir(), CROSSREFS_FILE_NAME);
-                               AsmManager.getDefault().writeStructureModel(configFileProxy.getAbsolutePath());
+                               state.getStructureModel().writeStructureModel(configFileProxy.getAbsolutePath());
                        }
 
                        // have to tell state we succeeded or next is not incremental
@@ -359,7 +365,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                        // but always returns true
                        // XXX weaved not in Mik's incremental
                        if (buildConfig.isGenerateModelMode()) {
-                               AsmManager.getDefault().fireModelUpdated();
+                               state.getStructureModel().fireModelUpdated();
                        }
                        CompilationAndWeavingContext.leavingPhase(ct);
 
@@ -719,13 +725,16 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
         * This code is driven before each 'fresh' (batch) build to create a new model.
         */
        private void setupModel(AjBuildConfig config) {
-               AsmManager.setCreatingModel(config.isEmacsSymMode() || config.isGenerateModelMode());
-               if (!AsmManager.isCreatingModel())
+               if (!(config.isEmacsSymMode() || config.isGenerateModelMode())) {
                        return;
+               }
+               // AsmManager.setCreatingModel(config.isEmacsSymMode() || config.isGenerateModelMode());
+               // if (!AsmManager.isCreatingModel())
+               // return;
 
-               AsmManager.getDefault().createNewASM();
+               AsmManager structureModel = AsmManager.createNewStructureModel();
                // AsmManager.getDefault().getRelationshipMap().clear();
-               IHierarchy model = AsmManager.getDefault().getHierarchy();
+               IHierarchy model = structureModel.getHierarchy();
                String rootLabel = "<root>";
 
                IProgramElement.Kind kind = IProgramElement.Kind.FILE_JAVA;
@@ -734,12 +743,12 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                        model.setConfigFile(buildConfig.getConfigFile().getAbsolutePath());
                        kind = IProgramElement.Kind.FILE_LST;
                }
-               model.setRoot(new ProgramElement(rootLabel, kind, new ArrayList()));
+               model.setRoot(new ProgramElement(structureModel, rootLabel, kind, new ArrayList()));
 
                model.setFileMap(new HashMap());
-               setStructureModel(model);
-               state.setStructureModel(model);
-               state.setRelationshipMap(AsmManager.getDefault().getRelationshipMap());
+               // setStructureModel(model);
+               state.setStructureModel(structureModel);
+               // state.setRelationshipMap(AsmManager.getDefault().getRelationshipMap());
        }
 
        //    
@@ -1230,15 +1239,16 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                return buf.toString();
        }
 
-       public void setStructureModel(IHierarchy structureModel) {
-               this.structureModel = structureModel;
-       }
+       //
+       // public void setStructureModel(IHierarchy structureModel) {
+       // this.structureModel = structureModel;
+       // }
 
        /**
         * Returns null if there is no structure model
         */
-       public IHierarchy getStructureModel() {
-               return structureModel;
+       public AsmManager getStructureModel() {
+               return (state == null ? null : state.getStructureModel());
        }
 
        public IProgressListener getProgressListener() {
index 51dc2f7ebb1677997816cdfe8993eed7b72a3dbd..0ce4355007e512414f582776dbae539dcf4d38b0 100644 (file)
@@ -32,8 +32,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.ajdt.internal.compiler.InterimCompilationResult;
-import org.aspectj.asm.IHierarchy;
-import org.aspectj.asm.IRelationshipMap;
+import org.aspectj.asm.AsmManager;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.Message;
 import org.aspectj.bridge.SourceLocation;
@@ -72,9 +71,10 @@ public class AjState implements CompilerConfigurationChangeFlags {
        private final AjBuildManager buildManager;
        private boolean couldBeSubsequentIncrementalBuild = false;
        private INameEnvironment nameEnvironment;
-
-       private IHierarchy structureModel;
-       private IRelationshipMap relmap;
+       //
+       // private IHierarchy structureModel;
+       // private IRelationshipMap relmap;
+       private AsmManager structureModel;
 
        /**
         * When looking at changes on the classpath, this set accumulates files in our state instance that affected by those changes.
@@ -497,7 +497,7 @@ public class AjState implements CompilerConfigurationChangeFlags {
                return CLASS_FILE_NO_CHANGES;
        }
 
-       private boolean isAspect(File file) {   
+       private boolean isAspect(File file) {
                return aspectClassFiles.contains(file.getAbsolutePath());
        }
 
@@ -1672,11 +1672,11 @@ public class AjState implements CompilerConfigurationChangeFlags {
 
        }
 
-       public void setStructureModel(IHierarchy model) {
-               structureModel = model;
+       public void setStructureModel(AsmManager structureModel) {
+               this.structureModel = structureModel;
        }
 
-       public IHierarchy getStructureModel() {
+       public AsmManager getStructureModel() {
                return structureModel;
        }
 
@@ -1696,13 +1696,14 @@ public class AjState implements CompilerConfigurationChangeFlags {
                return world;
        }
 
-       public void setRelationshipMap(IRelationshipMap irm) {
-               relmap = irm;
-       }
-
-       public IRelationshipMap getRelationshipMap() {
-               return relmap;
-       }
+       //
+       // public void setRelationshipMap(IRelationshipMap irm) {
+       // relmap = irm;
+       // }
+       //
+       // public IRelationshipMap getRelationshipMap() {
+       // return relmap;
+       // }
 
        public int getNumberOfStructuralChangesSinceLastFullBuild() {
                return structuralChangesSinceLastFullBuild.size();
@@ -1820,7 +1821,7 @@ public class AjState implements CompilerConfigurationChangeFlags {
 
        public void wipeAllKnowledge() {
                buildManager.state = null;
-               buildManager.setStructureModel(null);
+               // buildManager.setStructureModel(null);
        }
 
        public Map getAspectNamesToFileNameMap() {
index 3b1248002dadd91d3d1110e9d4c4a1e03094e002..b0b8c2f956dbe5600f3c5d4fbabca449980b610f 100644 (file)
@@ -32,9 +32,7 @@ import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
 import org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment;
 import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
 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.CharOperation;
 import org.aspectj.asm.internal.ProgramElement;
 import org.aspectj.bridge.ISourceLocation;
@@ -87,7 +85,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
        protected AsmElementFormatter formatter = new AsmElementFormatter();
        // pr148027 - stop generating uses pointcut/pointcut used by relationship
        // until we do it in the same way as other relationships.
-       public static boolean shouldAddUsesPointcut = false;
+       // public static boolean shouldAddUsesPointcut = false;
        /**
         * Reset for every compilation unit.
         */
@@ -111,7 +109,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
         * @param buildConfig
         * @param structureModel hiearchy to add this unit's declarations to
         */
-       public void buildStructureForCompilationUnit(CompilationUnitDeclaration cuDeclaration, IHierarchy structureModel,
+       public void buildStructureForCompilationUnit(CompilationUnitDeclaration cuDeclaration, AsmManager structureModel,
                        AjBuildConfig buildConfig) {
                currCompilationResult = cuDeclaration.compilationResult();
                filename = new String(currCompilationResult.fileName);
@@ -127,64 +125,73 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                // throw new RuntimeException("not implemented");
        }
 
-       private void internalBuild(CompilationUnitDeclaration unit, IHierarchy structureModel) {
+       private void internalBuild(CompilationUnitDeclaration unit, AsmManager structureModel) {
                LangUtil.throwIaxIfNull(structureModel, "structureModel");
-               // if (!currCompilationResult.equals(unit.compilationResult())) {
-               // throw new IllegalArgumentException("invalid unit: " + unit);
-               // }
-               // ---- summary
-               // add unit to package (or root if no package),
-               // first removing any duplicate (XXX? removes children if 3 classes in
-               // same file?)
-               // push the node on the stack
-               // and traverse
-
-               // -- create node to add
-               final File file = new File(new String(unit.getFileName()));
-               final IProgramElement cuNode;
-               {
-                       // AMC - use the source start and end from the compilation unit decl
-                       int startLine = getStartLine(unit);
-                       int endLine = getEndLine(unit);
-                       SourceLocation sourceLocation = new SourceLocation(file, startLine, endLine);
-                       sourceLocation.setOffset(unit.sourceStart);
-                       cuNode = new ProgramElement(new String(file.getName()), IProgramElement.Kind.FILE_JAVA, sourceLocation, 0, null, null);
-               }
-
-               cuNode.addChild(new ProgramElement("import declarations", IProgramElement.Kind.IMPORT_REFERENCE, null, 0, null, null));
-
-               final IProgramElement addToNode = genAddToNode(file, unit, structureModel);
+               try {
+                       activeStructureModel = structureModel;
+                       // if (!currCompilationResult.equals(unit.compilationResult())) {
+                       // throw new IllegalArgumentException("invalid unit: " + unit);
+                       // }
+                       // ---- summary
+                       // add unit to package (or root if no package),
+                       // first removing any duplicate (XXX? removes children if 3 classes in
+                       // same file?)
+                       // push the node on the stack
+                       // and traverse
+
+                       // -- create node to add
+                       final File file = new File(new String(unit.getFileName()));
+                       final IProgramElement cuNode;
+                       {
+                               // AMC - use the source start and end from the compilation unit decl
+                               int startLine = getStartLine(unit);
+                               int endLine = getEndLine(unit);
+                               SourceLocation sourceLocation = new SourceLocation(file, startLine, endLine);
+                               sourceLocation.setOffset(unit.sourceStart);
+                               cuNode = new ProgramElement(structureModel, new String(file.getName()), IProgramElement.Kind.FILE_JAVA,
+                                               sourceLocation, 0, null, null);
+                       }
 
-               // -- remove duplicates before adding (XXX use them instead?)
-               if (addToNode != null && addToNode.getChildren() != null) {
-                       for (ListIterator itt = addToNode.getChildren().listIterator(); itt.hasNext();) {
-                               IProgramElement child = (IProgramElement) itt.next();
-                               ISourceLocation childLoc = child.getSourceLocation();
-                               if (null == childLoc) {
-                                       // XXX ok, packages have null source locations
-                                       // signal others?
-                               } else if (childLoc.getSourceFile().equals(file)) {
-                                       itt.remove();
+                       cuNode.addChild(new ProgramElement(structureModel, "import declarations", IProgramElement.Kind.IMPORT_REFERENCE, null,
+                                       0, null, null));
+
+                       final IProgramElement addToNode = genAddToNode(file, unit, structureModel);
+
+                       // -- remove duplicates before adding (XXX use them instead?)
+                       if (addToNode != null && addToNode.getChildren() != null) {
+                               for (ListIterator itt = addToNode.getChildren().listIterator(); itt.hasNext();) {
+                                       IProgramElement child = (IProgramElement) itt.next();
+                                       ISourceLocation childLoc = child.getSourceLocation();
+                                       if (null == childLoc) {
+                                               // XXX ok, packages have null source locations
+                                               // signal others?
+                                       } else if (childLoc.getSourceFile().equals(file)) {
+                                               itt.remove();
+                                       }
                                }
                        }
-               }
-               // -- add and traverse
-               addToNode.addChild(cuNode);
-               stack.push(cuNode);
-               unit.traverse(this, unit.scope);
+                       // -- add and traverse
+                       addToNode.addChild(cuNode);
+                       stack.push(cuNode);
+                       unit.traverse(this, unit.scope);
 
-               // -- update file map (XXX do this before traversal?)
-               try {
-                       structureModel.addToFileMap(file.getCanonicalPath(), cuNode);
-               } catch (IOException e) {
-                       System.err.println("IOException " + e.getMessage() + " creating path for " + file);
-                       // XXX signal IOException when canonicalizing file path
+                       // -- update file map (XXX do this before traversal?)
+                       try {
+                               structureModel.getHierarchy().addToFileMap(file.getCanonicalPath(), cuNode);
+                       } catch (IOException e) {
+                               System.err.println("IOException " + e.getMessage() + " creating path for " + file);
+                               // XXX signal IOException when canonicalizing file path
+                       }
+               } finally {
+                       activeStructureModel = null;
                }
 
        }
 
-       private IProgramElement findOrCreateChildSourceFolder(String sourceFolder, IHierarchy structureModel) {
-               IProgramElement root = structureModel.getRoot();
+       private AsmManager activeStructureModel = null;
+
+       private IProgramElement findOrCreateChildSourceFolder(String sourceFolder, AsmManager structureModel) {
+               IProgramElement root = structureModel.getHierarchy().getRoot();
                // Check if already there
                IProgramElement sourceFolderNode = null;
                List kids = root.getChildren();
@@ -196,7 +203,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        }
                }
                if (sourceFolderNode == null) {
-                       sourceFolderNode = new ProgramElement(sourceFolder, IProgramElement.Kind.SOURCE_FOLDER, new ArrayList());
+                       sourceFolderNode = new ProgramElement(structureModel, sourceFolder, IProgramElement.Kind.SOURCE_FOLDER, new ArrayList());
                        root.addChild(sourceFolderNode);
                }
                return sourceFolderNode;
@@ -205,7 +212,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
        /**
         * Get/create the node (package or root) to add to.
         */
-       private IProgramElement genAddToNode(File sourceFile, CompilationUnitDeclaration unit, IHierarchy structureModel) {
+       private IProgramElement genAddToNode(File sourceFile, CompilationUnitDeclaration unit, AsmManager structureModel) {
                final IProgramElement addToNode;
                {
 
@@ -223,7 +230,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        // }
                        // } else {
 
-                       IProgramElement rootForSource = structureModel.getRoot();
+                       IProgramElement rootForSource = structureModel.getHierarchy().getRoot();
                        if (sourceFolder != null) {
                                rootForSource = findOrCreateChildSourceFolder(sourceFolder, structureModel);
                        }
@@ -244,7 +251,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        }
 
                        IProgramElement pkgNode = null;
-                       if (structureModel != null && structureModel.getRoot() != null && rootForSource.getChildren() != null) {
+                       if (structureModel != null && structureModel.getHierarchy().getRoot() != null && rootForSource.getChildren() != null) {
                                for (Iterator it = rootForSource.getChildren().iterator(); it.hasNext();) {
                                        IProgramElement currNode = (IProgramElement) it.next();
                                        if (pkgName.equals(currNode.getName())) {
@@ -255,7 +262,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        }
                        if (pkgNode == null) {
                                // note packages themselves have no source location
-                               pkgNode = new ProgramElement(pkgName, IProgramElement.Kind.PACKAGE, new ArrayList());
+                               pkgNode = new ProgramElement(activeStructureModel, pkgName, IProgramElement.Kind.PACKAGE, new ArrayList());
                                rootForSource.addChild(pkgNode);
                        }
                        addToNode = pkgNode;
@@ -300,11 +307,11 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                                                // Create the ImportReference needed to add a
                                                // ProgramElement
                                                ImportReference importRef = new ImportReference(path, new long[] { 0 }, false, 0);
-                                               ProgramElement ceNode = new ProgramElement(importRef.toString(), IProgramElement.Kind.IMPORT_REFERENCE,
-                                                               makeLocation(importRef), 0, null, null);
+                                               IProgramElement ceNode = new ProgramElement(activeStructureModel, importRef.toString(),
+                                                               IProgramElement.Kind.IMPORT_REFERENCE, makeLocation(importRef), 0, null, null);
                                                ceNode.setSourceSignature(genSourceSignature(importRef));
                                                // Add Element to Imports of Current Class
-                                               ProgramElement imports = (ProgramElement) ((ProgramElement) stack.peek()).getChildren().get(0);
+                                               ProgramElement imports = (ProgramElement) ((IProgramElement) stack.peek()).getChildren().get(0);
                                                imports.addChild(0, ceNode);
                                        }
                                }
@@ -316,7 +323,8 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        typeModifiers = ((AspectDeclaration) typeDeclaration).getDeclaredModifiers();
                }
 
-               IProgramElement peNode = new ProgramElement(name, kind, makeLocation(typeDeclaration), typeModifiers, null, null);
+               IProgramElement peNode = new ProgramElement(activeStructureModel, name, kind, makeLocation(typeDeclaration), typeModifiers,
+                               null, null);
                peNode.setSourceSignature(genSourceSignature(typeDeclaration));
                peNode.setFormalComment(generateJavadocComment(typeDeclaration));
 
@@ -360,7 +368,8 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        typeModifiers = ((AspectDeclaration) memberTypeDeclaration).getDeclaredModifiers();
                }
 
-               IProgramElement peNode = new ProgramElement(name, kind, makeLocation(memberTypeDeclaration), typeModifiers, null, null);
+               IProgramElement peNode = new ProgramElement(activeStructureModel, name, kind, makeLocation(memberTypeDeclaration),
+                               typeModifiers, null, null);
                peNode.setSourceSignature(genSourceSignature(memberTypeDeclaration));
                peNode.setFormalComment(generateJavadocComment(memberTypeDeclaration));
 
@@ -409,7 +418,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        }
                }
 
-               IProgramElement peNode = new ProgramElement(fullName, kind, makeLocation(memberTypeDeclaration),
+               IProgramElement peNode = new ProgramElement(activeStructureModel, fullName, kind, makeLocation(memberTypeDeclaration),
                                memberTypeDeclaration.modifiers, null, null);
                peNode.setSourceSignature(genSourceSignature(memberTypeDeclaration));
                peNode.setFormalComment(generateJavadocComment(memberTypeDeclaration));
@@ -461,19 +470,19 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                if (methodDeclaration instanceof InterTypeDeclaration) {
                        InterTypeDeclaration itd = (InterTypeDeclaration) methodDeclaration;
                        ResolvedMember sig = itd.getSignature();
-                       peNode = new ProgramElement(null, IProgramElement.Kind.ERROR, makeLocation(methodDeclaration), (sig != null ? sig
-                                       .getModifiers() : 0), null, null);
+                       peNode = new ProgramElement(activeStructureModel, null, IProgramElement.Kind.ERROR, makeLocation(methodDeclaration),
+                                       (sig != null ? sig.getModifiers() : 0), null, null);
 
                } else {
-                       peNode = new ProgramElement(null, IProgramElement.Kind.ERROR, makeLocation(methodDeclaration),
+                       peNode = new ProgramElement(activeStructureModel, null, IProgramElement.Kind.ERROR, makeLocation(methodDeclaration),
                                        methodDeclaration.modifiers, null, null);
                }
                formatter.genLabelAndKind(methodDeclaration, peNode); // will set the
                // name
                genBytecodeInfo(methodDeclaration, peNode);
                List namedPointcuts = genNamedPointcuts(methodDeclaration);
-               if (shouldAddUsesPointcut)
-                       addUsesPointcutRelationsForNode(peNode, namedPointcuts, methodDeclaration);
+               // if (shouldAddUsesPointcut)
+               // addUsesPointcutRelationsForNode(peNode, namedPointcuts, methodDeclaration);
 
                if (methodDeclaration.returnType != null) {
                        // if we don't make the distinction between ITD fields and other
@@ -508,24 +517,24 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                return true;
        }
 
-       private void addUsesPointcutRelationsForNode(IProgramElement peNode, List namedPointcuts, MethodDeclaration declaration) {
-               for (Iterator it = namedPointcuts.iterator(); it.hasNext();) {
-                       ReferencePointcut rp = (ReferencePointcut) it.next();
-                       ResolvedMember member = getPointcutDeclaration(rp, declaration);
-                       if (member != null) {
-                               IRelationship foreward = AsmManager.getDefault().getRelationshipMap().get(peNode.getHandleIdentifier(),
-                                               IRelationship.Kind.USES_POINTCUT, "uses pointcut", false, true);
-                               IProgramElement forwardIPE = AsmManager.getDefault().getHierarchy().findElementForSourceLine(
-                                               member.getSourceLocation());
-                               foreward.addTarget(AsmManager.getDefault().getHandleProvider().createHandleIdentifier(forwardIPE));
-
-                               IRelationship back = AsmManager.getDefault().getRelationshipMap().get(
-                                               AsmManager.getDefault().getHandleProvider().createHandleIdentifier(forwardIPE),
-                                               IRelationship.Kind.USES_POINTCUT, "pointcut used by", false, true);
-                               back.addTarget(peNode.getHandleIdentifier());
-                       }
-               }
-       }
+       // private void addUsesPointcutRelationsForNode(IProgramElement peNode, List namedPointcuts, MethodDeclaration declaration) {
+       // for (Iterator it = namedPointcuts.iterator(); it.hasNext();) {
+       // ReferencePointcut rp = (ReferencePointcut) it.next();
+       // ResolvedMember member = getPointcutDeclaration(rp, declaration);
+       // if (member != null) {
+       // IRelationship foreward = AsmManager.getDefault().getRelationshipMap().get(peNode.getHandleIdentifier(),
+       // IRelationship.Kind.USES_POINTCUT, "uses pointcut", false, true);
+       // IProgramElement forwardIPE = AsmManager.getDefault().getHierarchy().findElementForSourceLine(
+       // member.getSourceLocation());
+       // foreward.addTarget(AsmManager.getDefault().getHandleProvider().createHandleIdentifier(forwardIPE));
+       //
+       // IRelationship back = AsmManager.getDefault().getRelationshipMap().get(
+       // AsmManager.getDefault().getHandleProvider().createHandleIdentifier(forwardIPE),
+       // IRelationship.Kind.USES_POINTCUT, "pointcut used by", false, true);
+       // back.addTarget(peNode.getHandleIdentifier());
+       // }
+       // }
+       // }
 
        private ResolvedMember getPointcutDeclaration(ReferencePointcut rp, MethodDeclaration declaration) {
                EclipseFactory factory = ((AjLookupEnvironment) declaration.scope.environment()).factory;
@@ -672,10 +681,10 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                if (dotIndex != -1) {
                        currPackageImport = importRef.toString().substring(0, dotIndex);
                }
-               if (!((ProgramElement) stack.peek()).getPackageName().equals(currPackageImport)) {
+               if (!((IProgramElement) stack.peek()).getPackageName().equals(currPackageImport)) {
 
-                       ProgramElement peNode = new ProgramElement(new String(importRef.toString()), IProgramElement.Kind.IMPORT_REFERENCE,
-                                       makeLocation(importRef), 0,// could set static here, but for
+                       ProgramElement peNode = new ProgramElement(activeStructureModel, new String(importRef.toString()),
+                                       IProgramElement.Kind.IMPORT_REFERENCE, makeLocation(importRef), 0,// could set static here, but for
                                        // some reason the info is
                                        // private
                                        null, null);
@@ -686,7 +695,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        // create Source signature for import
                        peNode.setSourceSignature(genSourceSignature(importRef));
 
-                       ProgramElement imports = (ProgramElement) ((ProgramElement) stack.peek()).getChildren().get(0);
+                       ProgramElement imports = (ProgramElement) ((IProgramElement) stack.peek()).getChildren().get(0);
                        imports.addChild(0, peNode);
                        stack.push(peNode);
                }
@@ -699,7 +708,7 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                if (dotIndex != -1) {
                        currPackageImport = importRef.toString().substring(0, dotIndex);
                }
-               if (!((ProgramElement) stack.peek()).getPackageName().equals(currPackageImport)) {
+               if (!((IProgramElement) stack.peek()).getPackageName().equals(currPackageImport)) {
                        stack.pop();
                }
        }
@@ -717,11 +726,11 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                IProgramElement peNode = null;
                if (fieldDeclaration.type == null) { // The field represents an enum
                        // value
-                       peNode = new ProgramElement(new String(fieldDeclaration.name), IProgramElement.Kind.ENUM_VALUE,
+                       peNode = new ProgramElement(activeStructureModel, new String(fieldDeclaration.name), IProgramElement.Kind.ENUM_VALUE,
                                        makeLocation(fieldDeclaration), fieldDeclaration.modifiers, null, null);
                        peNode.setCorrespondingType(fieldDeclaration.binding.type.debugName());
                } else {
-                       peNode = new ProgramElement(new String(fieldDeclaration.name), IProgramElement.Kind.FIELD,
+                       peNode = new ProgramElement(activeStructureModel, new String(fieldDeclaration.name), IProgramElement.Kind.FIELD,
                                        makeLocation(fieldDeclaration), fieldDeclaration.modifiers, null, null);
                        peNode.setCorrespondingType(fieldDeclaration.type.toString());
                }
@@ -859,8 +868,9 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        }
                }
                argumentsSignature.append(")");
-               IProgramElement peNode = new ProgramElement(new String(constructorDeclaration.selector), IProgramElement.Kind.CONSTRUCTOR,
-                               makeLocation(constructorDeclaration), constructorDeclaration.modifiers, null, null);
+               IProgramElement peNode = new ProgramElement(activeStructureModel, new String(constructorDeclaration.selector),
+                               IProgramElement.Kind.CONSTRUCTOR, makeLocation(constructorDeclaration), constructorDeclaration.modifiers, null,
+                               null);
                formatter.setParameters(constructorDeclaration, peNode);
                peNode.setModifiers(constructorDeclaration.modifiers);
                peNode.setSourceSignature(genSourceSignature(constructorDeclaration));
@@ -956,8 +966,8 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                        return false;
                inInitializer = initializer;
 
-               IProgramElement peNode = new ProgramElement("...", IProgramElement.Kind.INITIALIZER, makeLocation(initializer),
-                               initializer.modifiers, null, null);
+               IProgramElement peNode = new ProgramElement(activeStructureModel, "...", IProgramElement.Kind.INITIALIZER,
+                               makeLocation(initializer), initializer.modifiers, null, null);
                // "",
                // new ArrayList());
                ((IProgramElement) stack.peek()).addChild(peNode);
index 73bf2088206fd5d1a8c5c08deee64f5903cf5cdb..668ac2e8ae31ff903133532e065a00b5920aa346 100644 (file)
  *     PARC     initial implementation 
  * ******************************************************************/
 
-
 package org.aspectj.ajdt.internal.core.builder;
 
-import java.io.*;
-import java.util.*;
+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.*;
-//import org.aspectj.ajde.compiler.AjdeCompiler;
+import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IProgramElement;
 
-/** 
+/**
  * @author Mik Kersten
  */
 public class EmacsStructureModelManager {
 
-    private static final String EXTERN_FILE_SUFFIX = ".ajesym";
-
-    public EmacsStructureModelManager() {
-        super();
-    }
-
-    public void externalizeModel() {
-       if (!AsmManager.getDefault().getHierarchy().isValid()) return;
-        
-        try {
-            //Set fileSet = StructureModelManager.INSTANCE.getStructureModel().getFileMap().entrySet(); 
-                       Set fileSet = AsmManager.getDefault().getHierarchy().getFileMapEntrySet(); 
-            for (Iterator it = fileSet.iterator(); it.hasNext(); ) {
-                IProgramElement peNode = (IProgramElement)((Map.Entry)it.next()).getValue();
-                dumpStructureToFile(peNode);
-            }
-        } catch (IOException ioe) {
-            ioe.printStackTrace();
-        }
-    }
-
-//    private void dumpStructureToFile(ProgramElementNode node) throws IOException {
-//        String sourceName = node.getSourceLocation().getSourceFilePath();
-//        String fileName = sourceName.substring(0, sourceName.lastIndexOf(".")) + EXTERN_FILE_SUFFIX;
-//        BufferedWriter writer = new BufferedWriter(new FileWriter(new File(fileName)));
-//        new SExpressionPrinter(writer).printDecls(node);
-//        writer.flush();
-//    }
-
-    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
-        String sourceName = node.getSourceLocation().getSourceFile().getAbsolutePath();
-        String fileName = sourceName.substring(0, sourceName.lastIndexOf(".")) + EXTERN_FILE_SUFFIX;
-        BufferedWriter writer = null;
-        try {
-            writer = new BufferedWriter(new FileWriter(new File(fileName)));
-            new SExpressionPrinter(writer).printDecls(node);
-            writer.flush();
-        } finally {
-            if (writer != null) {
-                try {  
-                    writer.close();
-                } catch (IOException e) {} // ignore
-            }
-        }
-    }
-
-    /**
-     * This class was not written in an OO style.
-     */
-    private static class SExpressionPrinter {
-
-        private BufferedWriter writer = null;
-
-        public SExpressionPrinter(BufferedWriter writer) {
-            this.writer = writer;
-        }
-
-        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();
-//                             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);
-//                }
-            }
-            print(") ");
-        }
-
-//        private void printDecls(IRelationship node) {
-////            for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) {
-////                // this ignores relations on the compile unit
-////                Object nodeObject = it.next();
-////                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(IProgramElement node, boolean recurse) {
-               if (node == null || node.getSourceLocation() == null) return;
-            String kind = node.getKind().toString().toLowerCase();
-            print("(");
-            print("(" + node.getSourceLocation().getLine() + " . " + node.getSourceLocation().getColumn() + ") ");
-            print("(" + node.getSourceLocation().getLine() + " . " + node.getSourceLocation().getColumn() + ") ");
-            print(kind + " ");                                     //2
-
-            // HACK:
-            String displayName = node.toString().replace('\"', ' ');
-
-            print("\"" + displayName + "\" ");
-            if (node.getSourceLocation().getSourceFile().getAbsolutePath() != null) {
-                print("\"" + fixFilename(node.getSourceLocation().getSourceFile().getAbsolutePath()) + "\"");  //4
-            } else {
-                print("nil");
-            }
-            if (node.getName() != null) {
-                print("\"" + node.getDeclaringType() + "\" ");         //5
-            } else {
-                print("nil");
-            }
-
-            if (!recurse) {
-                print("nil");
-                print("nil");
-                print("nil");
-            } else {
-                print("(");
-//                if (node instanceof IProgramElement) {
-//                    java.util.List relations = ((IProgramElement)node).getRelations();
-//                    if (relations != null) {
-//                        for (Iterator it = relations.iterator(); it.hasNext(); ) {
-//                                                     IRelationship relNode = (IRelationship)it.next();
-//                            if (relNode.getKind() == IRelationship.Kind.ADVICE ||
-//                                                             relNode.getKind() == IRelationship.Kind.DECLARE) {
-//                                printDecls(relNode);                                   // 6
-//                            }
-//                        }
-//                    }
-//                }
-                print(") ");
-                print("(");
-                print(") ");
-                print("(");
-                Iterator it3 = node.getChildren().iterator();
-                if (it3.hasNext()) {
-                    while (it3.hasNext()) {
-                        // this ignores relations on the compile unit
-                        Object nodeObject = it3.next();
-                        if (nodeObject instanceof IProgramElement) {
-                            IProgramElement currNode = (IProgramElement)nodeObject;
-                            if (//!currNode.isStmntKind() &&
-                                !currNode.getKind().equals("<undefined>")) {
-                                printDecl(currNode, true);
-                            }
-                        }
-                    }
-                }
-                print(") ");
-            }
-
-            print(node.getKind().equals("class") ? "t " : "nil ");        // 9
-//            print(node.getKind().equals("introduction") ? "t " : "nil "); // 10
-            print(node.getKind().equals("introduction") ? "nil " : "nil "); // 10
-            print("nil ");            // 11
-            print("nil ");       // 12
-            print(")");
-        }
-
-        String fixFilename(String filename) {
-            return subst("\\\\", "\\", filename);
-        }
-
-        private void print(String string) {
-            try {
-                writer.write(string + "\n");
-            } catch (IOException ioe) {
-                ioe.printStackTrace();
-            }
-        }
-
-        private String subst(String n, String o, String in) {
-            int pos = in.indexOf(o);
-            if (pos == -1)
-                return in;
-            return in.substring(0, pos) +
-                   n +
-                   subst(n, o, (in.substring(pos + o.length())));
-        }
-
-//        private void lose(Error e) {
-//            try {
-//                print("(ERROR \"" + e.toString() + "\")");
-//            }
-//            catch(Error ex) { }
-//        }
-    }
+       private static final String EXTERN_FILE_SUFFIX = ".ajesym";
+
+       public EmacsStructureModelManager() {
+               super();
+       }
+
+       public void externalizeModel(AsmManager model) {
+               if (!model.getHierarchy().isValid())
+                       return;
+
+               try {
+                       // Set fileSet = StructureModelManager.INSTANCE.getStructureModel().getFileMap().entrySet();
+                       Set fileSet = model.getHierarchy().getFileMapEntrySet();
+                       for (Iterator it = fileSet.iterator(); it.hasNext();) {
+                               IProgramElement peNode = (IProgramElement) ((Map.Entry) it.next()).getValue();
+                               dumpStructureToFile(peNode);
+                       }
+               } catch (IOException ioe) {
+                       ioe.printStackTrace();
+               }
+       }
+
+       // private void dumpStructureToFile(ProgramElementNode node) throws IOException {
+       // String sourceName = node.getSourceLocation().getSourceFilePath();
+       // String fileName = sourceName.substring(0, sourceName.lastIndexOf(".")) + EXTERN_FILE_SUFFIX;
+       // BufferedWriter writer = new BufferedWriter(new FileWriter(new File(fileName)));
+       // new SExpressionPrinter(writer).printDecls(node);
+       // writer.flush();
+       // }
+
+       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
+               String sourceName = node.getSourceLocation().getSourceFile().getAbsolutePath();
+               String fileName = sourceName.substring(0, sourceName.lastIndexOf(".")) + EXTERN_FILE_SUFFIX;
+               BufferedWriter writer = null;
+               try {
+                       writer = new BufferedWriter(new FileWriter(new File(fileName)));
+                       new SExpressionPrinter(writer).printDecls(node);
+                       writer.flush();
+               } finally {
+                       if (writer != null) {
+                               try {
+                                       writer.close();
+                               } catch (IOException e) {
+                               } // ignore
+                       }
+               }
+       }
+
+       /**
+        * This class was not written in an OO style.
+        */
+       private static class SExpressionPrinter {
+
+               private BufferedWriter writer = null;
+
+               public SExpressionPrinter(BufferedWriter writer) {
+                       this.writer = writer;
+               }
+
+               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();
+                               // 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);
+                               // }
+                       }
+                       print(") ");
+               }
+
+               // private void printDecls(IRelationship node) {
+               // // for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) {
+               // // // this ignores relations on the compile unit
+               // // Object nodeObject = it.next();
+               // // 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(IProgramElement node, boolean recurse) {
+                       if (node == null || node.getSourceLocation() == null)
+                               return;
+                       String kind = node.getKind().toString().toLowerCase();
+                       print("(");
+                       print("(" + node.getSourceLocation().getLine() + " . " + node.getSourceLocation().getColumn() + ") ");
+                       print("(" + node.getSourceLocation().getLine() + " . " + node.getSourceLocation().getColumn() + ") ");
+                       print(kind + " "); // 2
+
+                       // HACK:
+                       String displayName = node.toString().replace('\"', ' ');
+
+                       print("\"" + displayName + "\" ");
+                       if (node.getSourceLocation().getSourceFile().getAbsolutePath() != null) {
+                               print("\"" + fixFilename(node.getSourceLocation().getSourceFile().getAbsolutePath()) + "\""); // 4
+                       } else {
+                               print("nil");
+                       }
+                       if (node.getName() != null) {
+                               print("\"" + node.getDeclaringType() + "\" "); // 5
+                       } else {
+                               print("nil");
+                       }
+
+                       if (!recurse) {
+                               print("nil");
+                               print("nil");
+                               print("nil");
+                       } else {
+                               print("(");
+                               // if (node instanceof IProgramElement) {
+                               // java.util.List relations = ((IProgramElement)node).getRelations();
+                               // if (relations != null) {
+                               // for (Iterator it = relations.iterator(); it.hasNext(); ) {
+                               // IRelationship relNode = (IRelationship)it.next();
+                               // if (relNode.getKind() == IRelationship.Kind.ADVICE ||
+                               // relNode.getKind() == IRelationship.Kind.DECLARE) {
+                               // printDecls(relNode); // 6
+                               // }
+                               // }
+                               // }
+                               // }
+                               print(") ");
+                               print("(");
+                               print(") ");
+                               print("(");
+                               Iterator it3 = node.getChildren().iterator();
+                               if (it3.hasNext()) {
+                                       while (it3.hasNext()) {
+                                               // this ignores relations on the compile unit
+                                               Object nodeObject = it3.next();
+                                               if (nodeObject instanceof IProgramElement) {
+                                                       IProgramElement currNode = (IProgramElement) nodeObject;
+                                                       if (// !currNode.isStmntKind() &&
+                                                       !currNode.getKind().equals("<undefined>")) {
+                                                               printDecl(currNode, true);
+                                                       }
+                                               }
+                                       }
+                               }
+                               print(") ");
+                       }
+
+                       print(node.getKind().equals("class") ? "t " : "nil "); // 9
+                       // print(node.getKind().equals("introduction") ? "t " : "nil "); // 10
+                       print(node.getKind().equals("introduction") ? "nil " : "nil "); // 10
+                       print("nil "); // 11
+                       print("nil "); // 12
+                       print(")");
+               }
+
+               String fixFilename(String filename) {
+                       return subst("\\\\", "\\", filename);
+               }
+
+               private void print(String string) {
+                       try {
+                               writer.write(string + "\n");
+                       } catch (IOException ioe) {
+                               ioe.printStackTrace();
+                       }
+               }
+
+               private String subst(String n, String o, String in) {
+                       int pos = in.indexOf(o);
+                       if (pos == -1)
+                               return in;
+                       return in.substring(0, pos) + n + subst(n, o, (in.substring(pos + o.length())));
+               }
+
+               // private void lose(Error e) {
+               // try {
+               // print("(ERROR \"" + e.toString() + "\")");
+               // }
+               // catch(Error ex) { }
+               // }
+       }
 }
-
index 19f481eabbe0930c5d801b1758ad171889a59976..b7420690d40fe9feef8b10c6336f98e241aa61cc 100644 (file)
@@ -19,93 +19,97 @@ import java.util.List;
 import java.util.Set;
 
 import org.aspectj.ajdt.internal.compiler.CompilationResultDestinationManager;
-import org.aspectj.asm.AsmManager;
-
 
 /**
- * Central point for all things incremental...
- * - keeps track of the state recorded for each different config file
- * - allows limited interaction with these states
- *
- * - records dependency/change info for particular classpaths
- *   > this will become what JDT keeps in its 'State' object when its finished
+ * Central point for all things incremental... - keeps track of the state recorded for each different config file - allows limited
+ * interaction with these states
+ * 
+ * - records dependency/change info for particular classpaths > this will become what JDT keeps in its 'State' object when its
+ * finished
  */
 public class IncrementalStateManager {
 
        // FIXME asc needs an API through Ajde for trashing its contents
        // FIXME asc needs some memory mgmt (softrefs?) to recover memory
-       // SECRETAPI will consume more memory, so turn on at your own risk ;)  Set to 'true' when memory usage is understood
-       public  static boolean recordIncrementalStates = false;
-       public  static boolean debugIncrementalStates = false;
+       // SECRETAPI will consume more memory, so turn on at your own risk ;) Set to 'true' when memory usage is understood
+       public static boolean recordIncrementalStates = false;
+       public static boolean debugIncrementalStates = false;
        private static Hashtable incrementalStates = new Hashtable();
-       
+
        public static void recordSuccessfulBuild(String buildConfig, AjState state) {
-               if (!recordIncrementalStates) return;
-               incrementalStates.put(buildConfig,state);
+               if (!recordIncrementalStates)
+                       return;
+               incrementalStates.put(buildConfig, state);
        }
-       
+
        public static boolean removeIncrementalStateInformationFor(String buildConfig) {
-               return incrementalStates.remove(buildConfig)!=null;
+               return incrementalStates.remove(buildConfig) != null;
        }
-       
+
        public static void clearIncrementalStates() {
                for (Iterator iter = incrementalStates.values().iterator(); iter.hasNext();) {
                        AjState element = (AjState) iter.next();
                        element.wipeAllKnowledge();
                }
                incrementalStates.clear();
-               AsmManager.getDefault().createNewASM(); // forget what you know...
+               // AsmManager.getDefault().createNewStructureModel(); // forget what you know...
        }
-       
+
        public static Set getConfigFilesKnown() {
                return incrementalStates.keySet();
        }
 
        public static AjState retrieveStateFor(String configFile) {
-               return (AjState)incrementalStates.get(configFile);
+               return (AjState) incrementalStates.get(configFile);
        }
-       
+
        // now, managing changes to entries on a classpath
-       
+
        public static AjState findStateManagingOutputLocation(File location) {
                Collection allStates = incrementalStates.values();
-               if (debugIncrementalStates) System.err.println("> findStateManagingOutputLocation("+location+") has "+allStates.size()+" states to look through");
+               if (debugIncrementalStates)
+                       System.err.println("> findStateManagingOutputLocation(" + location + ") has " + allStates.size()
+                                       + " states to look through");
                for (Iterator iter = allStates.iterator(); iter.hasNext();) {
                        AjState element = (AjState) iter.next();
                        AjBuildConfig ajbc = element.getBuildConfig();
-                       if (ajbc==null) {
+                       if (ajbc == null) {
                                // FIXME asc why can it ever be null?
-                               if (debugIncrementalStates) System.err.println("  No build configuration for state "+element);
+                               if (debugIncrementalStates)
+                                       System.err.println("  No build configuration for state " + element);
                                continue;
                        }
                        File outputDir = ajbc.getOutputDir();
                        if (outputDir != null && outputDir.equals(location)) {
-                               if (debugIncrementalStates) System.err.println("< findStateManagingOutputLocation("+location+") returning "+element);
-                               return element;                         
-                       } 
+                               if (debugIncrementalStates)
+                                       System.err.println("< findStateManagingOutputLocation(" + location + ") returning " + element);
+                               return element;
+                       }
                        CompilationResultDestinationManager outputManager = ajbc.getCompilationResultDestinationManager();
                        if (outputManager != null) {
                                List outputDirs = outputManager.getAllOutputLocations();
-                               for (Iterator iterator = outputDirs.iterator(); iterator
-                                               .hasNext();) {
+                               for (Iterator iterator = outputDirs.iterator(); iterator.hasNext();) {
                                        File dir = (File) iterator.next();
                                        if (dir.equals(location)) {
-                                               if (debugIncrementalStates) System.err.println("< findStateManagingOutputLocation("+location+") returning "+element);
-                                               return element;                         
+                                               if (debugIncrementalStates)
+                                                       System.err.println("< findStateManagingOutputLocation(" + location + ") returning " + element);
+                                               return element;
                                        }
                                }
                        }
                        if (outputDir == null && outputManager == null) {
                                // FIXME why can it ever be null? due to using outjar?
-                               if (debugIncrementalStates) System.err.println("  output directory and output location manager for "+ajbc+" are null");
+                               if (debugIncrementalStates)
+                                       System.err.println("  output directory and output location manager for " + ajbc + " are null");
                                continue;
                        }
 
                }
-               if (debugIncrementalStates) System.err.println("< findStateManagingOutputLocation("+location+") returning null");
+               if (debugIncrementalStates)
+                       System.err.println("< findStateManagingOutputLocation(" + location + ") returning null");
                return null;
        }
-       
+
        // FIXME asc needs a persistence mechanism for storing/loading all state info
        // FIXME asc needs to understand two config files might point at the same output dir... what to do about this?
 }
\ No newline at end of file