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);
   }
 }
  public TypeReferencePattern(char[] qualification, char[] simpleName, int matchRule) {
    this(matchRule);

    this.qualification =
        this.isCaseSensitive ? qualification : CharOperation.toLowerCase(qualification);
    this.simpleName =
        (this.isCaseSensitive || this.isCamelCase)
            ? simpleName
            : CharOperation.toLowerCase(simpleName);

    if (simpleName == null)
      this.segments =
          this.qualification == null
              ? ONE_STAR_CHAR
              : CharOperation.splitOn('.', this.qualification);
    else this.segments = null;

    if (this.segments == null)
      if (this.qualification == null) this.segmentsSize = 0;
      else this.segmentsSize = CharOperation.occurencesOf('.', this.qualification) + 1;
    else this.segmentsSize = this.segments.length;

    this.mustResolve =
        true; // always resolve (in case of a simple name reference being a potential match)
  }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.compiler.lookup.Binding#shortReadableName()
  */
 public char[] shortReadableName() {
   switch (this.boundKind) {
     case Wildcard.UNBOUND:
       return TypeConstants.WILDCARD_NAME;
     case Wildcard.EXTENDS:
       if (this.otherBounds == null)
         return CharOperation.concat(
             TypeConstants.WILDCARD_NAME,
             TypeConstants.WILDCARD_EXTENDS,
             this.bound.shortReadableName());
       StringBuffer buffer = new StringBuffer(10);
       buffer.append(this.bound.shortReadableName());
       for (int i = 0, length = this.otherBounds.length; i < length; i++) {
         buffer.append('&').append(this.otherBounds[i].shortReadableName());
       }
       int length;
       char[] result = new char[length = buffer.length()];
       buffer.getChars(0, length, result, 0);
       return result;
     default: // SUPER
       return CharOperation.concat(
           TypeConstants.WILDCARD_NAME,
           TypeConstants.WILDCARD_SUPER,
           this.bound.shortReadableName());
   }
 }
  @Test
  public void testAddClass() throws Exception {

    File workspace = new File(BaseTest.class.getResource("/projects").getFile());
    ResourceChangedEvent event =
        new ResourceChangedEvent(
            workspace,
            new CreateEvent(
                "projects", "/test/src/main/java/com/codenvy/test/NewClass.java", false));

    NameEnvironmentAnswer answer =
        project
            .getNameEnvironment()
            .findType(CharOperation.splitOn('.', "com.codenvy.test.NewClass".toCharArray()));
    assertThat(answer).isNull();

    FileOutputStream outputStream =
        new FileOutputStream(
            new File(workspace, "/test/src/main/java/com/codenvy/test/NewClass.java"));
    outputStream.write("packagecom.codenvy.test;\n public class NewClass{}\n".getBytes());
    outputStream.close();

    project.getJavaModelManager().deltaState.resourceChanged(event);
    project.creteNewNameEnvironment();
    answer =
        project
            .getNameEnvironment()
            .findType(CharOperation.splitOn('.', "com.codenvy.test.NewClass".toCharArray()));
    assertThat(answer).isNotNull();
  }
 public char[] genericTypeSignature() {
   // since we have no wildcard, we combine the logic from CaptureBinding plus WildcardBinding
   // here:
   if (this.genericTypeSignature == null) {
     char[] boundSignature;
     try {
       if (this.recursionLevel++ > 0 || this.firstBound == null) {
         boundSignature = TypeConstants.WILDCARD_STAR;
       } else if (this.upperBounds != null) {
         boundSignature =
             CharOperation.concat(
                 TypeConstants.WILDCARD_PLUS, this.firstBound.genericTypeSignature());
       } else if (this.lowerBound != null) {
         boundSignature =
             CharOperation.concat(
                 TypeConstants.WILDCARD_MINUS, this.lowerBound.genericTypeSignature());
       } else {
         boundSignature = TypeConstants.WILDCARD_STAR;
       }
       this.genericTypeSignature =
           CharOperation.concat(TypeConstants.WILDCARD_CAPTURE, boundSignature);
     } finally {
       this.recursionLevel--;
     }
   }
   return this.genericTypeSignature;
 }
 public String annotatedDebugName() {
   StringBuffer buffer = new StringBuffer(16);
   AnnotationBinding[] annotations = getTypeAnnotations();
   for (int i = 0, length = annotations == null ? 0 : annotations.length; i < length; i++) {
     buffer.append(annotations[i]);
     buffer.append(' ');
   }
   switch (this.boundKind) {
     case Wildcard.UNBOUND:
       return buffer.append(TypeConstants.WILDCARD_NAME).toString();
     case Wildcard.EXTENDS:
       if (this.otherBounds == null)
         return buffer
             .append(
                 CharOperation.concat(
                     TypeConstants.WILDCARD_NAME,
                     TypeConstants.WILDCARD_EXTENDS,
                     this.bound.annotatedDebugName().toCharArray()))
             .toString();
       buffer.append(this.bound.annotatedDebugName());
       for (int i = 0, length = this.otherBounds.length; i < length; i++) {
         buffer.append(" & ").append(this.otherBounds[i].annotatedDebugName()); // $NON-NLS-1$
       }
       return buffer.toString();
     default: // SUPER
       return buffer
           .append(
               CharOperation.concat(
                   TypeConstants.WILDCARD_NAME,
                   TypeConstants.WILDCARD_SUPER,
                   this.bound.annotatedDebugName().toCharArray()))
           .toString();
   }
 }
 /** @see java.lang.Object#toString() */
 public String toString() {
   if (this.hasTypeAnnotations()) return annotatedDebugName();
   switch (this.boundKind) {
     case Wildcard.UNBOUND:
       return new String(TypeConstants.WILDCARD_NAME);
     case Wildcard.EXTENDS:
       if (this.otherBounds == null)
         return new String(
             CharOperation.concat(
                 TypeConstants.WILDCARD_NAME,
                 TypeConstants.WILDCARD_EXTENDS,
                 this.bound.debugName().toCharArray()));
       StringBuffer buffer = new StringBuffer(this.bound.debugName());
       for (int i = 0, length = this.otherBounds.length; i < length; i++) {
         buffer.append('&').append(this.otherBounds[i].debugName());
       }
       return buffer.toString();
     default: // SUPER
       return new String(
           CharOperation.concat(
               TypeConstants.WILDCARD_NAME,
               TypeConstants.WILDCARD_SUPER,
               this.bound.debugName().toCharArray()));
   }
 }
