Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

InterTypeDeclaration.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. HashSet set = new HashSet();
  59. for (Iterator i = v.superMethodsCalled.iterator(); i.hasNext(); ) {
  60. MethodBinding b = (MethodBinding)i.next();
  61. set.add(EclipseWorld.makeResolvedMember(b));
  62. }
  63. munger.setSuperMethodsCalled(set);
  64. }
  65. protected void resolveOnType(ClassScope classScope) {
  66. checkSpec();
  67. onTypeBinding = (ReferenceBinding)onType.getTypeBinding(classScope);
  68. if (!onTypeBinding.isValidBinding()) {
  69. if (onTypeBinding instanceof ProblemReferenceBinding) {
  70. classScope.problemReporter().invalidType(onType, onTypeBinding);
  71. } else {
  72. //XXX trouble
  73. }
  74. ignoreFurtherInvestigation = true;
  75. }
  76. }
  77. protected void checkSpec() {
  78. if (Modifier.isProtected(declaredModifiers)) {
  79. scope.problemReporter().signalError(sourceStart, sourceEnd,
  80. "protected inter-type declarations are not allowed");
  81. ignoreFurtherInvestigation = true;
  82. }
  83. }
  84. protected List makeEffectiveSignatureAttribute(
  85. ResolvedMember sig,
  86. Shadow.Kind kind,
  87. boolean weaveBody)
  88. {
  89. List l = new ArrayList(1);
  90. l.add(new EclipseAttributeAdapter(
  91. new AjAttribute.EffectiveSignatureAttribute(sig, kind, weaveBody)));
  92. return l;
  93. }
  94. protected int generateInfoAttributes(ClassFile classFile) {
  95. munger.getSignature().setPosition(sourceStart, sourceEnd);
  96. //System.out.println("generating effective for " + this);
  97. List l;;
  98. Shadow.Kind kind = getShadowKindForBody();
  99. if (kind != null) {
  100. l = makeEffectiveSignatureAttribute(munger.getSignature(), kind, true);
  101. } else {
  102. l = new ArrayList(0); //AstUtil.getAjSyntheticAttribute();
  103. }
  104. return classFile.generateMethodInfoAttribute(binding, l);
  105. }
  106. protected abstract Shadow.Kind getShadowKindForBody();
  107. }