Example usage for org.eclipse.jdt.core Signature getSignatureSimpleName

List of usage examples for org.eclipse.jdt.core Signature getSignatureSimpleName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core Signature getSignatureSimpleName.

Prototype

public static String getSignatureSimpleName(String typeSignature) 

Source Link

Document

Returns type fragment of a type signature.

Usage

From source file:at.bestsolution.fxide.jdt.editor.internal.MethodUtil.java

License:Open Source License

/**
 * Returns the simple erased name for a given type signature, possibly replacing type variables.
 *
 * @param signature the type signature/*from   w  w w.  j  av  a 2 s .  co m*/
 * @param typeVariables the Map<SimpleName, VariableName>
 * @return the simple erased name for signature
 */
private String computeSimpleTypeName(String signature, Map<String, char[]> typeVariables) {
    // method equality uses erased types
    String erasure = Signature.getTypeErasure(signature);
    erasure = erasure.replaceAll("/", "."); //$NON-NLS-1$//$NON-NLS-2$
    String simpleName = Signature.getSimpleName(Signature.toString(erasure));
    char[] typeVar = typeVariables.get(simpleName);
    if (typeVar != null)
        simpleName = String.valueOf(Signature.getSignatureSimpleName(typeVar));
    return simpleName;
}

From source file:at.bestsolution.fxide.jdt.editor.internal.SignatureUtil.java

License:Open Source License

/**
 * Returns the qualified signature corresponding to
 * <code>signature</code>.//from   w ww .  j ava2  s .c o m
 *
 * @param signature the signature to qualify
 * @param context the type inside which an unqualified type will be
 *        resolved to find the qualifier, or <code>null</code> if no
 *        context is available
 * @return the qualified signature
 */
public static String qualifySignature(final String signature, final IType context) {
    if (context == null)
        return signature;

    String qualifier = Signature.getSignatureQualifier(signature);
    if (qualifier.length() > 0)
        return signature;

    String elementType = Signature.getElementType(signature);
    String erasure = Signature.getTypeErasure(elementType);
    String simpleName = Signature.getSignatureSimpleName(erasure);
    String genericSimpleName = Signature.getSignatureSimpleName(elementType);

    int dim = Signature.getArrayCount(signature);

    try {
        String[][] strings = context.resolveType(simpleName);
        if (strings != null && strings.length > 0)
            qualifier = strings[0][0];
    } catch (JavaModelException e) {
        // ignore - not found
    }

    if (qualifier.length() == 0)
        return signature;

    String qualifiedType = Signature.toQualifiedName(new String[] { qualifier, genericSimpleName });
    String qualifiedSignature = Signature.createTypeSignature(qualifiedType, true);
    String newSignature = Signature.createArraySignature(qualifiedSignature, dim);

    return newSignature;
}

From source file:at.bestsolution.javafx.ide.jdt.internal.JavaEditor.java

License:Open Source License

