/** @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()));
   }
 }
 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();
   }
 }
 /* (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());
   }
 }
 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;
 }
  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;
  }
 /* (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());
   }
 }
Exemple #7
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());
  }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.compiler.lookup.TypeBinding#signature()
  */
 public char[] genericTypeSignature() {
   if (this.genericSignature == null) {
     switch (this.boundKind) {
       case Wildcard.UNBOUND:
         this.genericSignature = TypeConstants.WILDCARD_STAR;
         break;
       case Wildcard.EXTENDS:
         this.genericSignature =
             CharOperation.concat(TypeConstants.WILDCARD_PLUS, this.bound.genericTypeSignature());
         break;
       default: // SUPER
         this.genericSignature =
             CharOperation.concat(TypeConstants.WILDCARD_MINUS, this.bound.genericTypeSignature());
     }
   }
   return this.genericSignature;
 }
 public char[] genericTypeSignature() {
   if (this.genericTypeSignature == null) {
     this.genericTypeSignature =
         CharOperation.concat(
             TypeConstants.WILDCARD_CAPTURE, this.wildcard.genericTypeSignature());
   }
   return this.genericTypeSignature;
 }
Exemple #10
0
 public char[] sourceName() {
   char[] brackets = new char[dimensions * 2];
   for (int i = dimensions * 2 - 1; i >= 0; i -= 2) {
     brackets[i] = ']';
     brackets[i - 1] = '[';
   }
   return CharOperation.concat(leafComponentType.sourceName(), brackets);
 }
Exemple #11
0
 public char[] readableName() /* java.lang.Object[] */ {
   char[] brackets = new char[dimensions * 2];
   for (int i = dimensions * 2 - 1; i >= 0; i -= 2) {
     brackets[i] = ']';
     brackets[i - 1] = '[';
   }
   return CharOperation.concat(leafComponentType.readableName(), brackets);
 }
  public SyntheticArgumentBinding(ReferenceBinding enclosingType) {

    super(
        CharOperation.concat(
            TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX,
            String.valueOf(enclosingType.depth()).toCharArray()),
        enclosingType,
        ClassFileConstants.AccFinal,
        true);
  }