示例#8
0
 private char[][][] getQualifiedNames(ObjectVector types) {
   final int size = types.size;
   char[][][] focusQualifiedNames = null;
   IJavaElement javaElement = this.pattern.focus;
   int index = 0;
   while (javaElement != null && !(javaElement instanceof ITypeRoot)) {
     javaElement = javaElement.getParent();
   }
   if (javaElement != null) {
     IType primaryType = ((ITypeRoot) javaElement).findPrimaryType();
     if (primaryType != null) {
       focusQualifiedNames = new char[size + 1][][];
       focusQualifiedNames[index++] =
           CharOperation.splitOn('.', primaryType.getFullyQualifiedName().toCharArray());
     }
   }
   if (focusQualifiedNames == null) {
     focusQualifiedNames = new char[size][][];
   }
   for (int i = 0; i < size; i++) {
     focusQualifiedNames[index++] =
         CharOperation.splitOn(
             '.', ((IType) (types.elementAt(i))).getFullyQualifiedName().toCharArray());
   }
   return focusQualifiedNames.length == 0
       ? null
       : ReferenceCollection.internQualifiedNames(focusQualifiedNames, true);
 }
 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;
 }
  boolean matchTypeDeclaration(
      TypeDeclarationPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) {
    if (!(binaryInfo instanceof IBinaryType)) return false;

    IBinaryType type = (IBinaryType) binaryInfo;
    char[] fullyQualifiedTypeName = convertClassFileFormat(type.getName());
    boolean qualifiedPattern = pattern instanceof QualifiedTypeDeclarationPattern;
    if (pattern.enclosingTypeNames == null || qualifiedPattern) {
      char[] simpleName =
          (pattern.getMatchMode() == SearchPattern.R_PREFIX_MATCH)
              ? CharOperation.concat(pattern.simpleName, IIndexConstants.ONE_STAR)
              : pattern.simpleName;
      char[] pkg =
          qualifiedPattern
              ? ((QualifiedTypeDeclarationPattern) pattern).qualification
              : pattern.pkg;
      if (!checkTypeName(
          simpleName,
          pkg,
          fullyQualifiedTypeName,
          pattern.isCaseSensitive(),
          pattern.isCamelCase())) return false;
    } else {
      char[] enclosingTypeName = CharOperation.concatWith(pattern.enclosingTypeNames, '.');
      char[] patternString =
          pattern.pkg == null
              ? enclosingTypeName
              : CharOperation.concat(pattern.pkg, enclosingTypeName, '.');
      if (!checkTypeName(
          pattern.simpleName,
          patternString,
          fullyQualifiedTypeName,
          pattern.isCaseSensitive(),
          pattern.isCamelCase())) return false;
    }

    int kind = TypeDeclaration.kind(type.getModifiers());
    switch (pattern.typeSuffix) {
      case CLASS_SUFFIX:
        return kind == TypeDeclaration.CLASS_DECL;
      case INTERFACE_SUFFIX:
        return kind == TypeDeclaration.INTERFACE_DECL;
      case ENUM_SUFFIX:
        return kind == TypeDeclaration.ENUM_DECL;
      case ANNOTATION_TYPE_SUFFIX:
        return kind == TypeDeclaration.ANNOTATION_TYPE_DECL;
      case CLASS_AND_INTERFACE_SUFFIX:
        return kind == TypeDeclaration.CLASS_DECL || kind == TypeDeclaration.INTERFACE_DECL;
      case CLASS_AND_ENUM_SUFFIX:
        return kind == TypeDeclaration.CLASS_DECL || kind == TypeDeclaration.ENUM_DECL;
      case INTERFACE_AND_ANNOTATION_SUFFIX:
        return kind == TypeDeclaration.INTERFACE_DECL
            || kind == TypeDeclaration.ANNOTATION_TYPE_DECL;
      case TYPE_SUFFIX: // nothing
    }
    return true;
  }
 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;
  }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#sourceName()
  */
 public char[] sourceName() {
   switch (this.boundKind) {
     case Wildcard.UNBOUND:
       return TypeConstants.WILDCARD_NAME;
     case Wildcard.EXTENDS:
       return CharOperation.concat(
           TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.sourceName());
     default: // SUPER
       return CharOperation.concat(
           TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.sourceName());
   }
 }