@Inject
public JavaEditor(BorderPane pane, IEditorInput input) {
    editor = new SourceEditor();
    pane.setCenter(editor);//  ww  w .  j a  va2s.c  o  m

    IResourceFileInput fsInput = (IResourceFileInput) input;
    try {
        unit = ((ICompilationUnit) JavaCore.create(fsInput.getFile()))
                .getWorkingCopy(new FXWorkingCopyOwner(new IProblemRequestor() {
                    private List<ProblemMarker> l = new ArrayList<>();

                    @Override
                    public boolean isActive() {
                        // TODO Auto-generated method stub
                        return true;
                    }

                    @Override
                    public void endReporting() {
                        setMarkers(l);
                    }

                    @Override
                    public void beginReporting() {
                        l.clear();
                    }

                    @Override
                    public void acceptProblem(IProblem problem) {
                        int linenumber = problem.getSourceLineNumber();
                        int startCol = problem.getSourceStart();
                        int endCol = problem.getSourceEnd();

                        if (endCol == startCol) {
                            endCol++;
                        }

                        String description = problem.getMessage();
                        ProblemMarker marker = new ProblemMarker(
                                problem.isError() ? at.bestsolution.javafx.ide.editor.ProblemMarker.Type.ERROR
                                        : at.bestsolution.javafx.ide.editor.ProblemMarker.Type.WARNING,
                                linenumber, startCol, endCol, description);
                        l.add(marker);
                    }
                }), new NullProgressMonitor());
    } catch (JavaModelException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    final Document doc = createDocument(unit);
    editor.setDocument(doc);
    editor.setContentProposalComputer(new ContentProposalComputer() {

        @Override
        public List<Proposal> computeProposals(String line, String prefix, int offset) {
            final List<Proposal> l = new ArrayList<ContentProposalComputer.Proposal>();

            try {
                unit.codeComplete(offset, new CompletionRequestor() {

                    @Override
                    public void accept(CompletionProposal proposal) {
                        String completion = new String(proposal.getCompletion());

                        if (!Flags.isPublic(proposal.getFlags())) {
                            return;
                        }

                        if (proposal.getKind() == CompletionProposal.METHOD_REF) {
                            String sig = Signature.toString(new String(proposal.getSignature()),
                                    new String(proposal.getName()), null, false, false);
                            StyledString s = new StyledString(sig + " : " + Signature.getSimpleName(Signature
                                    .toString(Signature.getReturnType(new String(proposal.getSignature())))));
                            s.appendString(
                                    " - " + Signature.getSignatureSimpleName(
                                            new String(proposal.getDeclarationSignature())),
                                    Style.colored("#AAAAAA"));

                            l.add(new Proposal(Type.METHOD, completion, s));
                        } else if (proposal.getKind() == CompletionProposal.FIELD_REF) {
                            StyledString s = new StyledString(
                                    completion + " : "
                                            + (proposal.getSignature() != null
                                                    ? Signature.getSignatureSimpleName(
                                                            new String(proposal.getSignature()))
                                                    : "<unknown>"));
                            s.appendString(
                                    " - " + (proposal.getDeclarationSignature() != null
                                            ? Signature.getSignatureSimpleName(
                                                    new String(proposal.getDeclarationSignature()))
                                            : "<unknown>"),
                                    Style.colored("#AAAAAA"));
                            l.add(new Proposal(Type.FIELD, completion, s));
                        } else if (proposal.getKind() == CompletionProposal.TYPE_REF) {
                            if (proposal.getAccessibility() == IAccessRule.K_NON_ACCESSIBLE) {
                                return;
                            }

                            StyledString s = new StyledString(
                                    Signature.getSignatureSimpleName(new String(proposal.getSignature())));
                            s.appendString(" - " + new String(proposal.getDeclarationSignature()),
                                    Style.colored("#AAAAAA"));
                            l.add(new Proposal(Type.TYPE, new String(proposal.getCompletion()), s));
                        } else {
                            System.err.println(proposal);
                        }
                    }
                });
            } catch (JavaModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return l;
        }

    });
    editor.setSaveCallback(new Runnable() {

        @Override
        public void run() {
            try {
                unit.commitWorkingCopy(true, null);
            } catch (JavaModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });

    try {
        unit.reconcile(ICompilationUnit.NO_AST, true, null, null);
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.aqua.wikiwizard.JavaModelUtils.java

License:Apache License

/**
 * Returns the method return type// ww w .j  a v a  2s.c o m
 * @param method
 *          The given method
 * @return
 *          String
 * @throws JavaModelException
 */
public static String getMethodReturnTypeFullName(IMethod method) throws JavaModelException {
    String signature = method.getReturnType();
    String packageName = Signature.getSignatureQualifier(signature);
    return (packageName.trim().equals("") ? "" : packageName + ".")
            + Signature.getSignatureSimpleName(signature);
}

From source file:com.drgarbage.asm.render.impl.OutlineElementField.java

License:Apache License

@Override
public String getElementName() {
    StringBuffer buf = new StringBuffer(super.getElementName());
    buf.append(" : ");
    String sig = Signature.getSignatureSimpleName(typeSignature);
    //TODO: convert to unqualified name, Define preference
    buf.append(sig);/*from   w  w w  .  j a va  2  s.c o  m*/
    return buf.toString();
}

From source file:com.github.ajaxsys.jdtx.utils.JDTUtils.java

License:Open Source License

/**
 * @param typeSignature/* w ww  .  j a  v a2 s. c  om*/
 *            Some of the type signatures examples are "QString;" (String)
 *            and "I" (int) The type signatures may be either unresolved
 *            (for source types) or resolved (for binary types), and either
 *            basic (for basic types) or rich (for parameterized types). See
 *            {@link Signature} for details.
 */
public static String getHumanReadableType(String typeSignature) {
    String simpleName = Signature.getSignatureSimpleName(typeSignature);
    return simpleName;
}

From source file:com.github.ajaxsys.jdtx.utils.JDTUtils.java

License:Open Source License

/**
 * Find the IMethod in the workspace corresponding to a method selector.
 *
 * TODO: this is way too slow. figure out something better.
 *
 * @return null if not found//from  w  w w. jav  a  2s .  com
 */
public static IMethod findJavaMethodInProjects(String klass, String selector,
        Collection<IJavaProject> projects) {

    if (klass == null) {
        throw new IllegalArgumentException("null klass");
    }
    if (projects == null) {
        throw new IllegalArgumentException("null projects");
    }
    IType type = null;
    try {
        type = findJavaClassInProjects(klass, projects);
    } catch (Throwable t) {
        return null;
    }
    if (type == null) {
        return null;
    }
    String name = parseForName(selector, type);
    String[] paramTypes = parseForParameterTypes(selector);
    IMethod m = type.getMethod(name, paramTypes);
    IMethod[] methods = type.findMethods(m);
    if (methods != null && methods.length == 1) {
        return methods[0];
    } else {
        // methods is null. probably got screwed by generics.
        // i spent 5 hours trying to figure out how to fix this correctly
        // and failed. implementing a miserable hack instead.
        // Need to consult a guru to figure out how to do this.
        try {
            List<IMethod> matches = new ArrayList<IMethod>();
            Collection<String> typeParameterNames = getTypeParameterNames(type);
            METHODS: for (IMethod x : type.getMethods()) {
                if (x.getElementName().equals(name)) {
                    if (x.getParameterTypes().length == paramTypes.length) {
                        for (int i = 0; i < x.getParameterTypes().length; i++) {
                            String s1 = Signature
                                    .getTypeErasure(Signature.getSignatureSimpleName(x.getParameterTypes()[i]));
                            String s2 = Signature
                                    .getTypeErasure(Signature.getSignatureSimpleName(paramTypes[i]));
                            if (typeParameterNames.contains(s1)) {
                                // s1 is a type parameter to the class.
                                // optimistically assume
                                // the types match.
                            } else {
                                if (!s1.equals(s2)) {
                                    // no match
                                    continue METHODS;
                                }
                            }
                        }
                        matches.add(x);
                    }
                }
            }
            if (matches.size() == 1) {
                return matches.get(0);
            } else {
                System.err.println("findJavaMethodInWorkspace FAILED TO MATCH " + m);
                return null;
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
            return null;
        }
    }
}

From source file:com.google.gdt.eclipse.core.java.JavaModelSearch.java

License:Open Source License

/**
 * Extract the fully-qualified type name out of a type signature, with dots as
 * package separators.//from  www . j a  va2  s  .  co m
 */
public static String getQualifiedTypeName(String typeSignature) {
    // Make sure we're using dots for package separator, not /'s
    typeSignature = typeSignature.replace('/', '.');

    String pckg = Signature.getSignatureQualifier(typeSignature);
    String typeName = Signature.getSignatureSimpleName(typeSignature);

    if (pckg == null || pckg.length() == 0) {
        return typeName;
    }

    return pckg + "." + typeName;
}

From source file:com.google.gwt.eclipse.core.uibinder.contentassist.computers.SetterAttributeProposalComputer.java

License:Open Source License

/**
 * Determines whether a setter's parameter signature can be parsed from an
 * attribute based on the GWT AttributeParsers implementation.
 *//*from w w w . j  a  v  a 2s. c  o  m*/
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());
}

From source file:com.google.gwt.eclipse.core.validators.rpc.RemoteServiceUtilities.java

License:Open Source License

private static String resolveToQualifiedErasure(IType context, String typeSignature)
        throws RemoteServiceException {
    try {/*w  w w .  j a va 2 s  . c o m*/
        String typeErasureSig = Signature.getTypeErasure(typeSignature);
        String type = Signature.getSignatureSimpleName(typeErasureSig);
        String qualifiedErasure = JavaModelSearch.resolveTypeName(context, type);
        if (qualifiedErasure == null) {
            throw new RemoteServiceException("Could not resolve type " + type);
        }
        return qualifiedErasure;
    } catch (JavaModelException e) {
        throw new RemoteServiceException(e);
    }
}