コード例 #1
0
  public void resolveReceiver() {
    if (this.receiver == null) return;

    if (this.receiver.modifiers != 0) {
      this.scope
          .problemReporter()
          .illegalModifiers(
              this.receiver.declarationSourceStart, this.receiver.declarationSourceEnd);
    }

    TypeBinding resolvedReceiverType = this.receiver.type.resolvedType;
    if (this.binding == null
        || resolvedReceiverType == null
        || !resolvedReceiverType.isValidBinding()) {
      return;
    }

    ReferenceBinding declaringClass = this.binding.declaringClass;
    /* neither static methods nor methods in anonymous types can have explicit 'this' */
    if (this.isStatic() || declaringClass.isAnonymousType()) {
      this.scope.problemReporter().disallowedThisParameter(this.receiver);
      return; // No need to do further validation
    }

    ReferenceBinding enclosingReceiver = this.scope.enclosingReceiverType();
    if (this.isConstructor()) {
      /* Only non static member types or local types can declare explicit 'this' params in constructors */
      if (declaringClass.isStatic()
          || (declaringClass.tagBits & (TagBits.IsLocalType | TagBits.IsMemberType)) == 0) {
          /* neither member nor local type */
        this.scope.problemReporter().disallowedThisParameter(this.receiver);
        return; // No need to do further validation
      }
      enclosingReceiver = enclosingReceiver.enclosingType();
    }

    char[][] tokens =
        (this.receiver.qualifyingName == null) ? null : this.receiver.qualifyingName.getName();
    if (this.isConstructor()) {
      if (tokens == null
          || tokens.length > 1
          || !CharOperation.equals(enclosingReceiver.sourceName(), tokens[0])) {
        this.scope
            .problemReporter()
            .illegalQualifierForExplicitThis(this.receiver, enclosingReceiver);
        this.receiver.qualifyingName = null;
      }
    } else if (tokens != null && tokens.length > 0) {
      this.scope.problemReporter().illegalQualifierForExplicitThis2(this.receiver);
      this.receiver.qualifyingName = null;
    }

    if (TypeBinding.notEquals(enclosingReceiver, resolvedReceiverType)) {
      this.scope.problemReporter().illegalTypeForExplicitThis(this.receiver, enclosingReceiver);
    }

    if (this.receiver.type.hasNullTypeAnnotation(AnnotationPosition.ANY)) {
      this.scope.problemReporter().nullAnnotationUnsupportedLocation(this.receiver.type);
    }
  }
コード例 #2
0
  /** Record the thrown exception type bindings in the corresponding type references. */
  public void bindThrownExceptions() {

    if (this.thrownExceptions != null
        && this.binding != null
        && this.binding.thrownExceptions != null) {
      int thrownExceptionLength = this.thrownExceptions.length;
      int length = this.binding.thrownExceptions.length;
      if (length == thrownExceptionLength) {
        for (int i = 0; i < length; i++) {
          this.thrownExceptions[i].resolvedType = this.binding.thrownExceptions[i];
        }
      } else {
        int bindingIndex = 0;
        for (int i = 0; i < thrownExceptionLength && bindingIndex < length; i++) {
          TypeReference thrownException = this.thrownExceptions[i];
          ReferenceBinding thrownExceptionBinding = this.binding.thrownExceptions[bindingIndex];
          char[][] bindingCompoundName = thrownExceptionBinding.compoundName;
          if (bindingCompoundName == null) continue; // skip problem case
          if (thrownException instanceof SingleTypeReference) {
            // single type reference
            int lengthName = bindingCompoundName.length;
            char[] thrownExceptionTypeName = thrownException.getTypeName()[0];
            if (CharOperation.equals(
                thrownExceptionTypeName, bindingCompoundName[lengthName - 1])) {
              thrownException.resolvedType = thrownExceptionBinding;
              bindingIndex++;
            }
          } else {
            // qualified type reference
            if (CharOperation.equals(thrownException.getTypeName(), bindingCompoundName)) {
              thrownException.resolvedType = thrownExceptionBinding;
              bindingIndex++;
            }
          }
        }
      }
    }
  }
コード例 #3
0
 protected void consumeClassInstanceCreationExpressionWithTypeArguments() {
   boolean previousFlag = this.reportReferenceInfo;
   this.reportReferenceInfo =
       false; // not to see the type reference reported in super call to getTypeReference(...)
   super.consumeClassInstanceCreationExpressionWithTypeArguments();
   this.reportReferenceInfo = previousFlag;
   if (this.reportReferenceInfo) {
     AllocationExpression alloc = (AllocationExpression) this.expressionStack[this.expressionPtr];
     TypeReference typeRef = alloc.type;
     this.requestor.acceptConstructorReference(
         typeRef instanceof SingleTypeReference
             ? ((SingleTypeReference) typeRef).token
             : CharOperation.concatWith(alloc.type.getParameterizedTypeName(), '.'),
         alloc.arguments == null ? 0 : alloc.arguments.length,
         alloc.sourceStart);
   }
 }