示例#14
0
 /*
  * Creates the value wrapper from the given expression, and sets the valueKind on the given memberValuePair
  */
 private Object getAnnotationMemberValue(
     MemberValuePair memberValuePair, Expression expression, JavaElement parentElement) {
   if (expression instanceof NullLiteral) {
     return null;
   } else if (expression instanceof Literal) {
     ((Literal) expression).computeConstant();
     return Util.getAnnotationMemberValue(memberValuePair, expression.constant);
   } else if (expression instanceof org.eclipse.jdt.internal.compiler.ast.Annotation) {
     memberValuePair.valueKind = IMemberValuePair.K_ANNOTATION;
     return getAnnotation(
         (org.eclipse.jdt.internal.compiler.ast.Annotation) expression, parentElement);
   } else if (expression instanceof ClassLiteralAccess) {
     ClassLiteralAccess classLiteral = (ClassLiteralAccess) expression;
     char[] typeName = CharOperation.concatWith(classLiteral.type.getTypeName(), '.');
     memberValuePair.valueKind = IMemberValuePair.K_CLASS;
     return new String(typeName);
   } else if (expression instanceof QualifiedNameReference) {
     char[] qualifiedName =
         CharOperation.concatWith(((QualifiedNameReference) expression).tokens, '.');
     memberValuePair.valueKind = IMemberValuePair.K_QUALIFIED_NAME;
     return new String(qualifiedName);
   } else if (expression instanceof SingleNameReference) {
     char[] simpleName = ((SingleNameReference) expression).token;
     if (simpleName == RecoveryScanner.FAKE_IDENTIFIER) {
       memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
       return null;
     }
     memberValuePair.valueKind = IMemberValuePair.K_SIMPLE_NAME;
     return new String(simpleName);
   } else if (expression instanceof ArrayInitializer) {
     memberValuePair.valueKind = -1; // modified below by the first call to getMemberValue(...)
     Expression[] expressions = ((ArrayInitializer) expression).expressions;
     int length = expressions == null ? 0 : expressions.length;
     Object[] values = new Object[length];
     for (int i = 0; i < length; i++) {
       int previousValueKind = memberValuePair.valueKind;
       Object value = getAnnotationMemberValue(memberValuePair, expressions[i], parentElement);
       if (previousValueKind != -1 && memberValuePair.valueKind != previousValueKind) {
         // values are heterogeneous, value kind is thus unknown
         memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
       }
       values[i] = value;
     }
     if (memberValuePair.valueKind == -1) memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
     return values;
   } else {
     memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
     return null;
   }
 }
  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;
  }
  public static ReferenceBinding resolveType(LookupEnvironment lookupEnvironment, String typeName) {
    ReferenceBinding type = null;

    int p = typeName.indexOf('$');
    if (p > 0) {
      // resolve an outer type before trying to get the cached inner
      String cupName = typeName.substring(0, p);
      char[][] chars = CharOperation.splitOn('.', cupName.toCharArray());
      ReferenceBinding outerType = lookupEnvironment.getType(chars);
      if (outerType != null) {
        // outer class was found
        resolveRecursive(outerType);
        chars = CharOperation.splitOn('.', typeName.toCharArray());
        type = lookupEnvironment.getCachedType(chars);
        if (type == null) {
          // no inner type; this is a pure failure
          return null;
        }
      }
    } else {
      // just resolve the type straight out
      char[][] chars = CharOperation.splitOn('.', typeName.toCharArray());
      type = lookupEnvironment.getType(chars);
    }

    if (type != null) {
      if (type instanceof UnresolvedReferenceBinding) {
        /*
         * Since type is an instance of UnresolvedReferenceBinding, we know that
         * the return value BinaryTypeBinding.resolveType will be of type
         * ReferenceBinding
         */
        type = (ReferenceBinding) BinaryTypeBinding.resolveType(type, lookupEnvironment, true);
      }
      // found it
      return type;
    }

    // Assume that the last '.' should be '$' and try again.
    //
    p = typeName.lastIndexOf('.');
    if (p >= 0) {
      typeName = typeName.substring(0, p) + "$" + typeName.substring(p + 1);
      return resolveType(lookupEnvironment, typeName);
    }

    return null;
  }
 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);
 }
 /*
  * 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;
 }
示例#19
0
  /**
   * Answer the receiver's constant pool name. NOTE: This method should only be used during/after
   * code gen. e.g. '[Ljava/lang/Object;'
   */
  public char[] constantPoolName() {
    if (constantPoolName != null) return constantPoolName;

    char[] brackets = new char[dimensions];
    for (int i = dimensions - 1; i >= 0; i--) brackets[i] = '[';
    return constantPoolName = CharOperation.concat(brackets, leafComponentType.signature());
  }
 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);
 }
