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.

Declare.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 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. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.IOException;
  14. import java.util.Map;
  15. import org.aspectj.weaver.ISourceContext;
  16. import org.aspectj.weaver.ResolvedType;
  17. import org.aspectj.weaver.UnresolvedType;
  18. import org.aspectj.weaver.VersionedDataInputStream;
  19. import org.aspectj.weaver.World;
  20. public abstract class Declare extends PatternNode {
  21. public static final byte ERROR_OR_WARNING = 1;
  22. public static final byte PARENTS = 2;
  23. public static final byte SOFT = 3;
  24. public static final byte DOMINATES = 4;
  25. public static final byte ANNOTATION = 5;
  26. public static final byte PARENTSMIXIN = 6;
  27. public static final byte TYPE_ERROR_OR_WARNING = 7;
  28. // set when reading declare from aspect
  29. private ResolvedType declaringType;
  30. public static Declare read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  31. byte kind = s.readByte();
  32. switch (kind) {
  33. case ERROR_OR_WARNING:
  34. return DeclareErrorOrWarning.read(s, context);
  35. case DOMINATES:
  36. return DeclarePrecedence.read(s, context);
  37. case PARENTS:
  38. return DeclareParents.read(s, context);
  39. case SOFT:
  40. return DeclareSoft.read(s, context);
  41. case ANNOTATION:
  42. return DeclareAnnotation.read(s, context);
  43. case PARENTSMIXIN:
  44. return DeclareParentsMixin.read(s, context);
  45. case TYPE_ERROR_OR_WARNING:
  46. return DeclareTypeErrorOrWarning.read(s, context);
  47. default:
  48. throw new RuntimeException("unimplemented");
  49. }
  50. }
  51. /**
  52. * Returns this declare mutated
  53. */
  54. public abstract void resolve(IScope scope);
  55. /**
  56. * Returns a version of this declare element in which all references to type variables are replaced with their bindings given in
  57. * the map.
  58. */
  59. public abstract Declare parameterizeWith(Map<String, UnresolvedType> typeVariableBindingMap, World w);
  60. /**
  61. * Indicates if this declare should be treated like advice. If true, the declare will have no effect in an abstract aspect. It
  62. * will be inherited by any concrete aspects and will have an effect for each concrete aspect it is ultimately inherited by.
  63. */
  64. public abstract boolean isAdviceLike();
  65. /**
  66. * Declares have methods in the .class file against which info can be stored (for example, the annotation in the case of declare
  67. * annotation). The name is of the form ajc$declare_XXX_NNN where XXX can optionally be set in this 'getNameSuffix()' method -
  68. * depending on whether, at weave time, we want to easily differentiate between the declare methods.
  69. */
  70. public abstract String getNameSuffix();
  71. public void setDeclaringType(ResolvedType aType) {
  72. this.declaringType = aType;
  73. }
  74. public ResolvedType getDeclaringType() {
  75. return declaringType;
  76. }
  77. }