private TypeBinding getTypeFromSignature(String typeSignature, Scope scope) {
    TypeBinding assignableTypeBinding = null;

    TypeVariableBinding[] typeVariables = Binding.NO_TYPE_VARIABLES;
    ReferenceContext referenceContext = scope.referenceContext();
    if (referenceContext instanceof AbstractMethodDeclaration) {
      AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
      TypeParameter[] typeParameters = methodDeclaration.typeParameters();
      if (typeParameters != null && typeParameters.length > 0) {
        int length = typeParameters.length;
        int count = 0;
        typeVariables = new TypeVariableBinding[length];
        for (int i = 0; i < length; i++) {
          if (typeParameters[i].binding != null) {
            typeVariables[count++] = typeParameters[i].binding;
          }
        }

        if (count != length) {
          System.arraycopy(
              typeVariables, 0, typeVariables = new TypeVariableBinding[count], 0, count);
        }
      }
    }

    CompilationUnitDeclaration previousUnitBeingCompleted =
        this.lookupEnvironment.unitBeingCompleted;
    this.lookupEnvironment.unitBeingCompleted = this.compilationUnitDeclaration;
    // {ObjectTeams: protect call into the compiler
    /* orig:
    try {
    :giro */
    try (Config config =
        Dependencies.setup(this, this.parser, this.lookupEnvironment, true, true)) {
      // orig:

      SignatureWrapper wrapper =
          new SignatureWrapper(replacePackagesDot(typeSignature.toCharArray()));
      // FIXME(stephan): do we interpret type annotations here?
      assignableTypeBinding =
          this.lookupEnvironment.getTypeFromTypeSignature(
              wrapper,
              typeVariables,
              this.assistScope.enclosingClassScope().referenceContext.binding,
              null,
              ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER);
      assignableTypeBinding =
          BinaryTypeBinding.resolveType(assignableTypeBinding, this.lookupEnvironment, true);
    } catch (AbortCompilation e) {
      assignableTypeBinding = null;
    } finally {
      this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
    }
    return assignableTypeBinding;
  }
Exemplo n.º 2
0
 protected void reportInvalidType(Scope scope) {
   // {ObjectTeams: suppress this in role feature bridge (the same will be reported against the
   // original, too):
   if (scope.isFakeMethod(FakeKind.ROLE_FEATURE_BRIDGE)) {
     scope.referenceContext().tagAsHavingErrors();
     return;
   }
   // did we misread an OT keyword as a type reference (during syntax recovery)?
   if (!scope.environment().globalOptions.isPureJava) {
     char[] token = getLastToken();
     for (int j = 0; j < IOTConstants.OT_KEYWORDS.length; j++) {
       if (CharOperation.equals(token, IOTConstants.OT_KEYWORDS[j])) {
         if (scope.referenceContext().compilationResult().hasErrors())
           return; // assume this is a secondary error
       }
     }
   }
   // SH}
   scope.problemReporter().invalidType(this, this.resolvedType);
 }
