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.

AbstractReferenceTypeDelegate.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Contributors
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * Andy Clement - June 2005 - separated out from ResolvedType
  12. * ******************************************************************/
  13. package org.aspectj.weaver;
  14. import java.util.ArrayList;
  15. import java.util.Collections;
  16. import java.util.List;
  17. import org.aspectj.bridge.ISourceLocation;
  18. import org.aspectj.util.GenericSignature;
  19. import org.aspectj.util.GenericSignature.ClassSignature;
  20. import org.aspectj.util.GenericSignature.FormalTypeParameter;
  21. import org.aspectj.util.GenericSignatureParser;
  22. import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
  23. public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDelegate {
  24. private String sourcefilename = UNKNOWN_SOURCE_FILE;
  25. private ISourceContext sourceContext = SourceContextImpl.UNKNOWN_SOURCE_CONTEXT;
  26. protected boolean exposedToWeaver;
  27. protected ReferenceType resolvedTypeX;
  28. protected ClassSignature cachedGenericClassTypeSignature;
  29. // Happens to match Bcel javaClass default of '<Unknown>'
  30. public final static String UNKNOWN_SOURCE_FILE = "<Unknown>";
  31. public AbstractReferenceTypeDelegate(ReferenceType resolvedTypeX, boolean exposedToWeaver) {
  32. this.resolvedTypeX = resolvedTypeX;
  33. this.exposedToWeaver = exposedToWeaver;
  34. }
  35. @Override
  36. public final boolean isClass() {
  37. return !isAspect() && !isInterface();
  38. }
  39. @Override
  40. public boolean isCacheable() {
  41. return false;
  42. }
  43. /**
  44. * Designed to be overriden by EclipseType to disable collection of shadow mungers during pre-weave compilation phase
  45. */
  46. @Override
  47. public boolean doesNotExposeShadowMungers() {
  48. return false;
  49. }
  50. @Override
  51. public boolean isExposedToWeaver() {
  52. return exposedToWeaver;
  53. }
  54. @Override
  55. public ReferenceType getResolvedTypeX() {
  56. return resolvedTypeX;
  57. }
  58. @Override
  59. public final String getSourcefilename() {
  60. return sourcefilename;
  61. }
  62. public final void setSourcefilename(String sourceFileName) {
  63. sourcefilename = sourceFileName;
  64. if (sourceFileName != null && sourceFileName.equals(AbstractReferenceTypeDelegate.UNKNOWN_SOURCE_FILE)) {
  65. sourcefilename = "Type '" + getResolvedTypeX().getName() + "' (no debug info available)";
  66. } else {
  67. String pname = getResolvedTypeX().getPackageName();
  68. if (pname != null) {
  69. sourcefilename = pname.replace('.', '/') + '/' + sourceFileName;
  70. }
  71. }
  72. if (sourcefilename != null && sourceContext instanceof SourceContextImpl) {
  73. ((SourceContextImpl) sourceContext).setSourceFileName(sourcefilename);
  74. }
  75. }
  76. public ISourceLocation getSourceLocation() {
  77. return getSourceContext().makeSourceLocation(0, 0);
  78. }
  79. @Override
  80. public ISourceContext getSourceContext() {
  81. return sourceContext;
  82. }
  83. public void setSourceContext(ISourceContext isc) {
  84. sourceContext = isc;
  85. }
  86. public GenericSignature.ClassSignature getGenericClassTypeSignature() {
  87. if (cachedGenericClassTypeSignature == null) {
  88. String sig = getDeclaredGenericSignature();
  89. if (sig != null) {
  90. GenericSignatureParser parser = new GenericSignatureParser();
  91. cachedGenericClassTypeSignature = parser.parseAsClassSignature(sig);
  92. }
  93. }
  94. return cachedGenericClassTypeSignature;
  95. }
  96. protected GenericSignature.FormalTypeParameter[] getFormalTypeParametersFromOuterClass() {
  97. List<GenericSignature.FormalTypeParameter> typeParameters = new ArrayList<>();
  98. ResolvedType outerClassType = getOuterClass();
  99. if (!(outerClassType instanceof ReferenceType)) {
  100. if (outerClassType == null) {
  101. return GenericSignature.FormalTypeParameter.NONE;
  102. } else {
  103. if (System.getProperty("aspectj.debug565713","false").toLowerCase().equals("true")) {
  104. System.out.println("DEBUG 565713: Whilst processing type '" + this.resolvedTypeX.getSignature()+
  105. "' - cannot cast the outer type to a reference type. Signature=" + outerClassType.getSignature() +
  106. " toString()=" + outerClassType.toString()+" class=" + outerClassType.getClassName());
  107. return GenericSignature.FormalTypeParameter.NONE;
  108. } else {
  109. throw new BCException("Whilst processing type '" + this.resolvedTypeX.getSignature()
  110. + "' - cannot cast the outer type to a reference type. Signature=" + outerClassType.getSignature()
  111. + " toString()=" + outerClassType.toString()+" class=" + outerClassType.getClassName());
  112. }
  113. }
  114. }
  115. ReferenceType outer = (ReferenceType) outerClassType;
  116. ReferenceTypeDelegate outerDelegate = outer.getDelegate();
  117. AbstractReferenceTypeDelegate outerObjectType = (AbstractReferenceTypeDelegate) outerDelegate;
  118. if (outerObjectType.isNested()) {
  119. GenericSignature.FormalTypeParameter[] parentParams = outerObjectType.getFormalTypeParametersFromOuterClass();
  120. Collections.addAll(typeParameters, parentParams);
  121. }
  122. GenericSignature.ClassSignature outerSig = outerObjectType.getGenericClassTypeSignature();
  123. if (outerSig != null) {
  124. Collections.addAll(typeParameters, outerSig.formalTypeParameters);
  125. }
  126. GenericSignature.FormalTypeParameter[] ret = new GenericSignature.FormalTypeParameter[typeParameters.size()];
  127. typeParameters.toArray(ret);
  128. return ret;
  129. }
  130. @Override
  131. public boolean copySourceContext() {
  132. return true;
  133. }
  134. @Override
  135. public int getCompilerVersion() {
  136. return WeaverVersionInfo.getCurrentWeaverMajorVersion();
  137. }
  138. @Override
  139. public void ensureConsistent() {
  140. }
  141. @Override
  142. public boolean isWeavable() {
  143. return false;
  144. }
  145. @Override
  146. public boolean hasBeenWoven() {
  147. return false;
  148. }
  149. }