Exemple #13
0
  public char[] genericTypeSignature() {

    if (this.genericTypeSignature == null) {
      char[] brackets = new char[dimensions];
      for (int i = dimensions - 1; i >= 0; i--) brackets[i] = '[';
      this.genericTypeSignature =
          CharOperation.concat(brackets, leafComponentType.genericTypeSignature());
    }
    return this.genericTypeSignature;
  }
  public SyntheticArgumentBinding(LocalVariableBinding actualOuterLocalVariable) {

    super(
        CharOperation.concat(
            TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX, actualOuterLocalVariable.name),
        actualOuterLocalVariable.type,
        ClassFileConstants.AccFinal,
        true);
    this.actualOuterLocalVariable = actualOuterLocalVariable;
  }
 /*
  * genericTypeKey {rank}*|+|- [boundKey]
  * p.X<T> { X<?> ... } --> Lp/X<TT;>;{0}*
  */
 public char[] computeUniqueKey(boolean isLeaf) {
   char[] genericTypeKey = this.genericType.computeUniqueKey(false /*not a leaf*/);
   char[] wildCardKey;
   // We now encode the rank also in the binding key -
   // https://bugs.eclipse.org/bugs/show_bug.cgi?id=234609
   char[] rankComponent = ('{' + String.valueOf(this.rank) + '}').toCharArray();
   switch (this.boundKind) {
     case Wildcard.UNBOUND:
       wildCardKey = TypeConstants.WILDCARD_STAR;
       break;
     case Wildcard.EXTENDS:
       wildCardKey =
           CharOperation.concat(
               TypeConstants.WILDCARD_PLUS, this.bound.computeUniqueKey(false /*not a leaf*/));
       break;
     default: // SUPER
       wildCardKey =
           CharOperation.concat(
               TypeConstants.WILDCARD_MINUS, this.bound.computeUniqueKey(false /*not a leaf*/));
       break;
   }
   return CharOperation.concat(genericTypeKey, rankComponent, wildCardKey);
 }
 public int match(ASTNode node, MatchingNodeSet nodeSet) {
   int declarationsLevel = IMPOSSIBLE_MATCH;
   if (this.pattern.findReferences) {
     if (node instanceof ImportReference) {
       // With static import, we can have static method reference in import reference
       ImportReference importRef = (ImportReference) node;
       int length = importRef.tokens.length - 1;
       if (importRef.isStatic()
           && ((importRef.bits & ASTNode.OnDemand) == 0)
           && matchesName(this.pattern.selector, importRef.tokens[length])) {
         char[][] compoundName = new char[length][];
         System.arraycopy(importRef.tokens, 0, compoundName, 0, length);
         char[] declaringType =
             CharOperation.concat(
                 this.pattern.declaringQualification, this.pattern.declaringSimpleName, '.');
         if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) {
           declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
         }
       }
     }
   }
   return nodeSet.addMatch(node, declarationsLevel);
 }
 /** @return char[][] */
 public char[][] getParameterizedTypeName() {
   StringBuffer buffer = new StringBuffer(5);
   buffer.append(this.token).append('<');
   for (int i = 0, length = this.typeArguments.length; i < length; i++) {
     if (i > 0) buffer.append(',');
     buffer.append(
         CharOperation.concatWith(this.typeArguments[i].getParameterizedTypeName(), '.'));
   }
   buffer.append('>');
   int nameLength = buffer.length();
   char[] name = new char[nameLength];
   buffer.getChars(0, nameLength, name, 0);
   int dim = this.dimensions;
   if (dim > 0) {
     char[] dimChars = new char[dim * 2];
     for (int i = 0; i < dim; i++) {
       int index = i * 2;
       dimChars[index] = '[';
       dimChars[index + 1] = ']';
     }
     name = CharOperation.concat(name, dimChars);
   }
   return new char[][] {name};
 }
 /** T::Ljava/util/Map;:Ljava/io/Serializable; T:LY<TT;> */
 public char[] genericTypeSignature() {
   if (this.genericTypeSignature != null) return this.genericTypeSignature;
   return this.genericTypeSignature = CharOperation.concat('T', this.sourceName, ';');
 }
  protected void reportDeclaration(
      MethodBinding methodBinding, MatchLocator locator, SimpleSet knownMethods)
      throws CoreException {
    ReferenceBinding declaringClass = methodBinding.declaringClass;
    IType type = locator.lookupType(declaringClass);
    if (type == null) return; // case of a secondary type

    // Report match for binary
    if (type.isBinary()) {
      IMethod method = null;
      TypeBinding[] parameters = methodBinding.original().parameters;
      int parameterLength = parameters.length;
      char[][] parameterTypes = new char[parameterLength][];
      for (int i = 0; i < parameterLength; i++) {
        char[] typeName = parameters[i].qualifiedSourceName();
        for (int j = 0, dim = parameters[i].dimensions(); j < dim; j++) {
          typeName = CharOperation.concat(typeName, new char[] {'[', ']'});
        }
        parameterTypes[i] = typeName;
      }
      method = locator.createBinaryMethodHandle(type, methodBinding.selector, parameterTypes);
      if (method == null || knownMethods.addIfNotIncluded(method) == null) return;

      IResource resource = type.getResource();
      if (resource == null) resource = type.getJavaProject().getProject();
      IBinaryType info =
          locator.getBinaryInfo(
              (org.eclipse.jdt.internal.core.ClassFile) type.getClassFile(), resource);
      locator.reportBinaryMemberDeclaration(
          resource, method, methodBinding, info, SearchMatch.A_ACCURATE);
      return;
    }

    // When source is available, report match if method is found in the declaring type
    IResource resource = type.getResource();
    if (declaringClass instanceof ParameterizedTypeBinding)
      declaringClass = ((ParameterizedTypeBinding) declaringClass).genericType();
    ClassScope scope = ((SourceTypeBinding) declaringClass).scope;
    if (scope != null) {
      TypeDeclaration typeDecl = scope.referenceContext;
      AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(methodBinding.original());
      if (methodDecl != null) {
        // Create method handle from method declaration
        String methodName = new String(methodBinding.selector);
        Argument[] arguments = methodDecl.arguments;
        int length = arguments == null ? 0 : arguments.length;
        String[] parameterTypes = new String[length];
        for (int i = 0; i < length; i++) {
          char[][] typeName = arguments[i].type.getParameterizedTypeName();
          parameterTypes[i] =
              Signature.createTypeSignature(CharOperation.concatWith(typeName, '.'), false);
        }
        IMethod method = type.getMethod(methodName, parameterTypes);
        if (method == null || knownMethods.addIfNotIncluded(method) == null) return;

        // Create and report corresponding match
        int offset = methodDecl.sourceStart;
        this.match =
            new MethodDeclarationMatch(
                method,
                SearchMatch.A_ACCURATE,
                offset,
                methodDecl.sourceEnd - offset + 1,
                locator.getParticipant(),
                resource);
        locator.report(this.match);
      }
    }
  }
  /**
   * In case emulating local variables, wrap the (recovered) statements inside a try statement so as
   * to achieve local state commiting (copy local vars back to fields). The CSToCuMapper could not
   * be used, since it could have interfered with the syntax recovery specific to code snippets.
   */
  protected void consumeMethodDeclaration(boolean isNotAbstract) {
    // MethodDeclaration ::= MethodHeader MethodBody
    // AbstractMethodDeclaration ::= MethodHeader ';'

    super.consumeMethodDeclaration(isNotAbstract);

    // now we know that we have a method declaration at the top of the ast stack
    MethodDeclaration methodDecl = (MethodDeclaration) this.astStack[this.astPtr];

    // automatically wrap the last statement inside a return statement, if it is an expression
    // support have to be defined at toplevel only
    if (this.isTopLevelType()) {
      int last = methodDecl.statements == null ? -1 : methodDecl.statements.length - 1;
      if (last >= 0 && methodDecl.statements[last] instanceof Expression) {
        Expression lastExpression = (Expression) methodDecl.statements[last];
        methodDecl.statements[last] =
            new CodeSnippetReturnStatement(
                lastExpression, lastExpression.sourceStart, lastExpression.sourceEnd);
      }
    }

    int start = methodDecl.bodyStart - 1, end = start;
    long position = ((long) start << 32) + end;
    long[] positions = new long[] {position};
    if (this.evaluationContext.localVariableNames != null) {

      int varCount =
          this.evaluationContext.localVariableNames.length; // n local decls+ try statement

      // generate n local variable declarations: [type] [name] = val$[name];
      Statement[] newStatements = new Statement[varCount + 1];
      for (int i = 0; i < varCount; i++) {
        char[] trimmedTypeName = this.evaluationContext.localVariableTypeNames[i];
        int nameEnd = CharOperation.indexOf('[', trimmedTypeName);
        if (nameEnd >= 0) {
          trimmedTypeName = CharOperation.subarray(trimmedTypeName, 0, nameEnd);
        }
        nameEnd = CharOperation.indexOf(' ', trimmedTypeName);
        if (nameEnd >= 0) {
          trimmedTypeName = CharOperation.subarray(trimmedTypeName, 0, nameEnd);
        }
        TypeReference typeReference =
            new QualifiedTypeReference(CharOperation.splitOn('.', trimmedTypeName), positions);
        int dimCount =
            CharOperation.occurencesOf('[', this.evaluationContext.localVariableTypeNames[i]);
        if (dimCount > 0) {
          typeReference = this.copyDims(typeReference, dimCount);
        }
        NameReference init =
            new SingleNameReference(
                CharOperation.concat(
                    LOCAL_VAR_PREFIX, this.evaluationContext.localVariableNames[i]),
                position);
        LocalDeclaration declaration =
            new LocalDeclaration(this.evaluationContext.localVariableNames[i], start, end);
        declaration.initialization = init;
        declaration.type = typeReference;
        declaration.modifiers = this.evaluationContext.localVariableModifiers[i];
        newStatements[i] = declaration;
      }

      // generate try { [snippet] } finally { [save locals to fields] }
      // try block
      TryStatement tryStatement = new TryStatement();
      Block tryBlock = new Block(methodDecl.explicitDeclarations);
      tryBlock.sourceStart = start;
      tryBlock.sourceEnd = end;
      tryBlock.statements = methodDecl.statements; // snippet statements
      tryStatement.tryBlock = tryBlock;
      // finally block
      Block finallyBlock = new Block(0);
      finallyBlock.sourceStart = start;
      finallyBlock.sourceEnd = end;
      finallyBlock.statements = new Statement[varCount];
      for (int i = 0; i < varCount; i++) {
        finallyBlock.statements[i] =
            new Assignment(
                new SingleNameReference(
                    CharOperation.concat(
                        LOCAL_VAR_PREFIX, this.evaluationContext.localVariableNames[i]),
                    position),
                new SingleNameReference(this.evaluationContext.localVariableNames[i], position),
                (int) position);
      }
      tryStatement.finallyBlock = finallyBlock;

      newStatements[varCount] = tryStatement;
      methodDecl.statements = newStatements;
    }
  }
Exemple #21
0
 /*
  * brakets leafUniqueKey
  * p.X[][] --> [[Lp/X;
  */
 public char[] computeUniqueKey(boolean isLeaf) {
   char[] brackets = new char[dimensions];
   for (int i = dimensions - 1; i >= 0; i--) brackets[i] = '[';
   return CharOperation.concat(brackets, this.leafComponentType.computeUniqueKey(isLeaf));
 }