Java 类org.eclipse.jdt.core.Signature 实例源码

项目:java-builders-generator    文件:GenerateBuildersHandler.java   
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {

    final IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
    final ICompilationUnit icu = JavaUI.getWorkingCopyManager().getWorkingCopy(editorPart.getEditorInput());

    try {
        final IType type = icu.getTypes()[0];
        final List<Field> fields = new ArrayList<>();
        for (final IField field : type.getFields()) {
            final String fieldName = field.getElementName();
            final String fieldType = Signature.getSignatureSimpleName(field.getTypeSignature());
            fields.add(new Field(fieldName, fieldType));
        }

        new WizardDialog(HandlerUtil.getActiveShell(event), new BuilderGeneratorWizard(icu, fields)).open();

    }
    catch (final JavaModelException e) {
        e.printStackTrace();
    }

    return null;
}
项目:visuflow-plugin    文件:BreakpointLocator.java   
/**
 * Copied from org.eclipse.jdt.internal.debug.ui.actions.ToggleBreakpointAdapter
 * TODO: is there a public API to do this?
 *
 * Returns the resolved signature of the given method
 * @param method method to resolve
 * @return the resolved method signature or <code>null</code> if none
 * @throws JavaModelException
 * @since 3.4
 */
public static String resolveMethodSignature(IMethod method) throws JavaModelException {
    String signature = method.getSignature();
    String[] parameterTypes = Signature.getParameterTypes(signature);
    int length = parameterTypes.length;
    String[] resolvedParameterTypes = new String[length];
    for (int i = 0; i < length; i++) {
        resolvedParameterTypes[i] = resolveTypeSignature(method, parameterTypes[i]);
        if (resolvedParameterTypes[i] == null) {
            return null;
        }
    }
    String resolvedReturnType = resolveTypeSignature(method, Signature.getReturnType(signature));
    if (resolvedReturnType == null) {
        return null;
    }
    return Signature.createMethodSignature(resolvedParameterTypes, resolvedReturnType);
}
项目:pandionj    文件:StaticInvocationWidget.java   
public String getInvocationExpression() {
    String[] values = getValues();
    String[] parameterTypes = method.getParameterTypes();

    for(int i = 0; i < values.length; i++) {
        String pType = Signature.getSignatureSimpleName(parameterTypes[i]);
        values[i] = convertForTypedInvocation(values[i], pType);
    }

    try {
        return (method.isConstructor() ? "new " + method.getElementName() : methodName) + "(" + String.join(", ", values) + ")";
    } catch (JavaModelException e) {
        e.printStackTrace();
        return null;
    }
}
项目:eclemma    文件:SignatureResolver.java   
private static final void resolveParameterType(final IMethod method,
    final String parameterType, final StringBuilder result)
    throws JavaModelException {
  final char kind = parameterType.charAt(0);
  switch (kind) {
  case Signature.C_UNRESOLVED:
    final String identifier = parameterType.substring(1,
        parameterType.length() - 1);
    if (resolveType(method.getDeclaringType(), identifier, result)) {
      return;
    }
    if (resolveTypeParameter(method, identifier, result)) {
      return;
    }
    break;
  }
  result.append(parameterType);
}
项目:eclemma    文件:SignatureResolver.java   
private static final boolean resolveType(final IType scope,
    final String identifier, final StringBuilder result)
    throws JavaModelException {
  final String[][] types = scope.resolveType(Signature
      .getTypeErasure(identifier));
  if (types == null || types.length != 1) {
    return false;
  }
  result.append(Signature.C_RESOLVED);
  final String qualifier = types[0][0];
  if (qualifier.length() > 0) {
    replace(qualifier, Signature.C_DOT, SLASH, result);
    result.append(SLASH);
  }
  replace(types[0][1], Signature.C_DOT, Signature.C_DOLLAR, result);
  result.append(Signature.C_SEMICOLON);
  return true;
}
项目:google-cloud-eclipse    文件:LaunchPipelineShortcut.java   
private LaunchableResource toLaunchableResource(IResource resource) {
  if (resource == null) {
    return null;
  }
  IJavaElement javaElement = resource.getAdapter(IJavaElement.class);
  if (javaElement != null && javaElement.exists() && javaElement instanceof ICompilationUnit) {
    ICompilationUnit compilationUnit = (ICompilationUnit) javaElement;
    IType javaType = compilationUnit.findPrimaryType();
    if (javaType == null) {
      return null;
    }
    IMethod mainMethod = javaType.getMethod(
        "main", new String[] {Signature.createTypeSignature("String[]", false)});
    return new LaunchableResource(resource, mainMethod, javaType);
  }
  return new LaunchableResource(resource);
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
/**
 * Appends the parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param methodProposal the method proposal
 * @return the modified <code>buffer</code>
 */
private StringBuilder appendUnboundedParameterList(StringBuilder buffer, CompletionProposal methodProposal) {
    // TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
    // gets fixed.
    char[] signature= SignatureUtil.fix83600(methodProposal.getSignature());
    char[][] parameterNames= methodProposal.findParameterNames(null);
    char[][] parameterTypes= Signature.getParameterTypes(signature);

    for (int i= 0; i < parameterTypes.length; i++) {
        parameterTypes[i]= createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i]));
    }

    if (Flags.isVarargs(methodProposal.getFlags())) {
        int index= parameterTypes.length - 1;
        parameterTypes[index]= convertToVararg(parameterTypes[index]);
    }
    return appendParameterSignature(buffer, parameterTypes, parameterNames);
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
/**
 * Returns the display string for a java type signature.
 *
 * @param typeSignature the type signature to create a display name for
 * @return the display name for <code>typeSignature</code>
 * @throws IllegalArgumentException if <code>typeSignature</code> is not a
 *         valid signature
 * @see Signature#toCharArray(char[])
 * @see Signature#getSimpleName(char[])
 */
