aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core
diff options
context:
space:
mode:
authormkersten <mkersten>2003-08-05 16:24:05 +0000
committermkersten <mkersten>2003-08-05 16:24:05 +0000
commit5594a6579a215af6f9db9c806f4e331ec6259136 (patch)
tree83de3d2a7967780c03221f3a1d53dd68c3dc2e39 /org.aspectj.ajdt.core
parent6c1ca40c54c11315aa5caadf23c8f439b26c41e4 (diff)
downloadaspectj-5594a6579a215af6f9db9c806f4e331ec6259136.tar.gz
aspectj-5594a6579a215af6f9db9c806f4e331ec6259136.zip
Revised and added tests for ASM containment hierarchy.
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java110
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java188
2 files changed, 211 insertions, 87 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java
index 3827f6f65..3c3528975 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java
@@ -21,7 +21,8 @@ import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
import org.aspectj.asm.*;
import org.aspectj.bridge.*;
import org.aspectj.util.LangUtil;
-import org.aspectj.weaver.Member;
+import org.aspectj.weaver.*;
+import org.aspectj.weaver.patterns.*;
import org.eclipse.jdt.internal.compiler.*;
import org.eclipse.jdt.internal.compiler.ast.*;
import org.eclipse.jdt.internal.compiler.lookup.*;
@@ -39,6 +40,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
private final Stack stack;
private final CompilationResult currCompilationResult;
+ private AsmNodeFormatter formatter = new AsmNodeFormatter();
protected AsmBuilder(CompilationResult result) {
LangUtil.throwIaxIfNull(result, "result");
@@ -159,10 +161,11 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
name,
kind,
makeLocation(typeDeclaration),
- typeDeclaration.modifiers,
- "",
+ typeDeclaration.modifiers, "",
new ArrayList());
+// peNode.setFullSignature(typeDeclaration.());
+
((StructureNode)stack.peek()).addChild(peNode);
stack.push(peNode);
return true;
@@ -188,6 +191,8 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
"",
new ArrayList());
+ peNode.setFullSignature(memberTypeDeclaration.toString());
+
((StructureNode)stack.peek()).addChild(peNode);
stack.push(peNode);
return true;
@@ -250,54 +255,30 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
return (StructureNode)stack.peek();
}
- // !!! improve name and type generation
- // TODO: improve handling of malformed methodDeclaration.binding
- public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
- ProgramElementNode.Kind kind = ProgramElementNode.Kind.METHOD;
- String label = new String(methodDeclaration.selector);
-
- if (methodDeclaration instanceof AdviceDeclaration) {
- kind = ProgramElementNode.Kind.ADVICE;
- label = translateAdviceName(label);
- } else if (methodDeclaration instanceof PointcutDeclaration) {
- kind = ProgramElementNode.Kind.POINTCUT;
- label = translatePointcutName(label);
- } else if (methodDeclaration instanceof DeclareDeclaration) {
- DeclareDeclaration declare = (DeclareDeclaration)methodDeclaration;
- label = translateDeclareName(declare.toString());
-
- // TODO: fix this horrible way of checking what kind of declare it is
- if (label.indexOf("warning") != -1) {
- kind = ProgramElementNode.Kind.DECLARE_WARNING;
- } else if (label.indexOf("error") != -1) {
- kind = ProgramElementNode.Kind.DECLARE_ERROR;
- } else if (label.indexOf("parents") != -1) {
- kind = ProgramElementNode.Kind.DECLARE_PARENTS;
- } else if (label.indexOf("soft") != -1) {
- kind = ProgramElementNode.Kind.DECLARE_SOFT;
- } else {
- kind = ProgramElementNode.Kind.ERROR;
- }
- } else if (methodDeclaration instanceof InterTypeDeclaration) {
- kind = ProgramElementNode.Kind.INTRODUCTION;
- label = translateInterTypeDecName(new String(((InterTypeDeclaration)methodDeclaration).selector));
- }
-
+ public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
ProgramElementNode peNode = new ProgramElementNode(
- label,
- kind,
+ "",
+ ProgramElementNode.Kind.ERROR,
makeLocation(methodDeclaration),
methodDeclaration.modifiers,
"",
new ArrayList());
- if (kind == ProgramElementNode.Kind.METHOD) {
- // TODO: should improve determining what the main method is
- if (label.equals("main")) {
+ formatter.genLabelAndKind(methodDeclaration, peNode);
+ genBytecodeInfo(methodDeclaration, peNode);
+
+ // TODO: should improve determining what the main method is
+ if (peNode.getProgramElementKind().equals(ProgramElementNode.Kind.METHOD)) {
+ if (peNode.getName().equals("main")) {
((ProgramElementNode)stack.peek()).setRunnable(true);
}
}
+
+ stack.push(peNode);
+ return true;
+ }
+ private void genBytecodeInfo(MethodDeclaration methodDeclaration, ProgramElementNode peNode) {
if (methodDeclaration.binding != null) {
String memberName = "";
String memberBytecodeSignature = "";
@@ -308,14 +289,11 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
} catch (NullPointerException npe) {
memberName = "<undefined>";
}
-
+
peNode.setBytecodeName(memberName);
peNode.setBytecodeSignature(memberBytecodeSignature);
}
((StructureNode)stack.peek()).addChild(peNode);
- stack.push(peNode);
-
- return true;
}
public void endVisit(MethodDeclaration methodDeclaration, ClassScope scope) {
@@ -509,46 +487,4 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
currCompilationResult.lineSeparatorPositions,
td.declarationSourceEnd);
}
-
-
- // !!! move or replace
- 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 "<advice>";
- }
-
- // !!! 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/AsmNodeFormatter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java
new file mode 100644
index 000000000..eef14d7fd
--- /dev/null
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java
@@ -0,0 +1,188 @@
+/* *******************************************************************
+ * 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.ProgramElementNode;
+import org.aspectj.weaver.*;
+import org.aspectj.weaver.patterns.*;
+import org.eclipse.jdt.internal.compiler.ast.*;
+
+public class AsmNodeFormatter {
+
+ public static final int MAX_MESSAGE_LENGTH = 18;
+ public static final String DEC_LABEL = "declare";
+
+ public void genLabelAndKind(MethodDeclaration methodDeclaration, ProgramElementNode node) {
+ if (methodDeclaration instanceof AdviceDeclaration) {
+ node.setKind( ProgramElementNode.Kind.ADVICE);
+ node.setName(translateAdviceName(new String(methodDeclaration.selector)));
+
+ } else if (methodDeclaration instanceof PointcutDeclaration) {
+ PointcutDeclaration pd = (PointcutDeclaration)methodDeclaration;
+ node.setKind( ProgramElementNode.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( ProgramElementNode.Kind.DECLARE_ERROR);
+ label += "error: ";
+ } else {
+ node.setKind( ProgramElementNode.Kind.DECLARE_WARNING);
+ label += "warning: ";
+ }
+ node.setName(label + genDeclareMessage(deow.getMessage())) ;
+
+ } else if (declare.declare instanceof DeclareParents) {
+ node.setKind( ProgramElementNode.Kind.DECLARE_PARENTS);
+ DeclareParents dp = (DeclareParents)declare.declare;
+ node.setName(label + "parents: " + genTypePatternLabel(dp.getChild()));
+
+ } else if (declare.declare instanceof DeclareSoft) {
+ node.setKind( ProgramElementNode.Kind.DECLARE_SOFT);
+ DeclareSoft ds = (DeclareSoft)declare.declare;
+ node.setName(label + "soft: " + genTypePatternLabel(ds.getException()));
+ } else if (declare.declare instanceof DeclarePrecedence) {
+ node.setKind( ProgramElementNode.Kind.DECLARE_PRECEDENCE);
+ DeclarePrecedence ds = (DeclarePrecedence)declare.declare;
+ node.setName(label + "precedence: " + genPrecedenceListLabel(ds.getPatterns()));
+ } else {
+ node.setKind( ProgramElementNode.Kind.ERROR);
+ node.setName("<unknown declare>");
+ }
+
+ } else if (methodDeclaration instanceof InterTypeDeclaration) {
+ InterTypeDeclaration itd = (InterTypeDeclaration)methodDeclaration;
+ String label = itd.onType.toString() + "." + new String(itd.getDeclaredSelector());
+ if (methodDeclaration instanceof InterTypeFieldDeclaration) {
+ node.setKind(ProgramElementNode.Kind.INTER_TYPE_FIELD);
+ } else if (methodDeclaration instanceof InterTypeMethodDeclaration) {
+ node.setKind(ProgramElementNode.Kind.INTER_TYPE_METHOD);
+ InterTypeMethodDeclaration itmd = (InterTypeMethodDeclaration)methodDeclaration;
+ label += "(" + genArguments(itd) + ")";
+ } else if (methodDeclaration instanceof InterTypeConstructorDeclaration) {
+ node.setKind(ProgramElementNode.Kind.INTER_TYPE_CONSTRUCTOR);
+ InterTypeConstructorDeclaration itcd = (InterTypeConstructorDeclaration)methodDeclaration;
+ } else {
+ node.setKind(ProgramElementNode.Kind.ERROR);
+ }
+
+ node.setName(label);
+ node.setReturnType(itd.returnType.toString());
+
+
+ } else {
+ node.setKind(ProgramElementNode.Kind.METHOD);
+ node.setName(new String(methodDeclaration.selector));
+ }
+ }
+
+
+ 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_")) {
+ args += argType;
+ if (i < argArray.length-1) args += ", ";
+ }
+ }
+ return args;
+ }
+
+ public String genTypePatternLabel(TypePattern tp) {
+ final String TYPE_PATTERN_LITERAL = "<type pattern>";
+ 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) + "..";
+ }
+ }
+
+ // !!! move or replace
+ 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 "<advice>";
+ }
+
+// // !!! 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;
+ }
+ }
+
+
+}