diff options
author | mkersten <mkersten> | 2004-03-11 19:19:56 +0000 |
---|---|---|
committer | mkersten <mkersten> | 2004-03-11 19:19:56 +0000 |
commit | 4ee35142ffc1fb7d5776021c533bd4bfbb9cea1c (patch) | |
tree | e57ed9edb53354db905d5665c6a026fd41f615dd /org.aspectj.ajdt.core | |
parent | 1f78bbd8e7d3f4213479f805b6ea4796b5437054 (diff) | |
download | aspectj-4ee35142ffc1fb7d5776021c533bd4bfbb9cea1c.tar.gz aspectj-4ee35142ffc1fb7d5776021c533bd4bfbb9cea1c.zip |
Added methods for retrieving the signature of a program element as it occurrs in the source code.
Needed by ajdoc, possibly useful to other clients.
Diffstat (limited to 'org.aspectj.ajdt.core')
2 files changed, 50 insertions, 9 deletions
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 index 14e89d232..1f8a81a7d 100644 --- 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 @@ -6,6 +6,8 @@ * which accompanies this distribution and is available at * http://www.eclipse.org/legal/cpl-v10.html * + * Contributors: + * PARC initial implementation * ******************************************************************/ package org.aspectj.ajdt.internal.core.builder; @@ -18,6 +20,9 @@ import org.aspectj.weaver.*; import org.aspectj.weaver.patterns.*; import org.eclipse.jdt.internal.compiler.ast.*; +/** + * @author Mik Kersten + */ public class AsmElementFormatter { public static final String DECLARE_PRECEDENCE = "precedence"; 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 2aa2e07ca..674877a37 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 @@ -29,6 +29,9 @@ import org.eclipse.jdt.internal.compiler.ast.*; import org.eclipse.jdt.internal.compiler.lookup.*; import org.eclipse.jdt.internal.compiler.problem.ProblemHandler; +/** + * @author Mik Kersten + */ public class AsmHierarchyBuilder extends ASTVisitor { public static void build( @@ -169,7 +172,7 @@ public class AsmHierarchyBuilder extends ASTVisitor { } return addToNode; } - + public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { String name = new String(typeDeclaration.name); IProgramElement.Kind kind = IProgramElement.Kind.CLASS; @@ -183,6 +186,7 @@ public class AsmHierarchyBuilder extends ASTVisitor { typeDeclaration.modifiers, "", new ArrayList()); + peNode.setSourceSignature(genSourceSignature(typeDeclaration)); ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); @@ -208,6 +212,7 @@ public class AsmHierarchyBuilder extends ASTVisitor { memberTypeDeclaration.modifiers, "", new ArrayList()); + peNode.setSourceSignature(genSourceSignature(memberTypeDeclaration)); ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); @@ -228,10 +233,7 @@ public class AsmHierarchyBuilder extends ASTVisitor { int dollar = fullName.indexOf('$'); fullName = fullName.substring(dollar+1); -// -// System.err.println("member type with name: " + name + ", " + -// new String(fullName)); - + IProgramElement.Kind kind = IProgramElement.Kind.CLASS; if (memberTypeDeclaration.isInterface()) kind = IProgramElement.Kind.INTERFACE; @@ -242,6 +244,7 @@ public class AsmHierarchyBuilder extends ASTVisitor { memberTypeDeclaration.modifiers, "", new ArrayList()); + peNode.setSourceSignature(genSourceSignature(memberTypeDeclaration)); //??? we add this to the compilation unit findEnclosingClass(stack).addChild(peNode); @@ -252,6 +255,11 @@ public class AsmHierarchyBuilder extends ASTVisitor { stack.pop(); } + private String genSourceSignature(TypeDeclaration typeDeclaration) { + StringBuffer output = new StringBuffer(); + typeDeclaration.printHeader(0, output); + return output.toString(); + } private IProgramElement findEnclosingClass(Stack stack) { for (int i = stack.size()-1; i >= 0; i--) { @@ -277,7 +285,8 @@ public class AsmHierarchyBuilder extends ASTVisitor { genBytecodeInfo(methodDeclaration, peNode); peNode.setModifiers(methodDeclaration.modifiers); peNode.setCorrespondingType(methodDeclaration.returnType.toString()); - + peNode.setSourceSignature(genSourceSignature(methodDeclaration)); + // TODO: add return type test if (peNode.getKind().equals(IProgramElement.Kind.METHOD)) { if (peNode.toLabelString().equals("main(String[])") @@ -291,6 +300,27 @@ public class AsmHierarchyBuilder extends ASTVisitor { return true; } + private String genSourceSignature(MethodDeclaration methodDeclaration) { + StringBuffer output = new StringBuffer(); + methodDeclaration.printModifiers(methodDeclaration.modifiers, output); + methodDeclaration.printReturnType(0, output).append(methodDeclaration.selector).append('('); + if (methodDeclaration.arguments != null) { + for (int i = 0; i < methodDeclaration.arguments.length; i++) { + if (i > 0) output.append(", "); //$NON-NLS-1$ + methodDeclaration.arguments[i].print(0, output); + } + } + output.append(')'); + if (methodDeclaration.thrownExceptions != null) { + output.append(" throws "); //$NON-NLS-1$ + for (int i = 0; i < methodDeclaration.thrownExceptions.length; i++) { + if (i > 0) output.append(", "); //$NON-NLS-1$ + methodDeclaration.thrownExceptions[i].print(0, output); + } + } + return output.toString(); + } + private void genBytecodeInfo(MethodDeclaration methodDeclaration, IProgramElement peNode) { if (methodDeclaration.binding != null) { String memberName = ""; @@ -301,8 +331,8 @@ public class AsmHierarchyBuilder extends ASTVisitor { memberBytecodeSignature = member.getSignature(); } catch (NullPointerException npe) { memberName = "<undefined>"; - } - + } + peNode.setBytecodeName(memberName); peNode.setBytecodeSignature(memberBytecodeSignature); } @@ -354,8 +384,8 @@ public class AsmHierarchyBuilder extends ASTVisitor { fieldDeclaration.modifiers, "", new ArrayList()); - peNode.setCorrespondingType(fieldDeclaration.type.toString()); + peNode.setSourceSignature(genSourceSignature(fieldDeclaration)); ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); @@ -364,6 +394,12 @@ public class AsmHierarchyBuilder extends ASTVisitor { public void endVisit(FieldDeclaration fieldDeclaration, MethodScope scope) { stack.pop(); } + + private String genSourceSignature(FieldDeclaration fieldDeclaration) { + StringBuffer output = new StringBuffer(); + fieldDeclaration.print(0, output); + return output.toString(); + } // public boolean visit(ImportReference importRef, CompilationUnitScope scope) { |