Exemplo n.º 3
0
 protected TypeBinding internalResolveType(Scope scope, int location) {
   // handle the error here
   this.constant = Constant.NotAConstant;
   if (this.resolvedType != null) { // is a shared type reference which was already resolved
     if (this.resolvedType.isValidBinding()) {
       return this.resolvedType;
     } else {
       switch (this.resolvedType.problemId()) {
         case ProblemReasons.NotFound:
         case ProblemReasons.NotVisible:
         case ProblemReasons.InheritedNameHidesEnclosingName:
           TypeBinding type = this.resolvedType.closestMatch();
           if (type == null) return null;
           return scope
               .environment()
               .convertToRawType(type, false /*do not force conversion of enclosing types*/);
         default:
           return null;
       }
     }
   }
   boolean hasError;
   // {ObjectTeams: don't let SelectionNodeFound(null) prevent alternate searching strategies:
   SelectionNodeFound caughtException = null;
   TypeBinding type = null;
   try {
     // base import scope first:
     CompilationResult compilationResult = scope.referenceCompilationUnit().compilationResult();
     CompilationResult.CheckPoint cp = compilationResult.getCheckPoint(scope.referenceContext());
     try {
       type =
           checkResolveUsingBaseImportScope(
               scope, location, false); // apply TOLERATE strategy only as a last resort below
       // copied from below:
       if (type != null && type.isValidBinding()) {
         type =
             scope
                 .environment()
                 .convertToRawType(type, false /*do not force conversion of enclosing types*/);
         if (type.leafComponentType().isRawType()
             && (this.bits & ASTNode.IgnoreRawTypeCheck) == 0
             && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference)
                 != ProblemSeverities.Ignore) {
           scope.problemReporter().rawTypeReference(this, type);
         }
         return type;
       }
     } catch (SelectionNodeFound snf) {
       if (snf.binding != null) throw snf; // found a valid node.
       caughtException = snf;
     } finally {
       if (caughtException != null || (type == null) || !type.isValidBinding())
         compilationResult.rollBack(cp);
     }
     // ~orig~:
     type = this.resolvedType = getTypeBinding(scope);
     if (type == null) {
       return null; // detected cycle while resolving hierarchy
     }
     // :~giro~
   } catch (SelectionNodeFound snf) {
     if (snf.binding != null) throw snf; // found a valid node.
     caughtException = snf;
   }
   // a third chance trying an anchored type:
   try {
     if ((caughtException != null) || (this.resolvedType.problemId() == ProblemReasons.NotFound)) {
       // anchored type
       TypeBinding result = resolveAnchoredType(scope);
       if (result != null) // did we do any better than before?
       type = this.resolvedType = result; // if non-null but ProblemBinding report below.
     }
   } catch (SelectionNodeFound snf2) {
     caughtException = snf2; // throw the newer exception instead.
   }
   // a forth chance trying a TOLERATED base imported type:
   try {
     if ((caughtException != null) || (this.resolvedType.problemId() == ProblemReasons.NotFound)) {
       if (this.baseclassDecapsulation == DecapsulationState.TOLERATED) {
         TypeBinding result = checkResolveUsingBaseImportScope(scope, -1, true);
         if (result != null) // did we do any better than before?
         type = this.resolvedType = result; // if non-null but ProblemBinding report below.
       }
     }
   } catch (SelectionNodeFound snf2) {
     caughtException = snf2; // throw the newer exception instead.
   } finally {
     // the attempt to prevent an exception failed:
     if (caughtException != null) throw caughtException;
   }
   // SH}
   if ((hasError = !type.isValidBinding()) == true) {
     reportInvalidType(scope);
     switch (type.problemId()) {
       case ProblemReasons.NotFound:
       case ProblemReasons.NotVisible:
       case ProblemReasons.InheritedNameHidesEnclosingName:
         type = type.closestMatch();
         if (type == null) return null;
         break;
       default:
         return null;
     }
   }
   // {ObjectTeams: Split method to make tail accessible:
   return checkResolvedType(type, scope, location, hasError);
 }
  private void computeVisibleElementBindings() {
    CompilationUnitDeclaration previousUnitBeingCompleted =
        this.lookupEnvironment.unitBeingCompleted;
    this.lookupEnvironment.unitBeingCompleted = this.compilationUnitDeclaration;
    try {
      this.hasComputedVisibleElementBindings = true;

      Scope scope = this.assistScope;
      ASTNode astNode = this.assistNode;
      boolean notInJavadoc = this.completionContext.javadoc == 0;

      this.visibleLocalVariables = new ObjectVector();
      this.visibleFields = new ObjectVector();
      this.visibleMethods = new ObjectVector();

      ReferenceContext referenceContext = scope.referenceContext();
      if (referenceContext instanceof AbstractMethodDeclaration
          || referenceContext instanceof LambdaExpression) {
        // completion is inside a method body
        searchVisibleVariablesAndMethods(
            scope,
            this.visibleLocalVariables,
            this.visibleFields,
            this.visibleMethods,
            notInJavadoc);
      } else if (referenceContext instanceof TypeDeclaration) {
        TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
        FieldDeclaration[] fields = typeDeclaration.fields;
        if (fields != null) {
          done:
          for (int i = 0; i < fields.length; i++) {
            if (fields[i] instanceof Initializer) {
              Initializer initializer = (Initializer) fields[i];
              if (initializer.block.sourceStart <= astNode.sourceStart
                  && astNode.sourceStart < initializer.bodyEnd) {
                // completion is inside an initializer
                searchVisibleVariablesAndMethods(
                    scope,
                    this.visibleLocalVariables,
                    this.visibleFields,
                    this.visibleMethods,
                    notInJavadoc);
                break done;
              }
            } else {
              FieldDeclaration fieldDeclaration = fields[i];
              if (fieldDeclaration.initialization != null && fieldDeclaration.binding != null) {
                boolean isInsideInitializer = false;
                if (fieldDeclaration.initialization.sourceEnd > 0) {
                  if (fieldDeclaration.initialization.sourceStart <= astNode.sourceStart
                      && astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) {
                    // completion is inside a field initializer
                    isInsideInitializer = true;
                  }
                } else { // The sourceEnd may not yet be set
                  CompletionNodeDetector detector =
                      new CompletionNodeDetector(this.assistNode, fieldDeclaration.initialization);
                  if (detector.containsCompletionNode()) {
                    // completion is inside a field initializer
                    isInsideInitializer = true;
                  }
                }
                if (isInsideInitializer) {
                  searchVisibleVariablesAndMethods(
                      scope,
                      this.visibleLocalVariables,
                      this.visibleFields,
                      this.visibleMethods,
                      notInJavadoc);
                  // remove this field from visibleFields list because completion is being asked in
                  // its
                  // intialization and so this has not yet been declared successfully.
                  if (this.visibleFields.size > 0
                      && this.visibleFields.contains(fieldDeclaration.binding)) {
                    this.visibleFields.remove(fieldDeclaration.binding);
                  }
                  int count = 0;
                  while (count < this.visibleFields.size) {
                    FieldBinding visibleField = (FieldBinding) this.visibleFields.elementAt(count);
                    if (visibleField.id > fieldDeclaration.binding.id) {
                      this.visibleFields.remove(visibleField);
                      continue;
                    }
                    count++;
                  }
                  break done;
                }
              }
            }
          }
        }
      }
    } finally {
      this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
    }
  }