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.

Checker.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 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. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.util.Collection;
  14. import java.util.Collections;
  15. import java.util.Map;
  16. import org.aspectj.asm.AsmManager;
  17. import org.aspectj.asm.IRelationship;
  18. import org.aspectj.bridge.IMessage;
  19. import org.aspectj.bridge.ISourceLocation;
  20. import org.aspectj.bridge.Message;
  21. import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
  22. import org.aspectj.weaver.patterns.PerClause;
  23. import org.aspectj.weaver.patterns.Pointcut;
  24. public class Checker extends ShadowMunger {
  25. private String msg;
  26. private boolean isError;
  27. public Checker(DeclareErrorOrWarning deow) {
  28. super(deow.getPointcut(), deow.getStart(), deow.getEnd(), deow.getSourceContext());
  29. this.msg = deow.getMessage();
  30. this.isError = deow.isError();
  31. }
  32. private Checker(Pointcut pc, int start, int end, ISourceContext context) {
  33. super(pc,start,end,context);
  34. }
  35. public ShadowMunger concretize(ResolvedType fromType, World world, PerClause clause) {
  36. pointcut = pointcut.concretize(fromType, getDeclaringType(), 0, this);
  37. return this;
  38. }
  39. public void specializeOn(Shadow shadow) {
  40. throw new RuntimeException("illegal state");
  41. }
  42. public void implementOn(Shadow shadow) {
  43. throw new RuntimeException("illegal state");
  44. }
  45. public ShadowMunger parameterizeWith(ResolvedType declaringType,Map typeVariableMap) {
  46. Checker ret = new Checker(
  47. getPointcut().parameterizeWith(typeVariableMap),
  48. getStart(),
  49. getEnd(),
  50. this.sourceContext);
  51. ret.msg = this.msg;
  52. ret.isError = this.isError;
  53. return ret;
  54. }
  55. public boolean match(Shadow shadow, World world) {
  56. if (super.match(shadow, world)) {
  57. IMessage message = new Message(
  58. msg,
  59. shadow.toString(),
  60. isError ? IMessage.ERROR : IMessage.WARNING,
  61. shadow.getSourceLocation(),
  62. null,
  63. new ISourceLocation[]{this.getSourceLocation()},true,
  64. 0, // id
  65. -1,-1); // source start/end
  66. world.getMessageHandler().handleMessage(message);
  67. if (world.getCrossReferenceHandler() != null) {
  68. world.getCrossReferenceHandler().addCrossReference(this.getSourceLocation(),
  69. shadow.getSourceLocation(),
  70. (this.isError?IRelationship.Kind.DECLARE_ERROR:IRelationship.Kind.DECLARE_WARNING),false);
  71. }
  72. if (world.getModel() != null) {
  73. AsmRelationshipProvider.getDefault().checkerMunger(world.getModel(), shadow, this);
  74. }
  75. }
  76. return false;
  77. }
  78. public int compareTo(Object other) {
  79. return 0;
  80. }
  81. public Collection getThrownExceptions() { return Collections.EMPTY_LIST; }
  82. /**
  83. * Default to true
  84. * FIXME Alex: ATAJ is that ok in all cases ?
  85. * @return
  86. */
  87. public boolean mustCheckExceptions() { return true; }
  88. // XXX this perhaps ought to take account of the other fields in advice ...
  89. public boolean equals(Object other) {
  90. if (! (other instanceof Checker)) return false;
  91. Checker o = (Checker) other;
  92. return
  93. o.isError == isError &&
  94. ((o.pointcut == null) ? (pointcut == null) : o.pointcut.equals(pointcut)) &&
  95. (AsmManager.getDefault().getHandleProvider().dependsOnLocation()
  96. ?((o.getSourceLocation()==null) ? (getSourceLocation()==null): o.getSourceLocation().equals(getSourceLocation())):true) // pr134471 - remove when handles are improved to be independent of location
  97. ;
  98. }
  99. private volatile int hashCode = -1;
  100. public int hashCode() {
  101. if (hashCode == -1) {
  102. int result = 17;
  103. result = 37*result + (isError?1:0);
  104. result = 37*result + ((pointcut == null) ? 0 : pointcut.hashCode());
  105. hashCode = result;
  106. }
  107. return hashCode;
  108. }
  109. public boolean isError() {
  110. return isError;
  111. }
  112. public ResolvedType getResolvedDeclaringAspect() {
  113. // The aspect which declares this deow is the declaring type
  114. return getDeclaringType();
  115. }
  116. }