Package org.eclipse.jdt.internal.compiler.lookup

Examples of org.eclipse.jdt.internal.compiler.lookup.MethodBinding


    switchStatement.expression.sourceEnd);
}
public void missingOverrideAnnotation(AbstractMethodDeclaration method) {
  int severity = computeSeverity(IProblem.MissingOverrideAnnotation);
  if (severity == ProblemSeverities.Ignore) return;
  MethodBinding binding = method.binding;
  this.handle(
    IProblem.MissingOverrideAnnotation,
    new String[] {new String(binding.selector), typesAsString(binding, false), new String(binding.declaringClass.readableName()), },
    new String[] {new String(binding.selector), typesAsString(binding, true), new String(binding.declaringClass.shortReadableName()),},
    severity,
View Full Code Here


    method.sourceEnd);
}
public void missingOverrideAnnotationForInterfaceMethodImplementation(AbstractMethodDeclaration method) {
  int severity = computeSeverity(IProblem.MissingOverrideAnnotationForInterfaceMethodImplementation);
  if (severity == ProblemSeverities.Ignore) return;
  MethodBinding binding = method.binding;
  this.handle(
    IProblem.MissingOverrideAnnotationForInterfaceMethodImplementation,
    new String[] {new String(binding.selector), typesAsString(binding, false), new String(binding.declaringClass.readableName()), },
    new String[] {new String(binding.selector), typesAsString(binding, true), new String(binding.declaringClass.shortReadableName()),},
    severity,
View Full Code Here

    ProblemSeverities.Abort | ProblemSeverities.Error | ProblemSeverities.Fatal,
    typeDeclaration.sourceStart,
    typeDeclaration.sourceEnd);
}
public void tooManyParametersForSyntheticMethod(AbstractMethodDeclaration method) {
  MethodBinding binding = method.binding;
  String selector = null;
  if (binding.isConstructor()) {
    selector = new String(binding.declaringClass.sourceName());
  } else {
    selector = new String(method.selector);
  }
  this.handle(
View Full Code Here

      severity,
      typeDecl.sourceStart,
      typeDecl.sourceEnd);
  } else {
    // type parameter of generic method
    MethodBinding declaringMethod = (MethodBinding) hiddenTypeParameter.declaringElement;
    this.handle(
        IProblem.TypeHidingTypeParameterFromMethod,
        new String[] {
            new String(typeDecl.name),
            new String(hiddenTypeParameter.readableName()),
View Full Code Here

public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {

  int severity = computeSeverity(IProblem.UnusedPrivateConstructor);
  if (severity == ProblemSeverities.Ignore) return;

  MethodBinding constructor = constructorDecl.binding;
  this.handle(
      IProblem.UnusedPrivateConstructor,
    new String[] {
      new String(constructor.declaringClass.readableName()),
      typesAsString(constructor, false)
View Full Code Here

public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {

  int severity = computeSeverity(IProblem.UnusedPrivateMethod);
  if (severity == ProblemSeverities.Ignore) return;

  MethodBinding method = methodDecl.binding;

  // no report for serialization support 'void readObject(ObjectInputStream)'
  if (!method.isStatic()
      && TypeBinding.VOID == method.returnType
      && method.parameters.length == 1
      && method.parameters[0].dimensions() == 0
      && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
      && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, method.parameters[0].readableName())) {
    return;
  }
  // no report for serialization support 'void writeObject(ObjectOutputStream)'
  if (!method.isStatic()
      && TypeBinding.VOID == method.returnType
      && method.parameters.length == 1
      && method.parameters[0].dimensions() == 0
      && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
      && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, method.parameters[0].readableName())) {
    return;
  }
  // no report for serialization support 'Object readResolve()'
  if (!method.isStatic()
      && TypeIds.T_JavaLangObject == method.returnType.id
      && method.parameters.length == 0
      && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
    return;
  }
  // no report for serialization support 'Object writeReplace()'
  if (!method.isStatic()
      && TypeIds.T_JavaLangObject == method.returnType.id
      && method.parameters.length == 0
      && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
    return;
  }
View Full Code Here

public void computeConversion(Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) {
  if (runtimeTimeType == null || compileTimeType == null)
    return;
  // set the generic cast after the fact, once the type expectation is fully known (no need for strict cast)
  if (this.binding != null && this.binding.isValidBinding()) {
    MethodBinding originalBinding = this.binding.original();
    TypeBinding originalType = originalBinding.returnType;
      // extra cast needed if method return type is type variable
    if (originalType.leafComponentType().isTypeVariable()) {
        TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
          ? compileTimeType  // unboxing: checkcast before conversion
View Full Code Here

* @param valueRequired boolean
*/
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
  int pc = codeStream.position;
  // generate receiver/enclosing instance access
  MethodBinding codegenBinding = this.binding instanceof PolymorphicMethodBinding ? this.binding : this.binding.original();
  boolean isStatic = codegenBinding.isStatic();
  if (isStatic) {
    this.receiver.generateCode(currentScope, codeStream, false);
  } else if ((this.bits & ASTNode.DepthMASK) != 0 && this.receiver.isImplicitThis()) { // outer access ?
    // outer method can be reached through emulation if implicit access
    ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
    Object[] path = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
    codeStream.generateOuterAccess(path, this, targetType, currentScope);
  } else {
    this.receiver.generateCode(currentScope, codeStream, true);
    if ((this.bits & NeedReceiverGenericCast) != 0) {
      codeStream.checkcast(this.actualReceiverType);
    }
  }
  codeStream.recordPositionsFrom(pc, this.sourceStart);
  // generate arguments
  generateArguments(this.binding, this.arguments, currentScope, codeStream);
  pc = codeStream.position;
  // actual message invocation
  if (this.syntheticAccessor == null){
    TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenBinding, this.actualReceiverType, this.receiver.isImplicitThis());
    if (isStatic){
      codeStream.invoke(Opcodes.OPC_invokestatic, codegenBinding, constantPoolDeclaringClass);
    } else if((this.receiver.isSuper()) || codegenBinding.isPrivate()){
      codeStream.invoke(Opcodes.OPC_invokespecial, codegenBinding, constantPoolDeclaringClass);
    } else if (constantPoolDeclaringClass.isInterface()) { // interface or annotation type
      codeStream.invoke(Opcodes.OPC_invokeinterface, codegenBinding, constantPoolDeclaringClass);
    } else {
      codeStream.invoke(Opcodes.OPC_invokevirtual, codegenBinding, constantPoolDeclaringClass);
View Full Code Here

public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo){

  if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0return;

  // if method from parameterized type got found, use the original method at codegen time
  MethodBinding codegenBinding = this.binding.original();
  if (this.binding.isPrivate()){

    // depth is set for both implicit and explicit access (see MethodBinding#canBeSeenBy)
    if (currentScope.enclosingSourceType() != codegenBinding.declaringClass){
      this.syntheticAccessor = ((SourceTypeBinding)codegenBinding.declaringClass).addSyntheticMethod(codegenBinding, false /* not super access there */);
 
View Full Code Here

        this.binding =
          this.receiver.isImplicitThis()
            ? scope.getImplicitMethod(this.selector, pseudoArgs, this)
            : scope.findMethod((ReferenceBinding) this.actualReceiverType, this.selector, pseudoArgs, this);
        if (this.binding != null && !this.binding.isValidBinding()) {
          MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
          // record the closest match, for clients who may still need hint about possible method match
          if (closestMatch != null) {
            if (closestMatch.original().typeVariables != Binding.NO_TYPE_VARIABLES) { // generic method
              // shouldn't return generic method outside its context, rather convert it to raw method (175409)
              closestMatch = scope.environment().createParameterizedGenericMethod(closestMatch.original(), (RawTypeBinding)null);
            }
            this.binding = closestMatch;
            MethodBinding closestMatchOriginal = closestMatch.original();
            if (closestMatchOriginal.isOrEnclosedByPrivateType() && !scope.isDefinedInMethod(closestMatchOriginal)) {
              // ignore cases where method is used from within inside itself (e.g. direct recursions)
              closestMatchOriginal.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
            }
          }
        }
      }
      return null;
    }
  }
  if (this.actualReceiverType == null) {
    return null;
  }
  // base type cannot receive any message
  if (this.actualReceiverType.isBaseType()) {
    scope.problemReporter().errorNoMethodFor(this, this.actualReceiverType, argumentTypes);
    return null;
  }
  this.binding = this.receiver.isImplicitThis()
      ? scope.getImplicitMethod(this.selector, argumentTypes, this)
      : scope.getMethod(this.actualReceiverType, this.selector, argumentTypes, this);
  if (!this.binding.isValidBinding()) {
    if (this.binding.declaringClass == null) {
      if (this.actualReceiverType instanceof ReferenceBinding) {
        this.binding.declaringClass = (ReferenceBinding) this.actualReceiverType;
      } else {
        scope.problemReporter().errorNoMethodFor(this, this.actualReceiverType, argumentTypes);
        return null;
      }
    }
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=245007 avoid secondary errors in case of
    // missing super type for anonymous classes ...
    ReferenceBinding declaringClass = this.binding.declaringClass;
    boolean avoidSecondary = declaringClass != null &&
                 declaringClass.isAnonymousType() &&
                 declaringClass.superclass() instanceof MissingTypeBinding;
    if (!avoidSecondary)
      scope.problemReporter().invalidMethod(this, this.binding);
    MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
    switch (this.binding.problemId()) {
      case ProblemReasons.Ambiguous :
        break; // no resilience on ambiguous
      case ProblemReasons.NotVisible :
      case ProblemReasons.NonStaticReferenceInConstructorInvocation :
      case ProblemReasons.NonStaticReferenceInStaticContext :
      case ProblemReasons.ReceiverTypeNotVisible :
      case ProblemReasons.ParameterBoundMismatch :
        // only steal returnType in cases listed above
        if (closestMatch != null) this.resolvedType = closestMatch.returnType;
        break;
    }
    // record the closest match, for clients who may still need hint about possible method match
    if (closestMatch != null) {
      this.binding = closestMatch;
      MethodBinding closestMatchOriginal = closestMatch.original();
      if (closestMatchOriginal.isOrEnclosedByPrivateType() && !scope.isDefinedInMethod(closestMatchOriginal)) {
        // ignore cases where method is used from within inside itself (e.g. direct recursions)
        closestMatchOriginal.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
      }
    }
    return (this.resolvedType != null && (this.resolvedType.tagBits & TagBits.HasMissingType) == 0)
            ? this.resolvedType
            : null;
  }
  final CompilerOptions compilerOptions = scope.compilerOptions();
  if (compilerOptions.complianceLevel <= ClassFileConstants.JDK1_6
      && this.binding.isPolymorphic()) {
    scope.problemReporter().polymorphicMethodNotBelow17(this);
    return null;
  }

  if (((this.bits & ASTNode.InsideExpressionStatement) != 0)
      && this.binding.isPolymorphic()) {
    // we only set the return type to be void if this method invocation is used inside an expression statement
    this.binding = scope.environment().updatePolymorphicMethodReturnType((PolymorphicMethodBinding) this.binding, TypeBinding.VOID);
  }
  if ((this.binding.tagBits & TagBits.HasMissingType) != 0) {
    scope.problemReporter().missingTypeInMethod(this, this.binding);
  }
  if (!this.binding.isStatic()) {
    // the "receiver" must not be a type
    if (receiverIsType) {
      scope.problemReporter().mustUseAStaticMethod(this, this.binding);
      if (this.actualReceiverType.isRawType()
          && (this.receiver.bits & ASTNode.IgnoreRawTypeCheck) == 0
          && compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) {
        scope.problemReporter().rawTypeReference(this.receiver, this.actualReceiverType);
      }
    } else {
      // handle indirect inheritance thru variable secondary bound
      // receiver may receive generic cast, as part of implicit conversion
      TypeBinding oldReceiverType = this.actualReceiverType;
      this.actualReceiverType = this.actualReceiverType.getErasureCompatibleType(this.binding.declaringClass);
      this.receiver.computeConversion(scope, this.actualReceiverType, this.actualReceiverType);
      if (this.actualReceiverType != oldReceiverType && this.receiver.postConversionType(scope) != this.actualReceiverType) { // record need for explicit cast at codegen since receiver could not handle it
        this.bits |= NeedReceiverGenericCast;
      }
    }
  } else {
    // static message invoked through receiver? legal but unoptimal (optional warning).
    if (!(this.receiver.isImplicitThis() || this.receiver.isSuper() || receiverIsType)) {
      scope.problemReporter().nonStaticAccessToStaticMethod(this, this.binding);
    }
    if (!this.receiver.isImplicitThis() && this.binding.declaringClass != this.actualReceiverType) {
      scope.problemReporter().indirectAccessToStaticMethod(this, this.binding);
    }
  }
  if (checkInvocationArguments(scope, this.receiver, this.actualReceiverType, this.binding, this.arguments, argumentTypes, argsContainCast, this)) {
    this.bits |= ASTNode.Unchecked;
  }

  //-------message send that are known to fail at compile time-----------
  if (this.binding.isAbstract()) {
    if (this.receiver.isSuper()) {
      scope.problemReporter().cannotDireclyInvokeAbstractMethod(this, this.binding);
    }
    // abstract private methods cannot occur nor abstract static............
  }
  if (isMethodUseDeprecated(this.binding, scope, true))
    scope.problemReporter().deprecatedMethod(this.binding, this);

  // from 1.5 source level on, array#clone() returns the array type (but binding still shows Object)
  if (this.binding == scope.environment().arrayClone && compilerOptions.sourceLevel >= ClassFileConstants.JDK1_5) {
    this.resolvedType = this.actualReceiverType;
  } else {
    TypeBinding returnType;
    if ((this.bits & ASTNode.Unchecked) != 0 && this.genericTypeArguments == null) {
      // https://bugs.eclipse.org/bugs/show_bug.cgi?id=277643, align with javac on JLS 15.12.2.6
      returnType = this.binding.returnType;
      if (returnType != null) {
        returnType = scope.environment().convertToRawType(returnType.erasure(), true);
      }
    } else {
      returnType = this.binding.returnType;
      if (returnType != null) {
        returnType = returnType.capture(scope, this.sourceEnd);
      }
    }
    this.resolvedType = returnType;
  }
  if (this.receiver.isSuper() && compilerOptions.getSeverity(CompilerOptions.OverridingMethodWithoutSuperInvocation) != ProblemSeverities.Ignore) {
    final ReferenceContext referenceContext = scope.methodScope().referenceContext;
    if (referenceContext instanceof AbstractMethodDeclaration) {
      final AbstractMethodDeclaration abstractMethodDeclaration = (AbstractMethodDeclaration) referenceContext;
      MethodBinding enclosingMethodBinding = abstractMethodDeclaration.binding;
      if (enclosingMethodBinding.isOverriding()
          && CharOperation.equals(this.binding.selector, enclosingMethodBinding.selector)
          && this.binding.areParametersEqual(enclosingMethodBinding)) {
        abstractMethodDeclaration.bits |= ASTNode.OverridingMethodWithSupercall;
      }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.lookup.MethodBinding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.