diff options
author | mkersten <mkersten> | 2003-08-06 12:26:34 +0000 |
---|---|---|
committer | mkersten <mkersten> | 2003-08-06 12:26:34 +0000 |
commit | 1508de05e2a9c9c8e1d2c429e8b5d0415ce0a1a5 (patch) | |
tree | 823d0b0baa65f7a5b1a3c0b710372391663817d9 /org.aspectj.ajdt.core | |
parent | 511b6634ddd4554f30b4104d493ea7244a79d97b (diff) | |
download | aspectj-1508de05e2a9c9c8e1d2c429e8b5d0415ce0a1a5.tar.gz aspectj-1508de05e2a9c9c8e1d2c429e8b5d0415ce0a1a5.zip |
Improved generation of advice and pointcut names in the ASM.
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r-- | org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java | 89 |
1 files changed, 66 insertions, 23 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java index eef14d7fd..b7425d426 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java @@ -20,14 +20,55 @@ 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 = "<unknown declare>"; + public static final String POINTCUT_ABSTRACT = "<abstract pointcut>"; + public static final String POINTCUT_ANONYMOUS = "<anonymous pointcut>"; 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) { + AdviceDeclaration ad = (AdviceDeclaration)methodDeclaration; node.setKind( ProgramElementNode.Kind.ADVICE); - node.setName(translateAdviceName(new String(methodDeclaration.selector))); - + 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( ProgramElementNode.Kind.POINTCUT); @@ -43,29 +84,29 @@ public class AsmNodeFormatter { if (deow.isError()) { node.setKind( ProgramElementNode.Kind.DECLARE_ERROR); - label += "error: "; + label += DECLARE_ERROR; } else { node.setKind( ProgramElementNode.Kind.DECLARE_WARNING); - label += "warning: "; + label += DECLARE_WARNING; } - node.setName(label + genDeclareMessage(deow.getMessage())) ; + 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())); + node.setName(label + DECLARE_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())); + node.setName(label + DECLARE_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())); + node.setName(label + DECLARE_PRECEDENCE + genPrecedenceListLabel(ds.getPatterns())); } else { node.setKind( ProgramElementNode.Kind.ERROR); - node.setName("<unknown declare>"); + node.setName(DECLARE_UNKNONWN); } } else if (methodDeclaration instanceof InterTypeDeclaration) { @@ -83,11 +124,9 @@ public class AsmNodeFormatter { } 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)); @@ -112,11 +151,15 @@ public class AsmNodeFormatter { 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 += ", "; - } + 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; } @@ -144,14 +187,14 @@ public class AsmNodeFormatter { } } - // !!! 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>"; - } +// // 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 "<advice>"; +// } // // !!! move or replace // private String translateDeclareName(String name) { |