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.

AjProblemReporter.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.problem;
  13. import java.lang.reflect.Modifier;
  14. import java.util.Iterator;
  15. import org.aspectj.ajdt.internal.compiler.ast.*;
  16. import org.aspectj.ajdt.internal.compiler.ast.Proceed;
  17. import org.aspectj.ajdt.internal.compiler.lookup.EclipseWorld;
  18. import org.aspectj.util.FuzzyBoolean;
  19. import org.aspectj.weaver.*;
  20. import org.aspectj.weaver.Shadow;
  21. import org.aspectj.weaver.patterns.DeclareSoft;
  22. import org.eclipse.jdt.internal.compiler.*;
  23. import org.eclipse.jdt.internal.compiler.ast.AstNode;
  24. import org.eclipse.jdt.internal.compiler.impl.*;
  25. import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
  26. import org.eclipse.jdt.internal.compiler.lookup.*;
  27. import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
  28. import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
  29. import org.eclipse.jdt.internal.compiler.util.CharOperation;
  30. /**
  31. * Extends problem reporter to support compiler-side implementation of declare soft.
  32. * Also overrides error reporting for the need to implement abstract methods to
  33. * account for inter-type declarations and pointcut declarations. This second
  34. * job might be better done directly in the SourceTypeBinding/ClassScope classes.
  35. *
  36. * @author Jim Hugunin
  37. */
  38. public class AjProblemReporter extends ProblemReporter {
  39. private static final boolean DUMP_STACK = false;
  40. public EclipseWorld world;
  41. public AjProblemReporter(
  42. IErrorHandlingPolicy policy,
  43. CompilerOptions options,
  44. IProblemFactory problemFactory) {
  45. super(policy, options, problemFactory);
  46. }
  47. public void unhandledException(
  48. TypeBinding exceptionType,
  49. AstNode location)
  50. {
  51. if (!world.getDeclareSoft().isEmpty()) {
  52. Shadow callSite = world.makeShadow(location, referenceContext);
  53. if (callSite == null) {
  54. super.unhandledException(exceptionType, location);
  55. return;
  56. }
  57. Shadow enclosingExec = world.makeShadow(referenceContext);
  58. // System.err.println("about to show error for unhandled exception: " + exceptionType +
  59. // " at " + location + " in " + referenceContext);
  60. for (Iterator i = world.getDeclareSoft().iterator(); i.hasNext(); ) {
  61. DeclareSoft d = (DeclareSoft)i.next();
  62. FuzzyBoolean match = d.getPointcut().match(callSite);
  63. if (match.alwaysTrue()) {
  64. //System.err.println("matched callSite: " + callSite + " with " + d);
  65. return;
  66. } else if (!match.alwaysFalse()) {
  67. throw new RuntimeException("unimplemented, shouldn't have fuzzy match here");
  68. }
  69. match = d.getPointcut().match(enclosingExec);
  70. if (match.alwaysTrue()) {
  71. //System.err.println("matched enclosingExec: " + enclosingExec + " with " + d);
  72. return;
  73. } else if (!match.alwaysFalse()) {
  74. throw new RuntimeException("unimplemented, shouldn't have fuzzy match here");
  75. }
  76. }
  77. }
  78. //??? is this always correct
  79. if (location instanceof Proceed) {
  80. return;
  81. }
  82. super.unhandledException(exceptionType, location);
  83. }
  84. private boolean isPointcutDeclaration(MethodBinding binding) {
  85. return CharOperation.startsWith(binding.selector, PointcutDeclaration.mangledPrefix);
  86. }
  87. public void abstractMethodCannotBeOverridden(
  88. SourceTypeBinding type,
  89. MethodBinding concreteMethod)
  90. {
  91. if (isPointcutDeclaration(concreteMethod)) {
  92. return;
  93. }
  94. super.abstractMethodCannotBeOverridden(type, concreteMethod);
  95. }
  96. public void abstractMethodMustBeImplemented(
  97. SourceTypeBinding type,
  98. MethodBinding abstractMethod)
  99. {
  100. // if this is a PointcutDeclaration then there is no error
  101. if (isPointcutDeclaration(abstractMethod)) {
  102. return;
  103. }
  104. // if we implemented this method by an inter-type declaration, then there is no error
  105. //??? be sure this is always right
  106. ResolvedTypeX onTypeX = world.fromEclipse(type); //abstractMethod.declaringClass);
  107. for (Iterator i = onTypeX.getInterTypeMungers().iterator(); i.hasNext(); ) {
  108. ConcreteTypeMunger m = (ConcreteTypeMunger)i.next();
  109. if (m.matches(onTypeX)) {
  110. ResolvedMember sig = m.getSignature();
  111. if (Modifier.isPublic(sig.getModifiers()) && !Modifier.isAbstract(sig.getModifiers())) {
  112. if (ResolvedTypeX.matches(sig, world.makeResolvedMember(abstractMethod))) {
  113. return;
  114. }
  115. }
  116. }
  117. }
  118. super.abstractMethodMustBeImplemented(type, abstractMethod);
  119. }
  120. public void handle(
  121. int problemId,
  122. String[] problemArguments,
  123. int severity,
  124. int problemStartPosition,
  125. int problemEndPosition,
  126. ReferenceContext referenceContext,
  127. CompilationResult unitResult) {
  128. if (severity != Ignore && DUMP_STACK) {
  129. Thread.currentThread().dumpStack();
  130. }
  131. super.handle(
  132. problemId,
  133. problemArguments,
  134. severity,
  135. problemStartPosition,
  136. problemEndPosition,
  137. referenceContext,
  138. unitResult);
  139. }
  140. }