public boolean isEquivalent(Reference reference) {
   // only consider field references relative to "this":
   if (this.receiver.isThis() && !(this.receiver instanceof QualifiedThisReference)) {
     // current is a simple "this.f1"
     char[] otherToken = null;
     // matching 'reference' could be "f1" or "this.f1":
     if (reference instanceof SingleNameReference) {
       otherToken = ((SingleNameReference) reference).token;
     } else if (reference instanceof FieldReference) {
       FieldReference fr = (FieldReference) reference;
       if (fr.receiver.isThis() && !(fr.receiver instanceof QualifiedThisReference)) {
         otherToken = fr.token;
       }
     }
     return otherToken != null && CharOperation.equals(this.token, otherToken);
   } else {
     // search deeper for "this" inside:
     char[][] thisTokens = getThisFieldTokens(1);
     if (thisTokens == null) {
       return false;
     }
     // other can be "this.f1.f2", too, or "f1.f2":
     char[][] otherTokens = null;
     if (reference instanceof FieldReference) {
       otherTokens = ((FieldReference) reference).getThisFieldTokens(1);
     } else if (reference instanceof QualifiedNameReference) {
       if (((QualifiedNameReference) reference).binding instanceof LocalVariableBinding)
         return false; // initial variable mismatch: local (from f1.f2) vs. field (from this.f1.f2)
       otherTokens = ((QualifiedNameReference) reference).tokens;
     }
     return CharOperation.equals(thisTokens, otherTokens);
   }
 }
 boolean isDangerousMethod(MethodBinding method) {
   if (CharOperation.equals(method.selector, "hashCode".toCharArray())) // $NON-NLS-1$
   return method.parameters == Binding.NO_PARAMETERS;
   if (CharOperation.equals(method.selector, "equals".toCharArray())) // $NON-NLS-1$
   return (method.parameters.length == 1) && (method.parameters[0].id == TypeIds.T_JavaLangObject);
   return false;
 }
 private static boolean parameterValuesEquals(int flags, Object newValue, Object existingValue) {
   if (newValue.getClass().isArray() && existingValue.getClass().isArray()) {
     Object[] newValueArray = (Object[]) newValue;
     Object[] existingValueArray = (Object[]) existingValue;
     if (newValueArray.length != existingValueArray.length) {
       return false;
     }
     for (int i = 0; i < newValueArray.length; i++) {
       if (!parameterValuesEquals(flags, newValueArray[i], existingValueArray[i])) {
         return false;
       }
     }
   } else if (newValue instanceof ClassSignature) {
     if (existingValue instanceof ClassSignature) {
       if (!CharOperation.equals(
           ((ClassSignature) newValue).getTypeName(),
           ((ClassSignature) existingValue).getTypeName())) {
         return false;
       }
     } else {
       return false;
     }
   } else if (newValue instanceof Constant) {
     if (existingValue instanceof Constant) {
       if (!((Constant) newValue).hasSameValue((Constant) existingValue)) {
         return false;
       }
     } else {
       return false;
     }
   } else if (newValue instanceof EnumConstantSignature) {
     if (existingValue instanceof EnumConstantSignature) {
       if (!(CharOperation.equals(
               ((EnumConstantSignature) newValue).getTypeName(),
               ((EnumConstantSignature) existingValue).getTypeName())
           && CharOperation.equals(
               ((EnumConstantSignature) newValue).getEnumConstantName(),
               ((EnumConstantSignature) existingValue).getEnumConstantName()))) {
         return false;
       }
     } else {
       return false;
     }
   } else if (newValue instanceof IBinaryAnnotation) {
     if (existingValue instanceof EnumConstantSignature) {
       if (!annotationsEqual(
           new IBinaryAnnotation[] {(IBinaryAnnotation) newValue},
           new IBinaryAnnotation[] {(IBinaryAnnotation) existingValue},
           flags)) {
         return false;
       }
     } else {
       return false;
     }
   }
   return true;
 }
  private static boolean annotationsEqual(
      IBinaryAnnotation[] existingAnnotations, IBinaryAnnotation[] newAnnotations, int flags) {
    if (existingAnnotations == null) {
      existingAnnotations = TypeStructure.NoAnnotation;
    }
    if (newAnnotations == null) {
      newAnnotations = TypeStructure.NoAnnotation;
    }
    if (existingAnnotations.length != newAnnotations.length) {
      return false;
    }

    new_annotation_loop:
    for (int i = 0; i < newAnnotations.length; i++) {
      for (int j = 0; j < existingAnnotations.length; j++) {
        if (CharOperation.equals(
            newAnnotations[j].getTypeName(), existingAnnotations[i].getTypeName())) {
          // compare annotation parameters
          if ((flags & FLAG_ANNOTATION_VALUE) != 0) {
            IBinaryElementValuePair[] newParameters = newAnnotations[j].getElementValuePairs();
            IBinaryElementValuePair[] existingParameters =
                existingAnnotations[j].getElementValuePairs();
            if (newParameters == null) {
              newParameters = TypeStructure.NoElement;
            }
            if (existingParameters == null) {
              existingParameters = TypeStructure.NoElement;
            }
            if (existingParameters.length != newParameters.length) {
              return false;
            }
            for (int k = 0; k < newParameters.length; k++) {
              for (int l = 0; l < existingParameters.length; l++) {
                char[] newName = newParameters[l].getName();
                char[] existingName = existingParameters[l].getName();
                Object newValue = newParameters[l].getValue();
                Object existingValue = existingParameters[l].getValue();

                if (!CharOperation.equals(newName, existingName)) {
                  return false;
                }

                if (!parameterValuesEquals(flags, newValue, existingValue)) {
                  return false;
                }
              }
            }
          }
          continue new_annotation_loop;
        }
      }
      return false;
    }
    return true;
  }
 public boolean equals(Object obj) {
   if (!(obj instanceof HashableWeakReference)) return false;
   char[] referent = (char[]) get();
   char[] other = (char[]) ((HashableWeakReference) obj).get();
   if (referent == null) return other == null;
   return CharOperation.equals(referent, other);
 }
  /*
   * lookup through continue labels
   */
  public FlowContext getTargetContextForContinueLabel(char[] labelName) {
    FlowContext current = this;
    FlowContext lastContinuable = null;
    FlowContext lastNonReturningSubRoutine = null;

    while (current != null) {
      if (current.isNonReturningContext()) {
        lastNonReturningSubRoutine = current;
      } else {
        if (current.isContinuable()) {
          lastContinuable = current;
        }
      }

      char[] currentLabelName;
      if ((currentLabelName = current.labelName()) != null
          && CharOperation.equals(currentLabelName, labelName)) {
        ((LabeledStatement) current.associatedNode).bits |= ASTNode.LabelUsed;

        // matching label found
        if ((lastContinuable != null)
            && (current.associatedNode.concreteStatement() == lastContinuable.associatedNode)) {

          if (lastNonReturningSubRoutine == null) return lastContinuable;
          return lastNonReturningSubRoutine;
        }
        // label is found, but not a continuable location
        return FlowContext.NotContinuableContext;
      }
      current = current.getLocalParent();
    }
    // not found
    return null;
  }
 static boolean isEqual(VariableBinding variableBinding, VariableBinding variableBinding2) {
   return (variableBinding.modifiers & ExtraCompilerModifiers.AccJustFlag)
           == (variableBinding2.modifiers & ExtraCompilerModifiers.AccJustFlag)
       && CharOperation.equals(variableBinding.name, variableBinding2.name)
       && isEqual(variableBinding.type, variableBinding2.type)
       && (variableBinding.id == variableBinding2.id);
 }
  protected void finishedWith(
      String sourceLocator,
      CompilationResult result,
      char[] mainTypeName,
      ArrayList definedTypeNames,
      ArrayList duplicateTypeNames) {
    char[][] previousTypeNames = this.newState.getDefinedTypeNamesFor(sourceLocator);
    if (previousTypeNames == null) previousTypeNames = new char[][] {mainTypeName};
    IPath packagePath = null;
    next:
    for (int i = 0, l = previousTypeNames.length; i < l; i++) {
      char[] previous = previousTypeNames[i];
      for (int j = 0, m = definedTypeNames.size(); j < m; j++)
        if (CharOperation.equals(previous, (char[]) definedTypeNames.get(j))) continue next;

      SourceFile sourceFile = (SourceFile) result.getCompilationUnit();
      if (packagePath == null) {
        int count = sourceFile.sourceLocation.sourceFolder.getFullPath().segmentCount();
        packagePath =
            sourceFile.resource.getFullPath().removeFirstSegments(count).removeLastSegments(1);
      }
      if (this.secondaryTypesToRemove == null)
        this.secondaryTypesToRemove = new SimpleLookupTable();
      ArrayList types =
          (ArrayList) this.secondaryTypesToRemove.get(sourceFile.sourceLocation.binaryFolder);
      if (types == null) types = new ArrayList(definedTypeNames.size());
      types.add(packagePath.append(new String(previous)));
      this.secondaryTypesToRemove.put(sourceFile.sourceLocation.binaryFolder, types);
    }
    super.finishedWith(sourceLocator, result, mainTypeName, definedTypeNames, duplicateTypeNames);
  }
  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);
    }
  }
 /** Check OTJLD 4.4(b) "Callin parameter mapping / Restrictions for callin replace bindings" */
 public void checkResultMapping() {
   // for replace callins, a "result" mapping is not allowed,
   // unless an expected result is otherwise missing.
   if (this.mappings == null) return;
   for (MethodSpec baseSpec : this.baseMethodSpecs) {
     for (int i = 0; i < this.mappings.length; i++) {
       if (CharOperation.equals(this.mappings[i].ident.token, IOTConstants.RESULT)) {
         this.isResultMapped = true;
         // OTJLD 4.4(b): "If the base method declares a result, then ...
         if (baseSpec.resolvedType() != TypeBinding.VOID) {
           //                * if the role method also declares a result,
           if (this.roleMethodSpec.resolvedType() != TypeBinding.VOID) {
             Expression resultExpr = this.mappings[i].expression;
             //                  => result must be mapped to itself
             if (!(resultExpr instanceof ResultReference)) {
               this.scope.problemReporter().nonResultExpressionInReplaceResult(resultExpr);
               this.binding.tagBits |= TagBits.HasMappingIncompatibility;
             }
           } // no else because:
           //                * if the role method does not declare a result,
           //                  an arbitrary expression may be mapped to result
         } else {
           this.scope
               .problemReporter()
               .resultMappingForVoidMethod(this, baseSpec, this.mappings[i]);
           this.binding.tagBits |= TagBits.HasMappingIncompatibility;
         }
       }
     }
   }
 }
 static boolean isEqual(FieldBinding fieldBinding, FieldBinding fieldBinding2) {
   HashSet visitedTypes = new HashSet();
   return (fieldBinding.modifiers & ExtraCompilerModifiers.AccJustFlag)
           == (fieldBinding2.modifiers & ExtraCompilerModifiers.AccJustFlag)
       && CharOperation.equals(fieldBinding.name, fieldBinding2.name)
       && isEqual(fieldBinding.type, fieldBinding2.type, visitedTypes)
       && isEqual(fieldBinding.declaringClass, fieldBinding2.declaringClass, visitedTypes);
 }
 boolean areTypesEqual(TypeBinding one, TypeBinding two) {
   if (one == two) return true;
   if (one instanceof ReferenceBinding && two instanceof ReferenceBinding)
     // can compare unresolved to resolved reference bindings
     return CharOperation.equals(
         ((ReferenceBinding) one).compoundName, ((ReferenceBinding) two).compoundName);
   return false; // all other type bindings are identical
 }
 public boolean equals(Object obj) {
   if (obj instanceof VerificationTypeInfo) {
     VerificationTypeInfo info1 = (VerificationTypeInfo) obj;
     return info1.tag == this.tag
         && CharOperation.equals(info1.constantPoolName(), this.constantPoolName());
   }
   return false;
 }
