From b5d8b449c79cbedc82e03381cc459ae8c8ae9718 Mon Sep 17 00:00:00 2001 From: mkersten Date: Thu, 14 Aug 2003 09:07:44 +0000 Subject: Updated org.aspectj.asm relationship model to string-handle-based API in order to support adding and removing relationships at any point in the compilation cycle, and to support external tools building relationships (e.g. JDT's incremental containment hierarchy builder). Also made inter-type declaration relationships show up in the model. --- .../compiler/lookup/AjLookupEnvironment.java | 5 + .../lookup/AsmInterTypeRelationshipProvider.java | 67 ++++++ .../ajdt/internal/core/builder/AjBuildManager.java | 11 +- .../internal/core/builder/AsmElementFormatter.java | 268 +++++++++++++++++++++ .../internal/core/builder/AsmHierarchyBuilder.java | 19 +- .../internal/core/builder/AsmNodeFormatter.java | 237 ------------------ .../core/builder/EmacsStructureModelManager.java | 4 +- 7 files changed, 356 insertions(+), 255 deletions(-) create mode 100644 org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java create mode 100644 org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java delete mode 100644 org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java (limited to 'org.aspectj.ajdt.core/src') diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java index 8bbf228a8..171aeb722 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java @@ -16,6 +16,9 @@ package org.aspectj.ajdt.internal.compiler.lookup; import java.util.*; import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration; +import org.aspectj.asm.*; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.internal.Relationship; import org.aspectj.bridge.IMessage; import org.aspectj.weaver.*; import org.aspectj.weaver.patterns.*; @@ -211,6 +214,8 @@ public class AjLookupEnvironment extends LookupEnvironment { needOldStyleWarning = false; } onType.addInterTypeMunger(munger); + + AsmInterTypeRelationshipProvider.addRelationship(onType, munger); } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java new file mode 100644 index 000000000..329e5b57e --- /dev/null +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java @@ -0,0 +1,67 @@ +/* ******************************************************************* + * Copyright (c) 2003 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Mik Kersten initial implementation + * ******************************************************************/ + +package org.aspectj.ajdt.internal.compiler.lookup; + +import java.util.*; + +import org.aspectj.asm.*; +import org.aspectj.asm.internal.Relationship; +import org.aspectj.weaver.*; + +/** + * @author Mik Kersten + */ +public class AsmInterTypeRelationshipProvider { + + public static final String INTER_TYPE_DECLARES = "declares on"; + public static final String INTER_TYPE_DECLARED_BY = "aspect declarations"; + + public static void addRelationship( + ResolvedTypeX onType, + EclipseTypeMunger munger) { + + IProgramElement.Kind kind = IProgramElement.Kind.ERROR; + if (munger.getMunger().getKind() == ResolvedTypeMunger.Field) { + kind = IProgramElement.Kind.INTER_TYPE_FIELD; + } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Constructor) { + kind = IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR; + } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Method) { + kind = IProgramElement.Kind.INTER_TYPE_METHOD; + } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Parent) { + kind = IProgramElement.Kind.INTER_TYPE_PARENT; + } + + if (munger.getSourceLocation() != null + && munger.getSourceLocation() != null) { + String sourceHandle = + munger.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM + + munger.getSourceLocation().getLine() + IProgramElement.ID_DELIM + + munger.getSourceLocation().getColumn(); + + String targetHandle = + onType.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM + + onType.getSourceLocation().getLine() + IProgramElement.ID_DELIM + + onType.getSourceLocation().getColumn(); + + IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap(); + if (sourceHandle != null && targetHandle != null) { + IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARES); + foreward.getTargets().add(targetHandle); + + IRelationship back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARED_BY); + back.getTargets().add(sourceHandle); + } + } + } + +} 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 8cb60f48f..bada76650 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 @@ -22,6 +22,7 @@ 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.*; +import org.aspectj.asm.internal.*; import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.*; import org.aspectj.weaver.World; @@ -42,7 +43,7 @@ public class AjBuildManager { private int compiledCount; private int sourceFileCount; - private AspectJModel structureModel; + private IHierarchy structureModel; public AjBuildConfig buildConfig; AjState state = new AjState(this); @@ -118,7 +119,7 @@ public class AjBuildManager { if (batch) { // System.err.println("XXXX batch: " + buildConfig.getFiles()); if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) { - bcelWorld.setModel(AsmManager.getDefault().getModel()); + bcelWorld.setModel(AsmManager.getDefault().getHierarchy()); // in incremental build, only get updated model? } performCompilation(buildConfig.getFiles()); @@ -167,7 +168,7 @@ public class AjBuildManager { private void setupModel() { String rootLabel = ""; - AspectJModel model = AsmManager.getDefault().getModel(); + IHierarchy model = AsmManager.getDefault().getHierarchy(); IProgramElement.Kind kind = IProgramElement.Kind.FILE_JAVA; if (buildConfig.getConfigFile() != null) { rootLabel = buildConfig.getConfigFile().getName(); @@ -523,14 +524,14 @@ public class AjBuildManager { } - public void setStructureModel(AspectJModel structureModel) { + public void setStructureModel(IHierarchy structureModel) { this.structureModel = structureModel; } /** * Returns null if there is no structure model */ - public AspectJModel getStructureModel() { + public IHierarchy getStructureModel() { return structureModel; } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java new file mode 100644 index 000000000..114bf7439 --- /dev/null +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java @@ -0,0 +1,268 @@ +/* ******************************************************************* + * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * ******************************************************************/ + +package org.aspectj.ajdt.internal.core.builder; + +import java.util.*; + +import org.aspectj.ajdt.internal.compiler.ast.*; +import org.aspectj.asm.IProgramElement; +import org.aspectj.weaver.*; +import org.aspectj.weaver.patterns.*; +import org.eclipse.jdt.internal.compiler.ast.*; + +public class AsmElementFormatter { + + public static final String DECLARE_PRECEDENCE = "precedence"; + public static final String DECLARE_SOFT = "soft"; + public static final String DECLARE_PARENTS = "parents"; + public static final String DECLARE_WARNING = "warning"; + public static final String DECLARE_ERROR = "error"; + public static final String DECLARE_UNKNONWN = ""; + public static final String POINTCUT_ABSTRACT = ""; + public static final String POINTCUT_ANONYMOUS = ""; + public static final int MAX_MESSAGE_LENGTH = 18; + public static final String DEC_LABEL = "declare"; + + public void genLabelAndKind(MethodDeclaration methodDeclaration, IProgramElement node) { + + if (methodDeclaration instanceof AdviceDeclaration) { + AdviceDeclaration ad = (AdviceDeclaration)methodDeclaration; + node.setKind(IProgramElement.Kind.ADVICE); + + if (ad.kind == AdviceKind.Around) { + node.setReturnType(ad.returnTypeToString(0)); + } + + String details = ""; + if (ad.pointcutDesignator != null) { + if (ad.pointcutDesignator.getPointcut() instanceof ReferencePointcut) { + ReferencePointcut rp = (ReferencePointcut)ad.pointcutDesignator.getPointcut(); + details += rp.name + ".."; + } else if (ad.pointcutDesignator.getPointcut() instanceof AndPointcut) { + AndPointcut ap = (AndPointcut)ad.pointcutDesignator.getPointcut(); + if (ap.getLeft() instanceof ReferencePointcut) { + details += ap.getLeft().toString() + ".."; + } else { + details += POINTCUT_ANONYMOUS + ".."; + } + } else if (ad.pointcutDesignator.getPointcut() instanceof OrPointcut) { + OrPointcut op = (OrPointcut)ad.pointcutDesignator.getPointcut(); + if (op.getLeft() instanceof ReferencePointcut) { + details += op.getLeft().toString() + ".."; + } else { + details += POINTCUT_ANONYMOUS + ".."; + } + } else { + details += POINTCUT_ANONYMOUS; + } + } else { + details += POINTCUT_ABSTRACT; + } + node.setName(ad.kind.toString()); + node.setDetails(details); + setParameters(methodDeclaration, node); + + } else if (methodDeclaration instanceof PointcutDeclaration) { + PointcutDeclaration pd = (PointcutDeclaration)methodDeclaration; + node.setKind(IProgramElement.Kind.POINTCUT); + node.setName(translatePointcutName(new String(methodDeclaration.selector))); + setParameters(methodDeclaration, node); + + } else if (methodDeclaration instanceof DeclareDeclaration) { + DeclareDeclaration declare = (DeclareDeclaration)methodDeclaration; + String name = DEC_LABEL + " "; + if (declare.declare instanceof DeclareErrorOrWarning) { + DeclareErrorOrWarning deow = (DeclareErrorOrWarning)declare.declare; + + if (deow.isError()) { + node.setKind( IProgramElement.Kind.DECLARE_ERROR); + name += DECLARE_ERROR; + } else { + node.setKind( IProgramElement.Kind.DECLARE_WARNING); + name += DECLARE_WARNING; + } + node.setName(name) ; + node.setDetails("\"" + genDeclareMessage(deow.getMessage()) + "\""); + + } else if (declare.declare instanceof DeclareParents) { + node.setKind( IProgramElement.Kind.DECLARE_PARENTS); + DeclareParents dp = (DeclareParents)declare.declare; + node.setName(name + DECLARE_PARENTS); + node.setDetails(genTypePatternLabel(dp.getChild())); + + } else if (declare.declare instanceof DeclareSoft) { + node.setKind( IProgramElement.Kind.DECLARE_SOFT); + DeclareSoft ds = (DeclareSoft)declare.declare; + node.setName(name + DECLARE_SOFT); + node.setDetails(genTypePatternLabel(ds.getException())); + + } else if (declare.declare instanceof DeclarePrecedence) { + node.setKind( IProgramElement.Kind.DECLARE_PRECEDENCE); + DeclarePrecedence ds = (DeclarePrecedence)declare.declare; + node.setName(name + DECLARE_PRECEDENCE); + node.setDetails(genPrecedenceListLabel(ds.getPatterns())); + + + } else { + node.setKind(IProgramElement.Kind.ERROR); + node.setName(DECLARE_UNKNONWN); + } + + } else if (methodDeclaration instanceof InterTypeDeclaration) { + InterTypeDeclaration itd = (InterTypeDeclaration)methodDeclaration; + String name = itd.onType.toString() + "." + new String(itd.getDeclaredSelector()); + if (methodDeclaration instanceof InterTypeFieldDeclaration) { + node.setKind(IProgramElement.Kind.INTER_TYPE_FIELD); + } else if (methodDeclaration instanceof InterTypeMethodDeclaration) { + node.setKind(IProgramElement.Kind.INTER_TYPE_METHOD); + InterTypeMethodDeclaration itmd = (InterTypeMethodDeclaration)methodDeclaration; + } else if (methodDeclaration instanceof InterTypeConstructorDeclaration) { + node.setKind(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); + InterTypeConstructorDeclaration itcd = (InterTypeConstructorDeclaration)methodDeclaration; + } else { + node.setKind(IProgramElement.Kind.ERROR); + } + node.setName(name); + node.setReturnType(itd.returnType.toString()); + if (node.getKind() != IProgramElement.Kind.INTER_TYPE_FIELD) { + setParameters(methodDeclaration, node); + } + } else { + if (methodDeclaration.isConstructor()) { + node.setKind(IProgramElement.Kind.CONSTRUCTOR); + } else { + node.setKind(IProgramElement.Kind.METHOD); + } + String label = new String(methodDeclaration.selector); + node.setName(label); + setParameters(methodDeclaration, node); + } + } + + + private String genPrecedenceListLabel(TypePatternList list) { + String tpList = ""; + for (int i = 0; i < list.size(); i++) { + tpList += genTypePatternLabel(list.get(i)); + if (i < list.size()-1) tpList += ", "; + } + return tpList; + } + +// private String genArguments(MethodDeclaration md) { +// String args = ""; +// Argument[] argArray = md.arguments; +// if (argArray == null) return args; +// for (int i = 0; i < argArray.length; i++) { +// String argName = new String(argArray[i].name); +// String argType = argArray[i].type.toString(); +// if (acceptArgument(argName, argType)) { +// args += argType + ", "; +// } +// } +// int lastSepIndex = args.lastIndexOf(','); +// if (lastSepIndex != -1 && args.endsWith(", ")) args = args.substring(0, lastSepIndex); +// return args; +// } + + private void setParameters(MethodDeclaration md, IProgramElement pe) { + Argument[] argArray = md.arguments; + List names = new ArrayList(); + List types = new ArrayList(); + pe.setParameterNames(names); + pe.setParameterTypes(types); + + if (argArray == null) return; + for (int i = 0; i < argArray.length; i++) { + String argName = new String(argArray[i].name); + String argType = argArray[i].type.toString(); + if (acceptArgument(argName, argType)) { + names.add(argName); + types.add(argType); + } + } + } + + // TODO: fix this way of determing ajc-added arguments, make subtype of Argument with extra info + private boolean acceptArgument(String name, String type) { + return !name.startsWith("ajc$this_") + && !type.equals("org.aspectj.lang.JoinPoint.StaticPart") + && !type.equals("org.aspectj.lang.JoinPoint") + && !type.equals("org.aspectj.runtime.internal.AroundClosure"); + } + + + public String genTypePatternLabel(TypePattern tp) { + final String TYPE_PATTERN_LITERAL = ""; + String label; + TypeX typeX = tp.getExactType(); + + if (typeX != ResolvedTypeX.MISSING) { + label = typeX.getName(); + if (tp.isIncludeSubtypes()) label += "+"; + } else { + label = TYPE_PATTERN_LITERAL; + } + return label; + + } + + public String genDeclareMessage(String message) { + int length = message.length(); + if (length < MAX_MESSAGE_LENGTH) { + return message; + } else { + return message.substring(0, MAX_MESSAGE_LENGTH-1) + ".."; + } + } + +// // TODO: +// private String translateAdviceName(String label) { +// if (label.indexOf("before") != -1) return "before"; +// if (label.indexOf("returning") != -1) return "after returning"; +// if (label.indexOf("after") != -1) return "after"; +// if (label.indexOf("around") != -1) return "around"; +// else return ""; +// } + +// // !!! move or replace +// private String translateDeclareName(String name) { +// int colonIndex = name.indexOf(":"); +// if (colonIndex != -1) { +// return name.substring(0, colonIndex); +// } else { +// return name; +// } +// } + + // !!! move or replace +// private String translateInterTypeDecName(String name) { +// int index = name.lastIndexOf('$'); +// if (index != -1) { +// return name.substring(index+1); +// } else { +// return name; +// } +// } + + // !!! move or replace + private String translatePointcutName(String name) { + int index = name.indexOf("$$")+2; + int endIndex = name.lastIndexOf('$'); + if (index != -1 && endIndex != -1) { + return name.substring(index, endIndex); + } else { + return name; + } + } + + +} diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java index c159919d5..d044ab0fb 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java @@ -19,6 +19,7 @@ import java.util.*; 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.*; import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.*; import org.aspectj.util.LangUtil; @@ -32,14 +33,14 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { public static void build( CompilationUnitDeclaration unit, - AspectJModel structureModel) { + IHierarchy structureModel) { LangUtil.throwIaxIfNull(unit, "unit"); new AsmHierarchyBuilder(unit.compilationResult()).internalBuild(unit, structureModel); } private final Stack stack; private final CompilationResult currCompilationResult; - private AsmNodeFormatter formatter = new AsmNodeFormatter(); + private AsmElementFormatter formatter = new AsmElementFormatter(); protected AsmHierarchyBuilder(CompilationResult result) { LangUtil.throwIaxIfNull(result, "result"); @@ -53,7 +54,7 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { */ private void internalBuild( CompilationUnitDeclaration unit, - AspectJModel structureModel) { + IHierarchy structureModel) { LangUtil.throwIaxIfNull(structureModel, "structureModel"); if (!currCompilationResult.equals(unit.compilationResult())) { throw new IllegalArgumentException("invalid unit: " + unit); @@ -112,11 +113,11 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { } /** - * Get/create teh node (package or root) to add to. + * Get/create the node (package or root) to add to. */ private IProgramElement genAddToNode( CompilationUnitDeclaration unit, - AspectJModel structureModel) { + IHierarchy structureModel) { final IProgramElement addToNode; { ImportReference currentPackage = unit.currentPackage; @@ -174,8 +175,6 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { typeDeclaration.modifiers, "", new ArrayList()); -// peNode.setFullSignature(typeDeclaration.()); - ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); return true; @@ -201,8 +200,6 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { "", new ArrayList()); - peNode.setFullSignature(memberTypeDeclaration.toString()); - ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); return true; @@ -265,7 +262,7 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { return (IProgramElement)stack.peek(); } - public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { + public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { IProgramElement peNode = new ProgramElement( "", IProgramElement.Kind.ERROR, @@ -280,7 +277,7 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { // TODO: add return type test if (peNode.getKind().equals(IProgramElement.Kind.METHOD)) { - if (peNode.getName().equals("main(String[])") + if (peNode.toLabelString().equals("main(String[])") && peNode.getModifiers().contains(IProgramElement.Modifiers.STATIC) && peNode.getAccessibility().equals(IProgramElement.Accessibility.PUBLIC)) { ((IProgramElement)stack.peek()).setRunnable(true); 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 deleted file mode 100644 index e2025743e..000000000 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java +++ /dev/null @@ -1,237 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Common Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * ******************************************************************/ - -package org.aspectj.ajdt.internal.core.builder; - -import java.util.Iterator; - -import org.aspectj.ajdt.internal.compiler.ast.*; -import org.aspectj.asm.IProgramElement; -import org.aspectj.weaver.*; -import org.aspectj.weaver.patterns.*; -import org.eclipse.jdt.internal.compiler.ast.*; - -public class AsmNodeFormatter { - - public static final String DECLARE_PRECEDENCE = "precedence: "; - public static final String DECLARE_SOFT = "soft: "; - public static final String DECLARE_PARENTS = "parents: "; - public static final String DECLARE_WARNING = "warning: "; - public static final String DECLARE_ERROR = "error: "; - public static final String DECLARE_UNKNONWN = ""; - public static final String POINTCUT_ABSTRACT = ""; - public static final String POINTCUT_ANONYMOUS = ""; - public static final int MAX_MESSAGE_LENGTH = 18; - public static final String DEC_LABEL = "declare"; - - public void genLabelAndKind(MethodDeclaration methodDeclaration, IProgramElement node) { - if (methodDeclaration instanceof AdviceDeclaration) { - AdviceDeclaration ad = (AdviceDeclaration)methodDeclaration; - node.setKind( IProgramElement.Kind.ADVICE); - String label = ""; - label += ad.kind.toString(); - label += "(" + genArguments(ad) + "): "; - - if (ad.kind == AdviceKind.Around) { - node.setReturnType(ad.returnTypeToString(0)); - } - - if (ad.pointcutDesignator != null) { - if (ad.pointcutDesignator.getPointcut() instanceof ReferencePointcut) { - ReferencePointcut rp = (ReferencePointcut)ad.pointcutDesignator.getPointcut(); - label += rp.name + ".."; - } else if (ad.pointcutDesignator.getPointcut() instanceof AndPointcut) { - AndPointcut ap = (AndPointcut)ad.pointcutDesignator.getPointcut(); - if (ap.getLeft() instanceof ReferencePointcut) { - label += ap.getLeft().toString() + ".."; - } else { - label += POINTCUT_ANONYMOUS + ".."; - } - } else if (ad.pointcutDesignator.getPointcut() instanceof OrPointcut) { - OrPointcut op = (OrPointcut)ad.pointcutDesignator.getPointcut(); - if (op.getLeft() instanceof ReferencePointcut) { - label += op.getLeft().toString() + ".."; - } else { - label += POINTCUT_ANONYMOUS + ".."; - } - } else { - label += POINTCUT_ANONYMOUS; - } - } else { - label += POINTCUT_ABSTRACT; - } - node.setName(label); - - } else if (methodDeclaration instanceof PointcutDeclaration) { - PointcutDeclaration pd = (PointcutDeclaration)methodDeclaration; - node.setKind( IProgramElement.Kind.POINTCUT); - String label = translatePointcutName(new String(methodDeclaration.selector)); - label += "(" + genArguments(pd) + ")"; - node.setName(label); - - } else if (methodDeclaration instanceof DeclareDeclaration) { - DeclareDeclaration declare = (DeclareDeclaration)methodDeclaration; - String label = DEC_LABEL + " "; - if (declare.declare instanceof DeclareErrorOrWarning) { - DeclareErrorOrWarning deow = (DeclareErrorOrWarning)declare.declare; - - if (deow.isError()) { - node.setKind( IProgramElement.Kind.DECLARE_ERROR); - label += DECLARE_ERROR; - } else { - node.setKind( IProgramElement.Kind.DECLARE_WARNING); - label += DECLARE_WARNING; - } - node.setName(label + "\"" + genDeclareMessage(deow.getMessage()) + "\"") ; - - } else if (declare.declare instanceof DeclareParents) { - 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( 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( IProgramElement.Kind.DECLARE_PRECEDENCE); - DeclarePrecedence ds = (DeclarePrecedence)declare.declare; - node.setName(label + DECLARE_PRECEDENCE + genPrecedenceListLabel(ds.getPatterns())); - } else { - node.setKind( IProgramElement.Kind.ERROR); - node.setName(DECLARE_UNKNONWN); - } - - } else if (methodDeclaration instanceof InterTypeDeclaration) { - InterTypeDeclaration itd = (InterTypeDeclaration)methodDeclaration; - String label = itd.onType.toString() + "." + new String(itd.getDeclaredSelector()); - if (methodDeclaration instanceof InterTypeFieldDeclaration) { - node.setKind(IProgramElement.Kind.INTER_TYPE_FIELD); - } else if (methodDeclaration instanceof InterTypeMethodDeclaration) { - node.setKind(IProgramElement.Kind.INTER_TYPE_METHOD); - InterTypeMethodDeclaration itmd = (InterTypeMethodDeclaration)methodDeclaration; - label += "(" + genArguments(itd) + ")"; - } else if (methodDeclaration instanceof InterTypeConstructorDeclaration) { - node.setKind(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); - InterTypeConstructorDeclaration itcd = (InterTypeConstructorDeclaration)methodDeclaration; - } else { - node.setKind(IProgramElement.Kind.ERROR); - } - node.setName(label); - node.setReturnType(itd.returnType.toString()); - - } else { - 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); - } - } - - - private String genPrecedenceListLabel(TypePatternList list) { - String tpList = ""; - for (int i = 0; i < list.size(); i++) { - tpList += genTypePatternLabel(list.get(i)); - if (i < list.size()-1) tpList += ", "; - } - return tpList; - } - - private String genArguments(MethodDeclaration md) { - String args = ""; - Argument[] argArray = md.arguments; - if (argArray == null) return args; - for (int i = 0; i < argArray.length; i++) { - String argName = new String(argArray[i].name); - String argType = argArray[i].type.toString(); -// TODO: fix this way of determing ajc-added arguments, make subtype of Argument with extra info - if (!argName.startsWith("ajc$this_") - && !argType.equals("org.aspectj.lang.JoinPoint.StaticPart") - && !argType.equals("org.aspectj.lang.JoinPoint") - && !argType.equals("org.aspectj.runtime.internal.AroundClosure")) { - args += argType + ", "; - } - } - int lastSepIndex = args.lastIndexOf(','); - if (lastSepIndex != -1 && args.endsWith(", ")) args = args.substring(0, lastSepIndex); - return args; - } - - public String genTypePatternLabel(TypePattern tp) { - final String TYPE_PATTERN_LITERAL = ""; - String label; - TypeX typeX = tp.getExactType(); - - if (typeX != ResolvedTypeX.MISSING) { - label = typeX.getName(); - if (tp.isIncludeSubtypes()) label += "+"; - } else { - label = TYPE_PATTERN_LITERAL; - } - return label; - - } - - public String genDeclareMessage(String message) { - int length = message.length(); - if (length < MAX_MESSAGE_LENGTH) { - return message; - } else { - return message.substring(0, MAX_MESSAGE_LENGTH-1) + ".."; - } - } - -// // TODO: -// private String translateAdviceName(String label) { -// if (label.indexOf("before") != -1) return "before"; -// if (label.indexOf("returning") != -1) return "after returning"; -// if (label.indexOf("after") != -1) return "after"; -// if (label.indexOf("around") != -1) return "around"; -// else return ""; -// } - -// // !!! move or replace -// private String translateDeclareName(String name) { -// int colonIndex = name.indexOf(":"); -// if (colonIndex != -1) { -// return name.substring(0, colonIndex); -// } else { -// return name; -// } -// } - - // !!! move or replace -// private String translateInterTypeDecName(String name) { -// int index = name.lastIndexOf('$'); -// if (index != -1) { -// return name.substring(index+1); -// } else { -// return name; -// } -// } - - // !!! move or replace - private String translatePointcutName(String name) { - int index = name.indexOf("$$")+2; - int endIndex = name.lastIndexOf('$'); - if (index != -1 && endIndex != -1) { - return name.substring(index, endIndex); - } else { - return name; - } - } - - -} 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 93e1bd5fe..4188adeb4 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 @@ -32,11 +32,11 @@ public class EmacsStructureModelManager { } public void externalizeModel() { - if (!AsmManager.getDefault().getModel().isValid()) return; + if (!AsmManager.getDefault().getHierarchy().isValid()) return; try { //Set fileSet = StructureModelManager.INSTANCE.getStructureModel().getFileMap().entrySet(); - Set fileSet = AsmManager.getDefault().getModel().getFileMapEntrySet(); + Set fileSet = AsmManager.getDefault().getHierarchy().getFileMapEntrySet(); for (Iterator it = fileSet.iterator(); it.hasNext(); ) { IProgramElement peNode = (IProgramElement)((Map.Entry)it.next()).getValue(); dumpStructureToFile(peNode); -- cgit v1.2.3