public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
    if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) {
      // need assertion flag: $assertionsDisabled on outer most source clas
      // (in case of static member of interface, will use the outermost static member - bug 22334)
      SourceTypeBinding outerMostClass = currentScope.enclosingSourceType();
      while (outerMostClass.isLocalType()) {
        ReferenceBinding enclosing = outerMostClass.enclosingType();
        if (enclosing == null || enclosing.isInterface()) break;
        outerMostClass = (SourceTypeBinding) enclosing;
      }
      this.assertionSyntheticFieldBinding = outerMostClass.addSyntheticFieldForAssert(currentScope);

      // find <clinit> and enable assertion support
      TypeDeclaration typeDeclaration = outerMostClass.scope.referenceType();
      AbstractMethodDeclaration[] methods = typeDeclaration.methods;
      for (int i = 0, max = methods.length; i < max; i++) {
        AbstractMethodDeclaration method = methods[i];
        if (method.isClinit()) {
          ((Clinit) method)
              .setAssertionSupport(
                  this.assertionSyntheticFieldBinding,
                  currentScope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_5);
          break;
        }
      }
    }
  }
示例#2
0
 /**
  * Find all methods which have the requested name.
  *
  * <p>{@code <clinit>} is not supported.
  *
  * @param type JDT type declaration
  * @param name name of methods to find
  * @return list of matching methods
  */
 private static List<AbstractMethodDeclaration> findNamedMethods(
     TypeDeclaration type, String name) {
   List<AbstractMethodDeclaration> matching = new ArrayList<AbstractMethodDeclaration>();
   boolean isCtor = "<init>".equals(name);
   char[] nameArray = name.toCharArray();
   for (AbstractMethodDeclaration method : type.methods) {
     if ((isCtor && method.isConstructor())
         || (!isCtor
             && !method.isConstructor()
             && !method.isClinit()
             && Arrays.equals(method.selector, nameArray))) {
       matching.add(method);
     }
   }
   return matching;
 }
示例#3
0
 public static boolean containsIgnoredBody(AbstractMethodDeclaration method) {
   return !method.isDefaultConstructor()
       && !method.isClinit()
       && (method.modifiers & CompilerModifiers.AccSemicolonBody) == 0;
 }