示例#21
0
  /*
   * 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;
  }
 /** 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;
         }
       }
     }
   }
 }
  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);
    }
  }
 /**
  * @see
  *     org.eclipse.jdt.internal.compiler.ast.Expression#computeConversion(org.eclipse.jdt.internal.compiler.lookup.Scope,
  *     org.eclipse.jdt.internal.compiler.lookup.TypeBinding,
  *     org.eclipse.jdt.internal.compiler.lookup.TypeBinding)
  */
 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()) {
     FieldBinding originalBinding = this.binding.original();
     TypeBinding originalType = originalBinding.type;
     // extra cast needed if field type is type variable
     if (originalType.leafComponentType().isTypeVariable()) {
       TypeBinding targetType =
           (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
               ? compileTimeType // unboxing: checkcast before conversion
               : runtimeTimeType;
       this.genericCast = originalBinding.type.genericCast(targetType);
       if (this.genericCast instanceof ReferenceBinding) {
         ReferenceBinding referenceCast = (ReferenceBinding) this.genericCast;
         if (!referenceCast.canBeSeenBy(scope)) {
           scope
               .problemReporter()
               .invalidType(
                   this,
                   new ProblemReferenceBinding(
                       CharOperation.splitOn('.', referenceCast.shortReadableName()),
                       referenceCast,
                       ProblemReasons.NotVisible));
         }
       }
     }
   }
   super.computeConversion(scope, runtimeTimeType, compileTimeType);
 }
  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);
  }
