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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 (AbstractReferenceTypeDelegate.UNKNOWN_SOURCE_FILE.equals(sourceFileName))
  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. if (sourcefilename != null && sourceContext instanceof SourceContextImpl)
  72. ((SourceContextImpl) sourceContext).setSourceFileName(sourcefilename);
  73. }
  74. public ISourceLocation getSourceLocation() {
  75. return getSourceContext().makeSourceLocation(0, 0);
  76. }
  77. @Override
  78. public ISourceContext getSourceContext() {
  79. return sourceContext;
  80. }
  81. public void setSourceContext(ISourceContext isc) {
  82. sourceContext = isc;
  83. }
  84. public GenericSignature.ClassSignature getGenericClassTypeSignature() {
  85. if (cachedGenericClassTypeSignature == null) {
  86. String sig = getDeclaredGenericSignature();
  87. if (sig != null) {
  88. GenericSignatureParser parser = new GenericSignatureParser();
  89. cachedGenericClassTypeSignature = parser.parseAsClassSignature(sig);
  90. }
  91. }
  92. return cachedGenericClassTypeSignature;
  93. }
  94. protected GenericSignature.FormalTypeParameter[] getFormalTypeParametersFromOuterClass() {
  95. List<GenericSignature.FormalTypeParameter> typeParameters = new ArrayList<>();
  96. ResolvedType outerClassType = getOuterClass();
  97. if (!(outerClassType instanceof ReferenceType)) {
  98. if (outerClassType == null) {
  99. return GenericSignature.FormalTypeParameter.NONE;
  100. } else {
  101. if (System.getProperty("aspectj.debug565713","false").toLowerCase().equals("true")) {
  102. System.out.println("DEBUG 565713: Whilst processing type '" + this.resolvedTypeX.getSignature()+
  103. "' - cannot cast the outer type to a reference type. Signature=" + outerClassType.getSignature() +
  104. " toString()=" + outerClassType.toString()+" class=" + outerClassType.getClassName());
  105. return GenericSignature.FormalTypeParameter.NONE;
  106. } else {
  107. throw new BCException("Whilst processing type '" + this.resolvedTypeX.getSignature()
  108. + "' - cannot cast the outer type to a reference type. Signature=" + outerClassType.getSignature()
  109. + " toString()=" + outerClassType.toString()+" class=" + outerClassType.getClassName());
  110. }
  111. }
  112. }
  113. ReferenceType outer = (ReferenceType) outerClassType;
  114. ReferenceTypeDelegate outerDelegate = outer.getDelegate();
  115. AbstractReferenceTypeDelegate outerObjectType = (AbstractReferenceTypeDelegate) outerDelegate;
  116. if (outerObjectType.isNested()) {
  117. GenericSignature.FormalTypeParameter[] parentParams = outerObjectType.getFormalTypeParametersFromOuterClass();
  118. Collections.addAll(typeParameters, parentParams);
  119. }
  120. GenericSignature.ClassSignature outerSig = outerObjectType.getGenericClassTypeSignature();
  121. if (outerSig != null) {
  122. Collections.addAll(typeParameters, outerSig.formalTypeParameters);
  123. }
  124. GenericSignature.FormalTypeParameter[] ret = new GenericSignature.FormalTypeParameter[typeParameters.size()];
  125. typeParameters.toArray(ret);
  126. return ret;
  127. }
  128. @Override
  129. public boolean copySourceContext() {
  130. return true;
  131. }
  132. @Override
  133. public int getCompilerVersion() {
  134. return WeaverVersionInfo.getCurrentWeaverMajorVersion();
  135. }
  136. @Override
  137. public void ensureConsistent() {
  138. }
  139. @Override
  140. public boolean isWeavable() {
  141. return false;
  142. }
  143. @Override
  144. public boolean hasBeenWoven() {
  145. return false;
  146. }
  147. }