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.

InterTypeDeclaration.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. * Xerox/PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.compiler.ast;
  13. import java.lang.reflect.Modifier;
  14. import java.util.*;
  15. import org.aspectj.ajdt.internal.compiler.lookup.*;
  16. import org.aspectj.weaver.*;
  17. import org.eclipse.jdt.internal.compiler.*;
  18. import org.eclipse.jdt.internal.compiler.CompilationResult;
  19. import org.eclipse.jdt.internal.compiler.ast.*;
  20. import org.eclipse.jdt.internal.compiler.lookup.*;
  21. import org.eclipse.jdt.internal.compiler.util.CharOperation;
  22. public abstract class InterTypeDeclaration extends MethodDeclaration {
  23. //public AstNode myDeclaration;
  24. public TypeReference onType;
  25. protected ReferenceBinding onTypeBinding;
  26. protected ResolvedTypeMunger munger;
  27. protected int declaredModifiers;
  28. protected char[] declaredSelector;
  29. //protected Set superMethodsCalled;
  30. public InterTypeDeclaration(CompilationResult result, TypeReference onType) {
  31. super(result);
  32. this.onType = onType;
  33. modifiers = AccPublic | AccStatic;
  34. }
  35. public void setDeclaredModifiers(int modifiers) {
  36. this.declaredModifiers = modifiers;
  37. }
  38. public void setSelector(char[] selector) {
  39. declaredSelector = selector;
  40. this.selector = CharOperation.concat(selector, Integer.toHexString(sourceStart).toCharArray());
  41. }
  42. public void resolve(ClassScope upperScope) {
  43. if (ignoreFurtherInvestigation) return;
  44. ClassScope newParent = new InterTypeScope(upperScope, onTypeBinding);
  45. //interBinding.introducedField.declaringClass);
  46. scope.parent = newParent;
  47. this.scope.isStatic = Modifier.isStatic(declaredModifiers);
  48. super.resolve(newParent);
  49. fixSuperCallsInBody();
  50. }
  51. /**
  52. * Called from AspectDeclarations.buildInterTypeAndPerClause
  53. */
  54. public abstract void build(ClassScope classScope, CrosscuttingMembers xcut);
  55. public void fixSuperCallsInBody() {
  56. SuperFixerVisitor v = new SuperFixerVisitor(this, onTypeBinding);
  57. this.traverse(v, (ClassScope)null);
  58. munger.setSuperMethodsCalled(v.superMethodsCalled);
  59. // HashSet set = new HashSet();
  60. // for (Iterator i = v.superMethodsCalled.iterator(); i.hasNext(); ) {
  61. // MethodBinding b = (MethodBinding)i.next();
  62. // set.add(EclipseWorld.makeResolvedMember(b));
  63. // }
  64. //
  65. // munger.setSuperMethodsCalled(set);
  66. }
  67. protected void resolveOnType(ClassScope classScope) {
  68. checkSpec();
  69. onTypeBinding = (ReferenceBinding)onType.getTypeBinding(classScope);
  70. if (!onTypeBinding.isValidBinding()) {
  71. if (onTypeBinding instanceof ProblemReferenceBinding) {
  72. classScope.problemReporter().invalidType(onType, onTypeBinding);
  73. } else {
  74. //XXX trouble
  75. }
  76. ignoreFurtherInvestigation = true;
  77. }
  78. }
  79. protected void checkSpec() {
  80. if (Modifier.isProtected(declaredModifiers)) {
  81. scope.problemReporter().signalError(sourceStart, sourceEnd,
  82. "protected inter-type declarations are not allowed");
  83. ignoreFurtherInvestigation = true;
  84. }
  85. }
  86. protected List makeEffectiveSignatureAttribute(
  87. ResolvedMember sig,
  88. Shadow.Kind kind,
  89. boolean weaveBody)
  90. {
  91. List l = new ArrayList(1);
  92. l.add(new EclipseAttributeAdapter(
  93. new AjAttribute.EffectiveSignatureAttribute(sig, kind, weaveBody)));
  94. return l;
  95. }
  96. protected int generateInfoAttributes(ClassFile classFile) {
  97. munger.getSignature().setPosition(sourceStart, sourceEnd);
  98. //System.out.println("generating effective for " + this);
  99. List l;;
  100. Shadow.Kind kind = getShadowKindForBody();
  101. if (kind != null) {
  102. l = makeEffectiveSignatureAttribute(munger.getSignature(), kind, true);
  103. } else {
  104. l = new ArrayList(0); //AstUtil.getAjSyntheticAttribute();
  105. }
  106. return classFile.generateMethodInfoAttribute(binding, l);
  107. }
  108. protected abstract Shadow.Kind getShadowKindForBody();
  109. }