private char[] createTypeDisplayName(char[] typeSignature) throws IllegalArgumentException {
    char[] displayName= Signature.getSimpleName(Signature.toCharArray(typeSignature));

    // XXX see https://bugs.eclipse.org/bugs/show_bug.cgi?id=84675
    boolean useShortGenerics= false;
    if (useShortGenerics) {
        StringBuilder buf= new StringBuilder();
        buf.append(displayName);
        int pos;
        do {
            pos= buf.indexOf("? extends "); //$NON-NLS-1$
            if (pos >= 0) {
                buf.replace(pos, pos + 10, "+"); //$NON-NLS-1$
            } else {
                pos= buf.indexOf("? super "); //$NON-NLS-1$
                if (pos >= 0)
                {
                    buf.replace(pos, pos + 8, "-"); //$NON-NLS-1$
                }
            }
        } while (pos >= 0);
        return buf.toString().toCharArray();
    }
    return displayName;
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
private void createAnonymousTypeLabel(CompletionProposal proposal, CompletionItem item) {
    char[] declaringTypeSignature= proposal.getDeclarationSignature();
    declaringTypeSignature= Signature.getTypeErasure(declaringTypeSignature);
    String name = new String(Signature.getSignatureSimpleName(declaringTypeSignature));
    item.setInsertText(name);
    StringBuilder buf= new StringBuilder();
    buf.append(name);
    buf.append('(');
    appendUnboundedParameterList(buf, proposal);
    buf.append(')');
    buf.append("  "); //$NON-NLS-1$
    buf.append("Anonymous Inner Type"); //TODO: consider externalization
    item.setLabel(buf.toString());

    if (proposal.getRequiredProposals() != null) {
        char[] signatureQualifier= Signature.getSignatureQualifier(declaringTypeSignature);
        if (signatureQualifier.length > 0) {
            item.setDetail(String.valueOf(signatureQualifier));
        }
    }
    setDeclarationSignature(item, String.valueOf(declaringTypeSignature));
}
项目:eclipse.jdt.ls    文件:CompletionProposalReplacementProvider.java   
/**
 * @param completionBuffer
 * @param proposal
 */
private void appendMethodOverrideReplacement(StringBuilder completionBuffer, CompletionProposal proposal) {
    IDocument document;
    try {
        document = JsonRpcHelpers.toDocument(this.compilationUnit.getBuffer());
        String signature = String.valueOf(proposal.getSignature());
        String[] types = Stream.of(Signature.getParameterTypes(signature)).map(t -> Signature.toString(t))
                .toArray(String[]::new);
        String methodName = String.valueOf(proposal.getName());
        int offset = proposal.getReplaceStart();
        String completion = new String(proposal.getCompletion());
        OverrideCompletionProposal overrider = new OverrideCompletionProposal(compilationUnit, methodName, types,
                completion);
        String replacement = overrider.updateReplacementString(document, offset, importRewrite,
                client.isCompletionSnippetsSupported());
        completionBuffer.append(replacement);
    } catch (BadLocationException | CoreException e) {
        JavaLanguageServerPlugin.logException("Failed to compute override replacement", e);
    }
}
项目:eclipse.jdt.ls    文件:AnonymousTypeCompletionProposal.java   
private String createDummyType(String name) throws JavaModelException {
    StringBuffer buffer = new StringBuffer();
    buffer.append("abstract class "); //$NON-NLS-1$
    buffer.append(name);
    if (fSuperType.isInterface()) {
        buffer.append(" implements "); //$NON-NLS-1$
    } else {
        buffer.append(" extends "); //$NON-NLS-1$
    }
    if (fDeclarationSignature != null) {
        buffer.append(Signature.toString(fDeclarationSignature));
    } else {
        buffer.append(fSuperType.getFullyQualifiedParameterizedName());
    }
    buffer.append(" {"); //$NON-NLS-1$
    buffer.append("\n"); //$NON-NLS-1$
    buffer.append("}"); //$NON-NLS-1$
    return buffer.toString();
}
项目:eclipse.jdt.ls    文件:StubUtility.java   
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
    try {
        ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
        parser.setProject(overridden.getJavaProject());
        IBinding[] bindings = parser.createBindings(new IJavaElement[] { overridden }, null);
        if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
            return getParameterTypeNamesForSeeTag((IMethodBinding) bindings[0]);
        }
    } catch (IllegalStateException e) {
        // method does not exist
    }
    // fall back code. Not good for generic methods!
    String[] paramTypes = overridden.getParameterTypes();
    String[] paramTypeNames = new String[paramTypes.length];
    for (int i = 0; i < paramTypes.length; i++) {
        paramTypeNames[i] = Signature.toString(Signature.getTypeErasure(paramTypes[i]));
    }
    return paramTypeNames;
}
项目:eclipse.jdt.ls    文件:JavaElementLabelComposer.java   
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException {
    fBuilder.append('@');
    appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);
    IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs();
    if (memberValuePairs.length == 0) {
        return;
    }
    fBuilder.append('(');
    for (int i= 0; i < memberValuePairs.length; i++) {
        if (i > 0) {
            fBuilder.append(JavaElementLabels.COMMA_STRING);
        }
        IMemberValuePair memberValuePair= memberValuePairs[i];
        fBuilder.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
        fBuilder.append('=');
        appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags);
    }
    fBuilder.append(')');
}
项目:eclipse.jdt.ls    文件:SelfEncapsulateFieldProposal.java   
private void addNewJavadoc(ASTRewrite rewrite, MethodDeclaration decl, ImportRewriteContext context) throws CoreException {
    IType parentType = fField.getDeclaringType();

    String typeName = Signature.toString(fField.getTypeSignature());
    String accessorName = StubUtility.getBaseName(fField);
    String lineDelim = "\n";

    String comment = null;
    String name = getFunctionName();
    if (isGetter) {
        comment = CodeGeneration.getGetterComment(fField.getCompilationUnit(), parentType.getTypeQualifiedName('.'), name, fField.getElementName(), typeName, accessorName, lineDelim);
    } else {
        String argname = getArgumentName();
        comment = CodeGeneration.getSetterComment(fField.getCompilationUnit(), parentType.getTypeQualifiedName('.'), name, fField.getElementName(), typeName, argname, accessorName, lineDelim);
    }
    comment = comment.substring(0, comment.lastIndexOf(lineDelim));

    if (comment != null) {
        Javadoc javadoc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
        decl.setJavadoc(javadoc);
    }
}
项目:code    文件:SecurityAnalysis.java   
private String displayTraceItem(BaseTraceability traceItem) {
    StringBuffer sb = new StringBuffer();

    AstNode expr = traceItem.getExpression();
    if (expr != null) {
        BodyDeclaration enclDecl = expr.enclosingDeclaration;

        // Inline this?
        TypeDeclaration enclTypeDeclaration = MiniAstUtils.getEnclosingTypeDeclaration(expr);

        String type = Signature.getSimpleName(enclTypeDeclaration.getFullyQualifiedName());
        sb.append(type);
        sb.append("\t");
        if (enclDecl instanceof MethodDeclaration) {
            MethodDeclaration md = (MethodDeclaration) enclDecl;
            sb.append(md.methodName);
        }
        if (enclDecl instanceof FieldDeclaration) {
            FieldDeclaration fd = (FieldDeclaration)enclDecl;
            sb.append(fd.fieldName);
        }
        sb.append("\t");
        sb.append(expr);
    }
    return sb.toString();
}
项目:code    文件:ContentProviderOOGSearch.java   
private Set<DisplayEdge> getEdgesWithType(
        String inputElement) {
    Set<DisplayEdge> edges = RuntimeModel.getInstance().getDisplayModel().getEdges();
    Set<DisplayEdge> retEdges = new HashSet<DisplayEdge>();
    for(DisplayEdge edge: edges){
        DisplayObject toObject = edge.getToObject();
        DisplayObject fromObject = edge.getFromObject();
        String toTypeDisplayName = toObject.getTypeDisplayName();
        String fromTypeDisplayName = fromObject.getTypeDisplayName();
        String simpleName = Signature.getSimpleName(inputElement);
        if(toTypeDisplayName.contentEquals(simpleName)||
                fromTypeDisplayName.contentEquals(simpleName)){
            retEdges.add(edge);
        }
    }
    return retEdges;
}
项目:code    文件:LabelUtil.java   
public static String getSummaryViewLabel(Object element) {
    String label ="";
    if(element instanceof Info<?>){
        switch(((Info) element).getType()){
        case CLASS:
            label =  Signature.getSimpleName(((Info) element).getKey());
            break;
        case METHOD:
            label =  ((Info) element).getKey();
            break;

        }
    }else{
        label = element!=null? element.toString(): label;
    }
    return label;
}
项目:Migrate-Skeletal-Implementation-to-Interface-Refactoring    文件:TypeVariableUtil.java   
/**
 * Creates a type variable mapping from a domain to a range.
 *
 * @param domain
 *            the domain of the mapping
 * @param range
 *            the range of the mapping
 * @return a possibly empty type variable mapping
 */