示例#26
0
  private int initializeBuilder(int kind, boolean forBuild) throws CoreException {
    // some calls just need the nameEnvironment initialized so skip the rest
    this.javaProject = (JavaProject) JavaCore.create(this.currentProject);
    this.workspaceRoot = this.currentProject.getWorkspace().getRoot();

    if (forBuild) {
      // cache the known participants for this project
      this.participants =
          JavaModelManager.getJavaModelManager()
              .compilationParticipants
              .getCompilationParticipants(this.javaProject);
      if (this.participants != null)
        for (int i = 0, l = this.participants.length; i < l; i++)
          if (this.participants[i].aboutToBuild(this.javaProject)
              == CompilationParticipant.NEEDS_FULL_BUILD) kind = FULL_BUILD;

      // Flush the existing external files cache if this is the beginning of a build cycle
      String projectName = this.currentProject.getName();
      if (builtProjects == null || builtProjects.contains(projectName)) {
        builtProjects = new ArrayList();
      }
      builtProjects.add(projectName);
    }

    this.binaryLocationsPerProject = new SimpleLookupTable(3);
    this.nameEnvironment =
        new NameEnvironment(
            this.workspaceRoot, this.javaProject, this.binaryLocationsPerProject, this.notifier);

    if (forBuild) {
      String filterSequence =
          this.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, true);
      char[][] filters =
          filterSequence != null && filterSequence.length() > 0
              ? CharOperation.splitAndTrimOn(',', filterSequence.toCharArray())
              : null;
      if (filters == null) {
        this.extraResourceFileFilters = null;
        this.extraResourceFolderFilters = null;
      } else {
        int fileCount = 0, folderCount = 0;
        for (int i = 0, l = filters.length; i < l; i++) {
          char[] f = filters[i];
          if (f.length == 0) continue;
          if (f[f.length - 1] == '/') folderCount++;
          else fileCount++;
        }
        this.extraResourceFileFilters = new char[fileCount][];
        this.extraResourceFolderFilters = new String[folderCount];
        for (int i = 0, l = filters.length; i < l; i++) {
          char[] f = filters[i];
          if (f.length == 0) continue;
          if (f[f.length - 1] == '/')
            this.extraResourceFolderFilters[--folderCount] = new String(f, 0, f.length - 1);
          else this.extraResourceFileFilters[--fileCount] = f;
        }
      }
    }
    return kind;
  }
  public char[] getMainTypeName() {
    if (this.compilationResult.compilationUnit == null) {
      char[] fileName = this.compilationResult.getFileName();

      int start = CharOperation.lastIndexOf('/', fileName) + 1;
      if (start == 0 || start < CharOperation.lastIndexOf('\\', fileName))
        start = CharOperation.lastIndexOf('\\', fileName) + 1;

      int end = CharOperation.lastIndexOf('.', fileName);
      if (end == -1) end = fileName.length;

      return CharOperation.subarray(fileName, start, end);
    } else {
      return this.compilationResult.compilationUnit.getMainTypeName();
    }
  }
示例#28
0
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + Util.hashCode(this.pairs);
   result = prime * result + CharOperation.hashCode(this.typename);
   return result;
 }
 public SelectionOnQualifiedNameReference(
     char[][] previousIdentifiers, char[] selectionIdentifier, long[] positions) {
   super(
       CharOperation.arrayConcat(previousIdentifiers, selectionIdentifier),
       positions,
       (int) (positions[0] >>> 32),
       (int) positions[positions.length - 1]);
 }
示例#30
0
 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;
 }