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.

ExposedState.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.util.Arrays;
  14. import org.aspectj.weaver.Member;
  15. import org.aspectj.weaver.ResolvedType;
  16. import org.aspectj.weaver.UnresolvedType;
  17. import org.aspectj.weaver.ast.Expr;
  18. import org.aspectj.weaver.ast.Var;
  19. public class ExposedState {
  20. public static final boolean[] NO_ERRONEOUS_VARS = new boolean[0];
  21. public Var[] vars;
  22. private boolean[] erroneousVars;
  23. private Expr aspectInstance;
  24. private UnresolvedType[] expectedVarTypes; // enables us to check that binding is occurring with the *right* types
  25. private ResolvedType concreteAspect;
  26. public ExposedState(int size) {
  27. super();
  28. if (size == 0) {
  29. vars = Var.NONE;
  30. erroneousVars = NO_ERRONEOUS_VARS;
  31. } else {
  32. vars = new Var[size];
  33. erroneousVars = new boolean[size];
  34. }
  35. }
  36. public ExposedState(Member signature) {
  37. // XXX there maybe something about target for non-static sigs
  38. this(signature.getParameterTypes().length);
  39. expectedVarTypes = new UnresolvedType[signature.getParameterTypes().length];
  40. if (expectedVarTypes.length > 0) {
  41. for (int i = 0; i < signature.getParameterTypes().length; i++) {
  42. expectedVarTypes[i] = signature.getParameterTypes()[i];
  43. }
  44. }
  45. }
  46. public boolean isFullySetUp() {
  47. for (Var var : vars) {
  48. if (var == null)
  49. return false;
  50. }
  51. return true;
  52. }
  53. public void set(int i, Var var) {
  54. // check the type is OK if we can... these are the same rules as in matchesInstanceOf() processing
  55. if (expectedVarTypes != null) {
  56. ResolvedType expected = expectedVarTypes[i].resolve(var.getType().getWorld());
  57. if (!expected.equals(ResolvedType.OBJECT)) {
  58. if (!expected.isAssignableFrom(var.getType())) {
  59. if (!var.getType().isCoerceableFrom(expected)) {
  60. // throw new
  61. // BCException("Expected type "+expectedVarTypes[i]+" in slot "+i+" but attempt to put "+var.getType()+" into it");
  62. return;
  63. }
  64. }
  65. }
  66. }
  67. vars[i] = var;
  68. }
  69. public Var get(int i) {
  70. return vars[i];
  71. }
  72. public int size() {
  73. return vars.length;
  74. }
  75. public Expr getAspectInstance() {
  76. return aspectInstance;
  77. }
  78. public void setAspectInstance(Expr aspectInstance) {
  79. this.aspectInstance = aspectInstance;
  80. }
  81. public String toString() {
  82. return "ExposedState(#Vars=" + vars.length + ",Vars=" + Arrays.asList(vars) + ",AspectInstance=" + aspectInstance + ")";
  83. }
  84. // Set to true if we have reported an error message against it,
  85. // prevents us blowing up in later code gen.
  86. public void setErroneousVar(int formalIndex) {
  87. erroneousVars[formalIndex] = true;
  88. }
  89. public boolean isErroneousVar(int formalIndex) {
  90. return erroneousVars[formalIndex];
  91. }
  92. public void setConcreteAspect(ResolvedType concreteAspect) {
  93. this.concreteAspect = concreteAspect;
  94. }
  95. public ResolvedType getConcreteAspect() {
  96. return this.concreteAspect;
  97. }
  98. }