private static TypeVariableMaplet[] signaturesToParameters(final String[] domain, final ITypeParameter[] range) {
    Assert.isNotNull(domain);
    Assert.isNotNull(range);

    final List<TypeVariableMaplet> list = new ArrayList<TypeVariableMaplet>();
    String source = null;
    String target = null;
    for (int index = 0; index < Math.min(domain.length, range.length); index++) {
        source = Signature.toString(domain[index]);
        target = range[index].getElementName();
        list.add(new TypeVariableMaplet(source, index, target, index));
    }
    final TypeVariableMaplet[] result = new TypeVariableMaplet[list.size()];
    list.toArray(result);
    return result;
}
项目:che    文件:MethodDeclarationCompletionProposal.java   
private static StyledString getDisplayName(String methodName, String returnTypeSig) {
  StyledString buf = new StyledString();
  buf.append(methodName);
  buf.append('(');
  buf.append(')');
  if (returnTypeSig != null) {
    buf.append(" : "); // $NON-NLS-1$
    buf.append(Signature.toString(returnTypeSig));
    buf.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$
    buf.append(
        JavaTextMessages.MethodCompletionProposal_method_label, StyledString.QUALIFIER_STYLER);
  } else {
    buf.append(" - ", StyledString.QUALIFIER_STYLER); // $NON-NLS-1$
    buf.append(
        JavaTextMessages.MethodCompletionProposal_constructor_label,
        StyledString.QUALIFIER_STYLER);
  }
  return buf;
}
项目:junit-tools    文件:JDTUtils.java   
public static String createParamList(IMethod method, boolean withParamTypes)
        throws JavaModelException {
    StringBuilder params = new StringBuilder();
    String comma = "";
    for (ILocalVariable variable : method.getParameters()) {
        params.append(comma);
        comma = ", ";

        if (withParamTypes) {
            params.append(
                    Signature.getSignatureSimpleName(variable
                            .getTypeSignature())).append(" ");
        }

        params.append(variable.getElementName());
    }

    return params.toString();
}
项目:che    文件:JavaNavigation.java   
private Method convertToDTOMethod(IMethod iMethod) throws JavaModelException {
  Method method = DtoFactory.newDto(Method.class);

  setRootPath(iMethod, method);

  method.setFileRegion(convertToDTORegion(iMethod.getNameRange()));
  method.setElementName(iMethod.getElementName());
  method.setReturnType(Signature.toString(iMethod.getReturnType()));
  method.setHandleIdentifier(iMethod.getHandleIdentifier());
  method.setFlags(iMethod.getFlags());
  method.setLabel(
      org.eclipse.jdt.ui.JavaElementLabels.getElementLabel(
          iMethod, org.eclipse.jdt.ui.JavaElementLabels.ALL_DEFAULT));

  return method;
}
项目:che    文件:JavaMethodCompletionProposal.java   
@Override
protected String computeSortString() {
  /*
   * Lexicographical sort order:
   * 1) by relevance (done by the proposal sorter)
   * 2) by method name
   * 3) by parameter count
   * 4) by parameter type names
   */
  char[] name = fProposal.getName();
  char[] parameterList =
      Signature.toCharArray(fProposal.getSignature(), null, null, false, false);
  int parameterCount =
      Signature.getParameterCount(fProposal.getSignature())
          % 10; // we don't care about insane methods with >9 parameters
  StringBuffer buf = new StringBuffer(name.length + 2 + parameterList.length);

  buf.append(name);
  buf.append('\0'); // separator
  buf.append(parameterCount);
  buf.append(parameterList);
  return buf.toString();
}
项目:che    文件:Util.java   
private static int appendTypeArgumentSignatureForAnchor(
    char[] string, int start, StringBuffer buffer) {
  // need a minimum 1 char
  if (start >= string.length) {
    throw new IllegalArgumentException();
  }
  char c = string[start];
  switch (c) {
    case Signature.C_STAR:
      return start;
    case Signature.C_EXTENDS:
      return appendTypeSignatureForAnchor(string, start + 1, buffer, false);
    case Signature.C_SUPER:
      return appendTypeSignatureForAnchor(string, start + 1, buffer, false);
    default:
      return appendTypeSignatureForAnchor(string, start, buffer, false);
  }
}
项目:gwt-eclipse-plugin    文件:SetterAttributeProposalComputer.java   
/**
 * Determines whether a setter's parameter signature can be parsed from an
 * attribute based on the GWT AttributeParsers implementation.
 */