Beispiel #14
0
 /**
  * Read through this annotation in order to figure out the necessary tag
  * bits and the length of this annotation. The data structure will not be
  * flushed out.
  *
  * The tag bits are derived from the following (supported) standard
  * annotation. java.lang.annotation.Documented,
  * java.lang.annotation.Retention, java.lang.annotation.Target, and
  * java.lang.Deprecated
  *
  * @param expectRuntimeVisibleAnno
  *            <code>true</cod> to indicate that this is a runtime-visible annotation
  * @param toplevel <code>false</code> to indicate that an nested annotation is read.
  * 		<code>true</code> otherwise
  * @return the next offset to read.
  */
 private int scanAnnotation(int offset, boolean expectRuntimeVisibleAnno, boolean toplevel) {
   int currentOffset = offset;
   int utf8Offset = this.constantPoolOffsets[u2At(offset)] - this.structOffset;
   char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
   if (toplevel) this.typename = typeName;
   int numberOfPairs = u2At(offset + 2);
   // u2 type_index + u2 number_member_value_pair
   currentOffset += 4;
   if (expectRuntimeVisibleAnno && toplevel) {
     switch (typeName.length) {
       case 22:
         if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_DEPRECATED)) {
           this.standardAnnotationTagBits |= TagBits.AnnotationDeprecated;
           return currentOffset;
         }
         break;
       case 23:
         if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_SAFEVARARGS)) {
           this.standardAnnotationTagBits |= TagBits.AnnotationSafeVarargs;
           return currentOffset;
         }
         break;
       case 29:
         if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_TARGET)) {
           currentOffset += 2;
           return readTargetValue(currentOffset);
         }
         break;
       case 32:
         if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTION)) {
           currentOffset += 2;
           return readRetentionPolicy(currentOffset);
         }
         if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_INHERITED)) {
           this.standardAnnotationTagBits |= TagBits.AnnotationInherited;
           return currentOffset;
         }
         break;
       case 33:
         if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_DOCUMENTED)) {
           this.standardAnnotationTagBits |= TagBits.AnnotationDocumented;
           return currentOffset;
         }
         break;
       case 52:
         if (CharOperation.equals(
             typeName, ConstantPool.JAVA_LANG_INVOKE_METHODHANDLE_POLYMORPHICSIGNATURE)) {
           this.standardAnnotationTagBits |= TagBits.AnnotationPolymorphicSignature;
           return currentOffset;
         }
         break;
     }
   }
   for (int i = 0; i < numberOfPairs; i++) {
     // u2 member_name_index
     currentOffset += 2;
     currentOffset = scanElementValue(currentOffset);
   }
   return currentOffset;
 }
 /**
  * @param declaringElement
  * @param declaringElement2
  * @return true if both parameters are equals, false otherwise
  */
 static boolean isEqual(
     Binding declaringElement, Binding declaringElement2, HashSet visitedTypes) {
   if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
     if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding)) {
       return false;
     }
     return isEqual(
         (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement,
         (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement2,
         visitedTypes);
   } else if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) {
     if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding)) {
       return false;
     }
     return isEqual(
         (org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement,
         (org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement2,
         visitedTypes);
   } else if (declaringElement instanceof VariableBinding) {
     if (!(declaringElement2 instanceof VariableBinding)) {
       return false;
     }
     return isEqual((VariableBinding) declaringElement, (VariableBinding) declaringElement2);
   } else if (declaringElement
       instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
     if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding)) {
       return false;
     }
     org.eclipse.jdt.internal.compiler.lookup.PackageBinding packageBinding =
         (org.eclipse.jdt.internal.compiler.lookup.PackageBinding) declaringElement;
     org.eclipse.jdt.internal.compiler.lookup.PackageBinding packageBinding2 =
         (org.eclipse.jdt.internal.compiler.lookup.PackageBinding) declaringElement2;
     return CharOperation.equals(packageBinding.compoundName, packageBinding2.compoundName);
   } else if (declaringElement instanceof ImportBinding) {
     if (!(declaringElement2 instanceof ImportBinding)) {
       return false;
     }
     ImportBinding importBinding = (ImportBinding) declaringElement;
     ImportBinding importBinding2 = (ImportBinding) declaringElement2;
     return importBinding.isStatic() == importBinding2.isStatic()
         && importBinding.onDemand == importBinding2.onDemand
         && CharOperation.equals(importBinding.compoundName, importBinding2.compoundName);
   }
   return false;
 }
 public static boolean contains(char[] name, char[][] names) {
   for (int i = 0, max = names.length; i < max; i++) {
     char[] currentName = names[i];
     if (CharOperation.equals(currentName, name)) {
       return true;
     }
   }
   return false;
 }
  private void searchVisibleFields(
      FieldBinding[] fields,
      ReferenceBinding receiverType,
      Scope scope,
      InvocationSite invocationSite,
      Scope invocationScope,
      boolean onlyStaticFields,
      ObjectVector localsFound,
      ObjectVector fieldsFound) {
    ObjectVector newFieldsFound = new ObjectVector();
    // Inherited fields which are hidden by subclasses are filtered out
    // No visibility checks can be performed without the scope & invocationSite

    next:
    for (int f = fields.length; --f >= 0; ) {
      FieldBinding field = fields[f];

      if (field.isSynthetic()) continue next;

      if (onlyStaticFields && !field.isStatic()) continue next;

      if (!field.canBeSeenBy(receiverType, invocationSite, scope)) continue next;

      for (int i = fieldsFound.size; --i >= 0; ) {
        FieldBinding otherField = (FieldBinding) fieldsFound.elementAt(i);
        if (CharOperation.equals(field.name, otherField.name, true)) {
          continue next;
        }
      }

      for (int l = localsFound.size; --l >= 0; ) {
        LocalVariableBinding local = (LocalVariableBinding) localsFound.elementAt(l);

        if (CharOperation.equals(field.name, local.name, true)) {
          continue next;
        }
      }

      newFieldsFound.add(field);
    }

    fieldsFound.addAll(newFieldsFound);
  }
  protected void addToResult(char[][] compoundName) {
    int resultLength = this.result.length;
    for (int i = 0; i < resultLength; i++)
      if (CharOperation.equals(this.result[i], compoundName)) return; // already known

    if (resultLength == this.resultIndex)
      System.arraycopy(
          this.result, 0, this.result = new char[resultLength * 2][][], 0, resultLength);
    this.result[this.resultIndex++] = compoundName;
  }
 /*
  * Return whether a type name is in pattern all super declaring types names.
  */
 private boolean isTypeInSuperDeclaringTypeNames(char[][] typeName) {
   if (this.allSuperDeclaringTypeNames == null) return false;
   int length = this.allSuperDeclaringTypeNames.length;
   for (int i = 0; i < length; i++) {
     if (CharOperation.equals(this.allSuperDeclaringTypeNames[i], typeName)) {
       return true;
     }
   }
   return false;
 }
  /**
   * Returns whether the given reference type binding matches or is a subtype of a type that matches
   * the given qualified pattern. Returns ACCURATE_MATCH if it does. Returns INACCURATE_MATCH if
   * resolve fails Returns IMPOSSIBLE_MATCH if it doesn't.
   */
  protected int resolveLevelAsSubtype(
      char[] qualifiedPattern, ReferenceBinding type, TypeBinding[] argumentTypes) {
    if (type == null) return INACCURATE_MATCH;

    int level = resolveLevelForType(qualifiedPattern, type);
    if (level != IMPOSSIBLE_MATCH) {
      MethodBinding method = argumentTypes == null ? null : getMethodBinding(type, argumentTypes);
      if (((method != null && !method.isAbstract()) || !type.isAbstract())
          && !type.isInterface()) { // if concrete, then method is overridden
        level |= OVERRIDDEN_METHOD_FLAVOR;
      }
      return level;
    }

    // matches superclass
    if (!type.isInterface()
        && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
      level = resolveLevelAsSubtype(qualifiedPattern, type.superclass(), argumentTypes);
      if (level != IMPOSSIBLE_MATCH) {
        if (argumentTypes != null) {
          // need to verify if method may be overridden
          MethodBinding method = getMethodBinding(type, argumentTypes);
          if (method != null) { // one method match in hierarchy
            if ((level & OVERRIDDEN_METHOD_FLAVOR) != 0) {
              // this method is already overridden on a super class, current match is impossible
              return IMPOSSIBLE_MATCH;
            }
            if (!method.isAbstract() && !type.isInterface()) {
              // store the fact that the method is overridden
              level |= OVERRIDDEN_METHOD_FLAVOR;
            }
          }
        }
        return level | SUB_INVOCATION_FLAVOR; // add flavor to returned level
      }
    }

    // matches interfaces
    ReferenceBinding[] interfaces = type.superInterfaces();
    if (interfaces == null) return INACCURATE_MATCH;
    for (int i = 0; i < interfaces.length; i++) {
      level = resolveLevelAsSubtype(qualifiedPattern, interfaces[i], null);
      if (level != IMPOSSIBLE_MATCH) {
        if (!type.isAbstract()
            && !type.isInterface()) { // if concrete class, then method is overridden
          level |= OVERRIDDEN_METHOD_FLAVOR;
        }
        return level | SUB_INVOCATION_FLAVOR; // add flavor to returned level
      }
    }
    return IMPOSSIBLE_MATCH;
  }
  /** 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++;
            }
          }
        }
      }
    }
  }
  public char[] add(char[] name) {
    int length = this.names.length;
    int index = CharOperation.hashCode(name) % length;
    char[] current;
    while ((current = this.names[index]) != null) {
      if (CharOperation.equals(current, name)) return current;
      if (++index == length) index = 0;
    }
    this.names[index] = name;

    // assumes the threshold is never equal to the size of the table
    if (++this.elementSize > this.threshold) rehash();
    return name;
  }
  private boolean matchOverriddenMethod(
      ReferenceBinding type, MethodBinding method, MethodBinding matchMethod) {
    if (type == null || this.pattern.selector == null) return false;

    // matches superclass
    if (!type.isInterface()
        && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
      ReferenceBinding superClass = type.superclass();
      if (superClass.isParameterizedType()) {
        MethodBinding[] methods = superClass.getMethods(this.pattern.selector);
        int length = methods.length;
        for (int i = 0; i < length; i++) {
          if (methods[i].areParametersEqual(method)) {
            if (matchMethod == null) {
              if (methodParametersEqualsPattern(methods[i].original())) return true;
            } else {
              if (methods[i].original().areParametersEqual(matchMethod)) return true;
            }
          }
        }
      }
      if (matchOverriddenMethod(superClass, method, matchMethod)) {
        return true;
      }
    }

    // matches interfaces
    ReferenceBinding[] interfaces = type.superInterfaces();
    if (interfaces == null) return false;
    int iLength = interfaces.length;
    for (int i = 0; i < iLength; i++) {
      if (interfaces[i].isParameterizedType()) {
        MethodBinding[] methods = interfaces[i].getMethods(this.pattern.selector);
        int length = methods.length;
        for (int j = 0; j < length; j++) {
          if (methods[j].areParametersEqual(method)) {
            if (matchMethod == null) {
              if (methodParametersEqualsPattern(methods[j].original())) return true;
            } else {
              if (methods[j].original().areParametersEqual(matchMethod)) return true;
            }
          }
        }
      }
      if (matchOverriddenMethod(interfaces[i], method, matchMethod)) {
        return true;
      }
    }
    return false;
  }
 static boolean isEqual(
     org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding,
     org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding2,
     HashSet visitedTypes) {
   if (methodBinding == null) {
     return methodBinding2 == null;
   }
   if (methodBinding2 == null) return false;
   return CharOperation.equals(methodBinding.selector, methodBinding2.selector)
       && isEqual(methodBinding.returnType, methodBinding2.returnType, visitedTypes)
       && isEqual(methodBinding.thrownExceptions, methodBinding2.thrownExceptions, visitedTypes)
       && isEqual(methodBinding.declaringClass, methodBinding2.declaringClass, visitedTypes)
       && isEqual(methodBinding.typeVariables, methodBinding2.typeVariables, visitedTypes)
       && isEqual(methodBinding.parameters, methodBinding2.parameters, visitedTypes);
 }
 private IJavaElement declarationMatched(IJavaElement javaElement, IBindingProvider mirror) {
   if (mirror != null) {
     parser.setProject(typeRoot.getJavaProject());
     IBinding[] bindings = parser.createBindings(new IJavaElement[] {javaElement}, null);
     if (bindings.length > 0 && bindings[0] != null) {
       if (mirror instanceof JDTMethod && bindings[0] instanceof ITypeBinding) {
         // Case of a constructor : let's go to the constructor and not to the type.
         ITypeBinding typeBinding = (ITypeBinding) bindings[0];
         for (IMethodBinding methodBinding : typeBinding.getDeclaredMethods()) {
           //                        if (methodBinding.isConstructor()) {
           if (CharOperation.equals(
               methodBinding.getKey().toCharArray(), mirror.getBindingKey())) {
             return methodBinding.getJavaElement();
           }
           //                        }
         }
       }
       if (CharOperation.equals(bindings[0].getKey().toCharArray(), mirror.getBindingKey())) {
         return javaElement;
       }
     }
   }
   return null;
 }
Beispiel #26
0
 private int readTargetValue(int offset) {
   int currentOffset = offset;
   int tag = u1At(currentOffset);
   currentOffset++;
   switch (tag) {
     case 'e':
       int utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset;
       char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
       currentOffset += 2;
       if (typeName.length == 34
           && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_ELEMENTTYPE)) {
         utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset;
         char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
         this.standardAnnotationTagBits |= Annotation.getTargetElementType(constName);
       }
       currentOffset += 2;
       break;
     case 'B':
     case 'C':
     case 'D':
     case 'F':
     case 'I':
     case 'J':
     case 'S':
     case 'Z':
     case 's':
     case 'c':
       currentOffset += 2;
       break;
     case '@':
       // none of the supported standard annotation are in the nested
       // level.
       currentOffset = scanAnnotation(currentOffset, false, false);
       break;
     case '[':
       int numberOfValues = u2At(currentOffset);
       currentOffset += 2;
       if (numberOfValues == 0) {
         this.standardAnnotationTagBits |= TagBits.AnnotationTarget;
       } else {
         for (int i = 0; i < numberOfValues; i++) currentOffset = readTargetValue(currentOffset);
       }
       break;
     default:
       throw new IllegalStateException();
   }
   return currentOffset;
 }
 /*
  * Return the char array that is in this set and that is equals to the given char array.
  * Return null if not found.
  */
 public char[] get(char[] array) {
   cleanupGarbageCollectedValues();
   int valuesLength = this.values.length;
   int index = (CharOperation.hashCode(array) & 0x7FFFFFFF) % valuesLength;
   HashableWeakReference currentValue;
   while ((currentValue = this.values[index]) != null) {
     char[] referent;
     if (CharOperation.equals(array, referent = (char[]) currentValue.get())) {
       return referent;
     }
     if (++index == valuesLength) {
       index = 0;
     }
   }
   return null;
 }
