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

15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
14 years ago
15 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  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.List;
  16. import org.aspectj.bridge.ISourceLocation;
  17. import org.aspectj.util.GenericSignature;
  18. import org.aspectj.util.GenericSignature.ClassSignature;
  19. import org.aspectj.util.GenericSignatureParser;
  20. import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
  21. public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDelegate {
  22. private String sourcefilename = UNKNOWN_SOURCE_FILE;
  23. private ISourceContext sourceContext = SourceContextImpl.UNKNOWN_SOURCE_CONTEXT;
  24. protected boolean exposedToWeaver;
  25. protected ReferenceType resolvedTypeX;
  26. protected ClassSignature cachedGenericClassTypeSignature;
  27. // Happens to match Bcel javaClass default of '<Unknown>'
  28. public final static String UNKNOWN_SOURCE_FILE = "<Unknown>";
  29. public AbstractReferenceTypeDelegate(ReferenceType resolvedTypeX, boolean exposedToWeaver) {
  30. this.resolvedTypeX = resolvedTypeX;
  31. this.exposedToWeaver = exposedToWeaver;
  32. }
  33. public final boolean isClass() {
  34. return !isAspect() && !isInterface();
  35. }
  36. public boolean isCacheable() {
  37. return false;
  38. }
  39. /**
  40. * Designed to be overriden by EclipseType to disable collection of shadow mungers during pre-weave compilation phase
  41. */
  42. public boolean doesNotExposeShadowMungers() {
  43. return false;
  44. }
  45. public boolean isExposedToWeaver() {
  46. return exposedToWeaver;
  47. }
  48. public ReferenceType getResolvedTypeX() {
  49. return resolvedTypeX;
  50. }
  51. public final String getSourcefilename() {
  52. return sourcefilename;
  53. }
  54. public final void setSourcefilename(String sourceFileName) {
  55. sourcefilename = sourceFileName;
  56. if (sourceFileName != null && sourceFileName.equals(AbstractReferenceTypeDelegate.UNKNOWN_SOURCE_FILE)) {
  57. sourcefilename = "Type '" + getResolvedTypeX().getName() + "' (no debug info available)";
  58. } else {
  59. String pname = getResolvedTypeX().getPackageName();
  60. if (pname != null) {
  61. sourcefilename = pname.replace('.', '/') + '/' + sourceFileName;
  62. }
  63. }
  64. if (sourcefilename != null && sourceContext instanceof SourceContextImpl) {
  65. ((SourceContextImpl) sourceContext).setSourceFileName(sourcefilename);
  66. }
  67. }
  68. public ISourceLocation getSourceLocation() {
  69. return getSourceContext().makeSourceLocation(0, 0);
  70. }
  71. public ISourceContext getSourceContext() {
  72. return sourceContext;
  73. }
  74. public void setSourceContext(ISourceContext isc) {
  75. sourceContext = isc;
  76. }
  77. public GenericSignature.ClassSignature getGenericClassTypeSignature() {
  78. if (cachedGenericClassTypeSignature == null) {
  79. String sig = getDeclaredGenericSignature();
  80. if (sig != null) {
  81. GenericSignatureParser parser = new GenericSignatureParser();
  82. cachedGenericClassTypeSignature = parser.parseAsClassSignature(sig);
  83. }
  84. }
  85. return cachedGenericClassTypeSignature;
  86. }
  87. protected GenericSignature.FormalTypeParameter[] getFormalTypeParametersFromOuterClass() {
  88. List<GenericSignature.FormalTypeParameter> typeParameters = new ArrayList<GenericSignature.FormalTypeParameter>();
  89. ResolvedType outerClassType = getOuterClass();
  90. if (!(outerClassType instanceof ReferenceType)) {
  91. if (outerClassType == null) {
  92. return GenericSignature.FormalTypeParameter.NONE;
  93. } else {
  94. throw new BCException("Whilst processing type '" + this.resolvedTypeX.getSignature()
  95. + "' - cannot cast the outer type to a reference type. Signature=" + outerClassType.getSignature()
  96. + " toString()=" + outerClassType.toString()+" class=" + outerClassType.getClassName());
  97. }
  98. }
  99. ReferenceType outer = (ReferenceType) outerClassType;
  100. ReferenceTypeDelegate outerDelegate = outer.getDelegate();
  101. AbstractReferenceTypeDelegate outerObjectType = (AbstractReferenceTypeDelegate) outerDelegate;
  102. if (outerObjectType.isNested()) {
  103. GenericSignature.FormalTypeParameter[] parentParams = outerObjectType.getFormalTypeParametersFromOuterClass();
  104. for (int i = 0; i < parentParams.length; i++) {
  105. typeParameters.add(parentParams[i]);
  106. }
  107. }
  108. GenericSignature.ClassSignature outerSig = outerObjectType.getGenericClassTypeSignature();
  109. if (outerSig != null) {
  110. for (int i = 0; i < outerSig.formalTypeParameters.length; i++) {
  111. typeParameters.add(outerSig.formalTypeParameters[i]);
  112. }
  113. }
  114. GenericSignature.FormalTypeParameter[] ret = new GenericSignature.FormalTypeParameter[typeParameters.size()];
  115. typeParameters.toArray(ret);
  116. return ret;
  117. }
  118. public boolean copySourceContext() {
  119. return true;
  120. }
  121. public int getCompilerVersion() {
  122. return WeaverVersionInfo.getCurrentWeaverMajorVersion();
  123. }
  124. public void ensureConsistent() {
  125. }
  126. public boolean isWeavable() {
  127. return false;
  128. }
  129. public boolean hasBeenWoven() {
  130. return false;
  131. }
  132. }