private boolean isParsableSetter(IMethod method) {
  StringBuffer signature = new StringBuffer();

  for (String paramType : method.getParameterTypes()) {
    if (signature.length() > 0) {
      signature.append(',');
    }

    String qualifier = Signature.getSignatureQualifier(paramType);
    if (qualifier.length() > 0) {
      signature.append(qualifier);
      signature.append('.');
    }

    signature.append(Signature.getSignatureSimpleName(paramType));
  }

  return PARSABLE_ARGS.contains(signature.toString());
}
项目:gwt-eclipse-plugin    文件:JsniCompletionProposalCollector.java   
@Override
protected IJavaCompletionProposal createJavaCompletionProposal(
    CompletionProposal proposal) {
  IJavaCompletionProposal defaultProposal = super.createJavaCompletionProposal(proposal);

  // For members of inner classes, there's a bug in the JDT which results in
  // the declaration signature of the proposal missing the outer classes, so
  // we have to manually set the signature instead.
  if (proposal.getKind() == CompletionProposal.METHOD_REF
      || proposal.getKind() == CompletionProposal.FIELD_REF) {
    char[] typeSignature = Signature.createTypeSignature(qualifiedTypeName,
        true).toCharArray();
    proposal.setDeclarationSignature(typeSignature);
  }

  return JsniCompletionProposal.create(defaultProposal, proposal,
      getCompilationUnit().getJavaProject(), refOffset, refLength);
}
项目:che    文件:MethodProposalInfo.java   
/**
 * Resolves the member described by the receiver and returns it if found. Returns <code>null
 * </code> if no corresponding member can be found.
 *
 * @return the resolved member or <code>null</code> if none is found
 * @throws org.eclipse.jdt.core.JavaModelException if accessing the java model fails
 */
