You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeclareDeclaration.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.compiler.ast;
  13. //import java.util.List;
  14. import org.aspectj.ajdt.internal.compiler.lookup.EclipseScope;
  15. import org.aspectj.weaver.AjAttribute;
  16. import org.aspectj.weaver.patterns.Declare;
  17. import org.aspectj.weaver.patterns.FormalBinding;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  20. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.*;
  21. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope;
  22. import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser;
  23. public class DeclareDeclaration extends AjMethodDeclaration {
  24. public Declare declareDecl;
  25. /**
  26. * Constructor for IntraTypeDeclaration.
  27. */
  28. static int counter = 0; //XXX evil
  29. public DeclareDeclaration(CompilationResult result, Declare symbolicDeclare) {
  30. super(result);
  31. this.declareDecl = symbolicDeclare;
  32. if (declareDecl != null) {
  33. // AMC added init of declarationSourceXXX fields which are used
  34. // in AsmBuilder for processing of MethodDeclaration locations.
  35. declarationSourceStart = sourceStart = declareDecl.getStart();
  36. declarationSourceEnd = sourceEnd = declareDecl.getEnd();
  37. }
  38. //??? we might need to set parameters to be empty
  39. this.returnType = TypeReference.baseTypeReference(T_void, 0);
  40. this.selector = ("ajc$declare_"+counter++).toCharArray(); //??? performance
  41. }
  42. /**
  43. * A declare declaration exists in a classfile only as an attibute on the
  44. * class. Unlike advice and inter-type declarations, it has no corresponding
  45. * method.
  46. * **AMC** changed the above policy in the case of declare annotation, which uses a
  47. * corresponding method as the anchor for the declared annotation
  48. */
  49. public void generateCode(ClassScope classScope, ClassFile classFile) {
  50. classFile.extraAttributes.add(new EclipseAttributeAdapter(new AjAttribute.DeclareAttribute(declareDecl)));
  51. if (shouldDelegateCodeGeneration()) {
  52. super.generateCode(classScope,classFile);
  53. }
  54. return;
  55. }
  56. protected boolean shouldDelegateCodeGeneration() {
  57. return false;
  58. }
  59. public void parseStatements(
  60. Parser parser,
  61. CompilationUnitDeclaration unit) {
  62. // do nothing
  63. }
  64. public void resolveStatements(ClassScope upperScope) {
  65. // do nothing
  66. }
  67. // public boolean finishResolveTypes(SourceTypeBinding sourceTypeBinding) {
  68. // // there's nothing for our super to resolve usefully
  69. // //if (!super.finishResolveTypes(sourceTypeBinding)) return false;
  70. //// if (declare == null) return true;
  71. ////
  72. //// EclipseScope scope = new EclipseScope(new FormalBinding[0], this.scope);
  73. ////
  74. //// declare.resolve(scope);
  75. //// return true;
  76. // }
  77. public Declare build(ClassScope classScope) {
  78. if (declareDecl == null) return null;
  79. EclipseScope scope = new EclipseScope(new FormalBinding[0], classScope);
  80. declareDecl.resolve(scope);
  81. return declareDecl;
  82. }
  83. public StringBuffer print(int tab, StringBuffer output) {
  84. printIndent(tab, output);
  85. if (declareDecl == null) {
  86. output.append("<declare>");
  87. } else {
  88. output.append(declareDecl.toString());
  89. }
  90. return output;
  91. }
  92. }