Beispiel #28
0
  private boolean isUnsafeLongAnnotation(Annotation annot, ClassScope scope) {
    if (annot.type == null) {
      return false;
    }

    TypeBinding resolved = annot.type.resolveType(scope);
    if (resolved == null || !(resolved instanceof ReferenceBinding)) {
      return false;
    }

    ReferenceBinding rb = (ReferenceBinding) resolved;
    if (CharOperation.equals(rb.compoundName, UNSAFE_LONG_ANNOTATION_CHARS)) {
      return true;
    }
    return false;
  }
 public boolean canUseDiamond(String[] parameterTypes, char[] fullyQualifiedTypeName) {
   TypeBinding guessedType = null;
   char[][] cn = CharOperation.splitOn('.', fullyQualifiedTypeName);
   Scope scope = this.assistScope;
   if (scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_7) return false;
   // If no LHS or return type expected, then we can safely use diamond
   char[][] expectedTypekeys = this.completionContext.getExpectedTypesKeys();
   if (expectedTypekeys == null || expectedTypekeys.length == 0) return true;
   // Next, find out whether any of the constructor parameters are the same as one of the
   // class type variables. If yes, diamond cannot be used.
   TypeReference ref;
   if (cn.length == 1) {
     ref = new SingleTypeReference(cn[0], 0);
   } else {
     ref = new QualifiedTypeReference(cn, new long[cn.length]);
   }
   // {ObjectTeams: protect call into the compiler
   try (Config config =
       Dependencies.setup(this, this.parser, this.lookupEnvironment, true, true)) {
     // orig:
     switch (scope.kind) {
       case Scope.METHOD_SCOPE:
       case Scope.BLOCK_SCOPE:
         guessedType = ref.resolveType((BlockScope) scope);
         break;
       case Scope.CLASS_SCOPE:
         guessedType = ref.resolveType((ClassScope) scope);
         break;
     }
     // :giro
   }
   // SH}
   if (guessedType != null && guessedType.isValidBinding()) {
     // the erasure must be used because guessedType can be a RawTypeBinding
     guessedType = guessedType.erasure();
     TypeVariableBinding[] typeVars = guessedType.typeVariables();
     for (int i = 0; i < parameterTypes.length; i++) {
       for (int j = 0; j < typeVars.length; j++) {
         if (CharOperation.equals(parameterTypes[i].toCharArray(), typeVars[j].sourceName))
           return false;
       }
     }
     return true;
   }
   return false;
 }
 /**
  * Answer the name of the role that introduced this callin mapping (support for overriding in
  * otredyn).
  */
 public char[] declaringRoleName() {
   char[] roleName = this.scope.enclosingSourceType().sourceName();
   if (this.name == null) return roleName;
   if (this.name[0] != '<') {
     ReferenceBinding currentRole = this.scope.enclosingSourceType();
     while (currentRole != null && currentRole.isRole()) {
       for (CallinCalloutBinding mapping : currentRole.callinCallouts) {
         if (CharOperation.equals(this.name, mapping.name)) {
           roleName = currentRole.sourceName();
           break;
         }
       }
       currentRole = currentRole.superclass();
     }
   }
   return roleName;
 }