@Override
protected IMember resolveMember() throws JavaModelException {
  char[] declarationSignature = fProposal.getDeclarationSignature();
  String typeName = SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature));
  IType type = fJavaProject.findType(typeName);
  if (type != null) {
    String name = String.valueOf(fProposal.getName());
    String[] parameters =
        Signature.getParameterTypes(
            String.valueOf(SignatureUtil.fix83600(fProposal.getSignature())));
    for (int i = 0; i < parameters.length; i++) {
      parameters[i] = SignatureUtil.getLowerBound(parameters[i]);
    }
    boolean isConstructor = fProposal.isConstructor();

    return findMethod(name, parameters, isConstructor, type);
  }

  return null;
}
项目:che    文件:CompilationUnitCompletion.java   
/**
 * Returns the type names of all member type bounds, as they would be appear when referenced in
 * the current compilation unit.
 *
 * @return type names of all member type bounds
 */
public String[] getMemberTypeNames() {
  String[] signatures = getMemberTypeSignatures();
  String[] names = new String[signatures.length];

  for (int i = 0; i < signatures.length; i++) {
    String sig = signatures[i];
    String local = fLocalTypes.get(Signature.getElementType(sig));
    int dim = Signature.getArrayCount(sig);
    if (local != null && dim > 0) {
      StringBuffer array = new StringBuffer(local);
      for (int j = 0; j < dim; j++) array.append("[]"); // $NON-NLS-1$
      local = array.toString();
    }
    if (local != null) names[i] = local;
    else names[i] = Signature.getSimpleName(Signature.getSignatureSimpleName(sig));
  }
  return names;
}
项目:vsminecraft    文件:JavaElementLabelComposer.java   
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException {
    fBuffer.append('@');
    appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);
    IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs();
    if (memberValuePairs.length == 0)
        return;
    fBuffer.append('(');
    for (int i= 0; i < memberValuePairs.length; i++) {
        if (i > 0)
            fBuffer.append(COMMA_STRING);
        IMemberValuePair memberValuePair= memberValuePairs[i];
        fBuffer.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
        fBuffer.append('=');
        appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags);
    }
    fBuffer.append(')');
}
项目:che    文件:TypeVariableResolver.java   
private void resolve(MultiVariable mv, JavaVariable master, int index, JavaContext context) {
  Object[] choices = master.getChoices();
  if (choices instanceof Variable[]) {
    context.addDependency(master, mv);
    Variable[] variables = (Variable[]) choices;
    String type = master.getParamType();
    for (int i = 0; i < choices.length; i++) {
      String[] bounds = variables[i].getTypeArgumentBoundSignatures(type, index);
      for (int j = 0; j < bounds.length; j++)
        bounds[j] = Signature.getSignatureSimpleName(bounds[j]);
      mv.setChoices(variables[i], bounds);
    }
    mv.setKey(master.getCurrentChoice());
  } else {
    super.resolve(mv, context);
    return;
  }
}
项目:che    文件:JavaContext.java   
private String[] suggestVariableName(String type, String[] excludes)
    throws IllegalArgumentException {
  int dim = 0;
  while (type.endsWith("[]")) { // $NON-NLS-1$
    dim++;
    type = type.substring(0, type.length() - 2);
  }

  IJavaProject project = getJavaProject();
  if (project != null)
    return StubUtility.getVariableNameSuggestions(
        NamingConventions.VK_LOCAL, project, type, dim, Arrays.asList(excludes), true);

  // fallback if we lack proper context: roll-our own lowercasing
  return new String[] {Signature.getSimpleName(type).toLowerCase()};
}
项目:datahierarchy    文件:FieldReferencesRequestor.java   
private boolean isTypeAccepted(IField field) {
    String signature = SearchUtils.getTypeSignature(field);
    if (signature == null) {
        return false;
    }

    boolean isPrimitive = SearchUtils.isPrimitive(signature);
    if (!searchPrimitivesToo && isPrimitive) {
        return false;
    }
    int arrayCount = Signature.getArrayCount(signature);
    if (arrayCount > 0) {
        return searchArrays;
    }

    // have to resolve types now...
    String resolvedType = SearchUtils.getResolvedType(signature, field);
    if (resolvedType == null || isFiltered(resolvedType)) {
        return false;
    }
    return true;
}
项目:che    文件:UnresolvedElementsSubProcessor.java   
static CompilationUnitChange createAddImportChange(
    ICompilationUnit cu, Name name, String fullyQualifiedName) throws CoreException {
  String[] args = {
    BasicElementLabels.getJavaElementName(Signature.getSimpleName(fullyQualifiedName)),
    BasicElementLabels.getJavaElementName(Signature.getQualifier(fullyQualifiedName))
  };
  String label =
      Messages.format(
          CorrectionMessages.UnresolvedElementsSubProcessor_importtype_description, args);

  CompilationUnitChange cuChange = new CompilationUnitChange(label, cu);
  ImportRewrite importRewrite =
      StubUtility.createImportRewrite((CompilationUnit) name.getRoot(), true);
  importRewrite.addImport(fullyQualifiedName);
  cuChange.setEdit(importRewrite.rewriteImports(null));
  return cuChange;
}
项目:che    文件:JavaElementLabelComposer.java   
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException {
  fBuffer.append('@');
  appendTypeSignatureLabel(
      annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);
  IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
  if (memberValuePairs.length == 0) return;
  fBuffer.append('(');
  for (int i = 0; i < memberValuePairs.length; i++) {
    if (i > 0) fBuffer.append(JavaElementLabels.COMMA_STRING);
    IMemberValuePair memberValuePair = memberValuePairs[i];
    fBuffer.append(
        getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
    fBuffer.append('=');
    appendAnnotationValue(
        annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags);
  }
  fBuffer.append(')');
}
项目:che    文件:StubUtility.java   
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
  try {
    CheASTParser parser = CheASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
    parser.setProject(overridden.getJavaProject());
    IBinding[] bindings = parser.createBindings(new IJavaElement[] {overridden}, null);
    if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
      return getParameterTypeNamesForSeeTag((IMethodBinding) bindings[0]);
    }
  } catch (IllegalStateException e) {
    // method does not exist
  }
  // fall back code. Not good for generic methods!
  String[] paramTypes = overridden.getParameterTypes();
  String[] paramTypeNames = new String[paramTypes.length];
  for (int i = 0; i < paramTypes.length; i++) {
    paramTypeNames[i] = Signature.toString(Signature.getTypeErasure(paramTypes[i]));
  }
  return paramTypeNames;
}
项目:che    文件:ChangeSignatureProcessor.java   
public String getNewMethodSignature() throws JavaModelException {
  StringBuffer buff = new StringBuffer();

  buff.append(getVisibilityString(fVisibility));
  int flags = getMethod().getFlags();
  if (Flags.isStatic(flags)) {
    buff.append("static "); // $NON-NLS-1$
  } else if (Flags.isDefaultMethod(flags)) {
    buff.append("default "); // $NON-NLS-1$
  }
  if (!getMethod().isConstructor()) buff.append(getReturnTypeString()).append(' ');

  buff.append(getMethodName())
      .append(Signature.C_PARAM_START)
      .append(getMethodParameters())
      .append(Signature.C_PARAM_END);

  buff.append(getMethodThrows());

  return BasicElementLabels.getJavaCodeString(buff.toString());
}
项目:che    文件:FillArgumentNamesCompletionProposalCollector.java   
private IJavaCompletionProposal createMethodReferenceProposal(CompletionProposal methodProposal) {
  String completion = String.valueOf(methodProposal.getCompletion());
  // super class' behavior if this is not a normal completion or has no
  // parameters
  if ((completion.length() == 0)
      || ((completion.length() == 1) && completion.charAt(0) == ')')
      || Signature.getParameterCount(methodProposal.getSignature()) == 0
      || getContext().isInJavadoc()) return super.createJavaCompletionProposal(methodProposal);

  LazyJavaCompletionProposal proposal = null;
  proposal =
      ParameterGuessingProposal.createProposal(
          methodProposal, getInvocationContext(), fIsGuessArguments);
  if (proposal == null) {
    proposal = new FilledArgumentNamesMethodProposal(methodProposal, getInvocationContext());
  }
  return proposal;
}
项目:gwt-eclipse-plugin    文件:JavaProjectUtilities.java   
/**
 * Creates an {@link ICompilationUnit} with the given fully qualified name and
 * code in the <code>javaProject</code>.
 *
 * @param javaProject java project to host the new class
 * @param fullyQualifiedClassName fully qualified name for the class
 * @param source code for the classs
 * @return newly created {@link ICompilationUnit}
 * @throws JavaModelException
 */
public static ICompilationUnit createCompilationUnit(
    IJavaProject javaProject, String fullyQualifiedClassName, String source)
    throws JavaModelException {
  IPackageFragmentRoot root = javaProject.findPackageFragmentRoot(javaProject.getPath());
  if (root == null) {
    addRawClassPathEntry(javaProject,
        JavaCore.newSourceEntry(javaProject.getPath()));
    root = javaProject.findPackageFragmentRoot(javaProject.getPath());
  }

  String qualifier = Signature.getQualifier(fullyQualifiedClassName);
  IProgressMonitor monitor = new NullProgressMonitor();
  IPackageFragment packageFragment = root.createPackageFragment(qualifier,
      true, monitor);
  String name = Signature.getSimpleName(fullyQualifiedClassName);
  ICompilationUnit cu = packageFragment.createCompilationUnit(name + ".java",
      source, false, monitor);
  JobsUtilities.waitForIdle();
  return cu;
}
项目:che    文件:RefactoringAvailabilityTester.java   
public static boolean isGeneralizeTypeAvailable(final IStructuredSelection selection)
    throws JavaModelException {
  if (selection.size() == 1) {
    final Object element = selection.getFirstElement();
    if (element instanceof IMethod) {
      final IMethod method = (IMethod) element;
      if (!method.exists()) return false;
      final String type = method.getReturnType();
      if (PrimitiveType.toCode(Signature.toString(type)) == null)
        return Checks.isAvailable(method);
    } else if (element instanceof IField) {
      final IField field = (IField) element;
      if (!field.exists()) return false;
      if (!JdtFlags.isEnum(field)) return Checks.isAvailable(field);
    }
  }
  return false;
}
项目:che    文件:StubCreator.java   
protected void appendExpression(String signature, boolean castNull) {
  switch (signature.charAt(0)) {
    case Signature.C_BOOLEAN:
      fBuffer.append("false"); // $NON-NLS-1$
      break;
    case Signature.C_BYTE:
    case Signature.C_CHAR:
    case Signature.C_DOUBLE:
    case Signature.C_FLOAT:
    case Signature.C_INT:
    case Signature.C_LONG:
    case Signature.C_SHORT:
      fBuffer.append("0"); // $NON-NLS-1$
      break;
    default:
      if (castNull) {
        fBuffer.append("("); // $NON-NLS-1$
        fBuffer.append(Signature.toString(signature));
        fBuffer.append(")"); // $NON-NLS-1$
      }
      fBuffer.append("null"); // $NON-NLS-1$
      break;
  }
}
项目:gwt-eclipse-plugin    文件:AbstractGWTPluginTestCase.java   
public void addToTestProject() throws Exception {
  IProject testProject = Util.getWorkspaceRoot().getProject(TEST_PROJECT_NAME);
  if (!testProject.exists()) {
    throw new Exception("The test project does not exist");
  }

  IJavaProject javaProject = JavaCore.create(testProject);

  IPath srcPath = new Path("/" + TEST_PROJECT_NAME + "/src");
  IPackageFragmentRoot pckgRoot = javaProject.findPackageFragmentRoot(srcPath);

  String packageName = Signature.getQualifier(typeName);
  String cuName = Signature.getSimpleName(typeName) + ".java";

  // If the package fragment already exists, this call does nothing
  IPackageFragment pckg = pckgRoot.createPackageFragment(packageName, false, null);

  cu = pckg.createCompilationUnit(cuName, contents, true, null);
  JobsUtilities.waitForIdle();
}