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

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

Introduction

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

Prototype

String SIG_VOID

To view the source code for org.eclipse.jdt.core Signature SIG_VOID.

Click Source Link

Document

String constant for the signature of result type void.

Usage

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java

License:Open Source License

private boolean needsReturnTag() {
    if (fMethod == null)
        return false;
    try {//from  ww w . ja  v a  2 s  .c o  m
        return !Signature.SIG_VOID.equals(fMethod.getReturnType());
    } catch (JavaModelException e) {
        //TODO
        e.printStackTrace();
        return false;
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.Member.java

License:Open Source License

protected boolean isMainMethod(IMethod method) throws JavaModelException {
    if ("main".equals(method.getElementName()) && Signature.SIG_VOID.equals(method.getReturnType())) { //$NON-NLS-1$
        int flags = method.getFlags();
        IType declaringType = null;/*from ww  w . j a  v a 2  s  . c o m*/
        if (Flags.isStatic(flags) && (Flags.isPublic(flags)
                || ((declaringType = getDeclaringType()) != null && declaringType.isInterface()))) {
            String[] paramTypes = method.getParameterTypes();
            if (paramTypes.length == 1) {
                String typeSignature = Signature.toString(paramTypes[0]);
                return "String[]".equals(Signature.getSimpleName(typeSignature)); //$NON-NLS-1$
            }
        }
    }
    return false;
}

From source file:com.codenvy.ide.ext.java.server.javadoc.JavadocContentAccess2.java

License:Open Source License

private boolean needsReturnTag() {
    if (fMethod == null)
        return false;
    try {//from w ww.ja  v a 2 s.c o m
        return !Signature.SIG_VOID.equals(fMethod.getReturnType());
    } catch (JavaModelException e) {
        LOG.error(e.getMessage(), e);
        return false;
    }
}

From source file:com.ecfeed.ui.common.JavaModelAnalyser.java

License:Open Source License

public static IMethod getIMethod(MethodNode method) {
    IType parentType = getIType(method.getClassNode().getName());

    if (parentType == null) {
        return null;
    }/*from   w w  w.  j  a  v a2 s  .  c o  m*/

    try {
        for (IMethod methodDef : parentType.getMethods()) {
            if (methodDef.getElementName().equals(method.getName()) == false
                    || methodDef.getReturnType().equals(Signature.SIG_VOID) == false) {
                continue;
            }
            List<String> parameterTypes = new ArrayList<>();
            for (ILocalVariable parameter : methodDef.getParameters()) {
                parameterTypes.add(getTypeName(methodDef, parameter));
            }
            if (parameterTypes.equals(method.getParametersTypes())) {
                return methodDef;
            }
        }
    } catch (JavaModelException e) {
        SystemLogger.logCatch(e.getMessage());
    }
    return null;
}

From source file:com.ecfeed.ui.common.JavaModelAnalyser.java

License:Open Source License

public static boolean isVoid(IMethod method) {
    try {/*w w  w .j  a v  a 2  s  .c o m*/
        return !method.getElementName().equals(method.getParent().getElementName())
                && method.getReturnType().equals(Signature.SIG_VOID);
    } catch (JavaModelException e) {
        SystemLogger.logCatch(e.getMessage());
    }
    return false;
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.RequestFactoryUtils.java

License:Open Source License

public static boolean isGetterMethod(IMethod method) throws JavaModelException {

    if (!isPublicInstanceMethod(method) || hasParams(method)) {
        return false;
    }/* ww  w.  ja v a 2  s .c o m*/

    String returnType = method.getReturnType();

    if (Signature.SIG_VOID.equals(returnType)) {
        return false;
    }

    String methodName = method.getElementName();

    // boolean getters {is,has}
    for (String prefix : BOOLEAN_GETTER_PREFIXES) {
        if (isPrefixedBy(methodName, prefix)) {
            return isBooleanReturnType(returnType);
        }
    }

    // standard getter {get}
    return isPrefixedBy(methodName, GETTER_PREFIX);
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.RequestFactoryUtils.java

License:Open Source License

public static boolean isSetterMethod(IMethod method) throws JavaModelException {
    return hasSetterFormat(method.getElementName()) && isPublicInstanceMethod(method)
            && Signature.SIG_VOID.equals(method.getReturnType());
}

From source file:com.google.gwt.eclipse.core.editors.java.JsniMethodBodyCompletionProposalComputer.java

License:Open Source License

public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context,
        IProgressMonitor monitor) {/* w ww.  j a  va  2s . c o  m*/
    if (!(context instanceof JavaContentAssistInvocationContext)) {
        // Not in a java content assist content.
        return NO_PROPOSALS;
    }

    try {
        JavaContentAssistInvocationContext jcaic = (JavaContentAssistInvocationContext) context;
        ICompilationUnit compilationUnit = jcaic.getCompilationUnit();

        /*
         * Resolves issue 3560,
         * http://code.google.com/p/google-web-toolkit/issues/detail?id=3650. We
         * need to have a reconciled compilation unit if we are to use it, but we
         * don't want to tickle the hierarchy view bug.
         */
        compilationUnit.reconcile(ICompilationUnit.NO_AST, false, null, null);

        int invocationOffset = jcaic.getInvocationOffset();
        IJavaElement elementAt = compilationUnit.getElementAt(invocationOffset);

        if (elementAt == null) {
            // Can't determine the element at the specified offset.
            return NO_PROPOSALS;
        }

        if (IJavaElement.METHOD != elementAt.getElementType()) {
            // Not a method.
            return NO_PROPOSALS;
        }

        IMethod method = (IMethod) elementAt;

        IType thisType = method.getDeclaringType();
        if (thisType.isInterface()) {
            // Don't propose anything for interfaces.
            return NO_PROPOSALS;
        }

        ISourceRange sourceRange = method.getSourceRange();
        if (sourceRange == null) {
            // No source code.
            // TODO: Is this possible?
            return NO_PROPOSALS;
        }

        String methodSource = method.getSource();
        int invocationIdx = invocationOffset - sourceRange.getOffset();

        // Sometimes, if incomplete JSNI method has /* and is followed by any global 
        // comment of format /*..*/, compilation unit separates the code after
        // incomplete JSNI method's /* as a separate block from the incomplete method.
        // So we need to check whether the block before the invocation offset's block
        // is the incomplete JSNI method that we are interested in.

        IJavaElement prevElement = compilationUnit.getElementAt(sourceRange.getOffset() - 1);
        if (prevElement != null && IJavaElement.METHOD == prevElement.getElementType()) {

            IMethod prevMethod = (IMethod) prevElement;

            if ((prevMethod.getDeclaringType().isInterface() == false)
                    && (Flags.isNative(prevMethod.getFlags()) == true)) {

                String prevMethodSource = prevMethod.getSource();
                if (prevMethodSource.trim().endsWith(")") == true) {
                    methodSource = prevMethodSource.concat(methodSource);
                    method = prevMethod;
                    invocationIdx += prevMethodSource.length();
                }
            }
        }

        int flags = method.getFlags();
        if (!Flags.isNative(flags)) {
            // If the method is not native then no proposals.
            return NO_PROPOSALS;
        }

        // Eliminating comments that might precede native method declaration, so that
        // following code can safely assume first ')' found is that of function declaration.
        int idxMultiLineComment = methodSource.trim().indexOf("/*");
        int idxSingleLineComment = methodSource.trim().indexOf("//");
        while ((idxMultiLineComment == 0) || (idxSingleLineComment == 0)) {
            if (idxMultiLineComment == 0) {
                invocationIdx -= methodSource.indexOf("*/") + 2;
                methodSource = methodSource.substring(methodSource.indexOf("*/") + 2);
            } else {
                invocationIdx -= methodSource.indexOf('\n') + 1;
                methodSource = methodSource.substring(methodSource.indexOf('\n') + 1);
            }
            idxMultiLineComment = methodSource.trim().indexOf("/*");
            idxSingleLineComment = methodSource.trim().indexOf("//");
        }

        // Eliminating any JSNI method that might follow the JSNI method in consideration.
        int jsniMethodOpenIdx = methodSource.indexOf(JSNI_METHOD_OPEN_BRACE);
        if (jsniMethodOpenIdx != -1) {
            int jsniMethodCloseBracketIdx = methodSource.indexOf(")");
            String tempString = methodSource.substring(jsniMethodCloseBracketIdx, jsniMethodOpenIdx);
            if (tempString.trim().length() != 1) {
                methodSource = methodSource.substring(0, jsniMethodOpenIdx - 1);
            } else {
                int nextJsniMethodOpenIdx = methodSource.substring(jsniMethodOpenIdx + 4)
                        .indexOf(JSNI_METHOD_OPEN_BRACE);
                if (nextJsniMethodOpenIdx != -1) {
                    nextJsniMethodOpenIdx += jsniMethodOpenIdx + 4;
                    methodSource = methodSource.substring(0, nextJsniMethodOpenIdx - 1);
                }
            }
        }

        // Check if the JSNI method is already complete.
        if (methodSource.indexOf("}-*/;") != -1) {
            // JSNI method is complete.
            return NO_PROPOSALS;
        }

        // Check position of invocation offset.
        int numCharsFilled = 0, numCharsToOverwrite = 0;

        String tempString = "";
        if (methodSource.substring(methodSource.indexOf(")") + 1).trim().indexOf("/") != -1) {
            tempString = methodSource.substring(methodSource.indexOf(")"), methodSource.indexOf("/"));
        }

        if ((methodSource.substring(methodSource.indexOf(")") + 1).trim().indexOf("/") == 0)
                && (tempString.indexOf('\n') == -1)) {

            int jsniMethodOpenSlashIdx = methodSource.indexOf("/");

            if (jsniMethodOpenSlashIdx > invocationIdx) {
                // Invocation index is placed before JSNI open slash.
                return NO_PROPOSALS;
            }

            String jsniCompletedString = methodSource.substring(jsniMethodOpenSlashIdx, invocationIdx);

            if (jsniCompletedString.indexOf(JSNI_METHOD_OPEN_BRACE) != -1) {
                jsniCompletedString = jsniCompletedString.trim();
            }

            if (JSNI_METHOD_OPEN_BRACE.startsWith(jsniCompletedString)) {
                numCharsFilled = jsniCompletedString.length();
            } else {
                // Invocation index placement does not allow auto-completion.
                return NO_PROPOSALS;
            }
        } else {
            int jsniMethodCloseBracketIdx = methodSource.indexOf(")") + 1;

            if (jsniMethodCloseBracketIdx > invocationIdx) {
                // Invocation index is not placed after method's close bracket.
                return NO_PROPOSALS;
            }
            if (methodSource.substring(jsniMethodCloseBracketIdx, invocationIdx).trim().length() != 0) {
                // Do not auto-complete if there is anything other than space between the two indices.
                return NO_PROPOSALS;
            }
        }

        methodSource = methodSource.substring(invocationIdx);
        int endIdx = methodSource.length();
        if (methodSource.indexOf(" ") != -1) {
            endIdx = methodSource.indexOf(" ");
            if (methodSource.indexOf("\n") != -1 && (endIdx > methodSource.indexOf("\n"))) {
                endIdx = methodSource.indexOf("\n");
            }
        } else if (methodSource.indexOf("\n") != -1) {
            endIdx = methodSource.indexOf("\n");
        }

        numCharsToOverwrite = methodSource.substring(0, endIdx).trim().length();

        IDocument document = jcaic.getDocument();
        int lineOfInvocationOffset = document.getLineOfOffset(invocationOffset);
        int lineOffset = document.getLineOffset(lineOfInvocationOffset);

        IJavaProject project = jcaic.getProject();
        int indentationUnits = measureIndentationUnits(document, lineOfInvocationOffset, lineOffset, project);

        List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();

        proposeEmptyJsniBlock(project, method, invocationOffset, indentationUnits, proposals, numCharsFilled,
                numCharsToOverwrite);

        boolean isStatic = Flags.isStatic(flags);
        if (method.getReturnType().equals(Signature.SIG_VOID)) {
            proposeSetters(project, method, invocationOffset, indentationUnits, isStatic, proposals,
                    numCharsFilled, numCharsToOverwrite);
        } else {
            proposeGetters(project, method, invocationOffset, indentationUnits, isStatic, proposals,
                    numCharsFilled, numCharsToOverwrite);
        }
        return proposals;
    } catch (JavaModelException e) {
        // Default to no proposals.
    } catch (BadLocationException e) {
        // Default to no proposals.
    }

    return NO_PROPOSALS;
}

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

License:Open Source License

/**
 * Determines whether the argument is a setter method based on heuristics
 * similar to GWT's OwnerFieldClass.//from   w  w w.  j a v  a  2  s . c  o  m
 */
private boolean isSetterMethod(IMethod method) throws JavaModelException {
    // All setter methods should be public void setSomething(...)
    // (com.google.gwt.uibinder.rebind.model.OwnerFieldClass.isSetterMethod)
    String methodName = method.getElementName();

    return methodName.startsWith(SETTER_PREFIX) && methodName.length() > SETTER_PREFIX_LENGTH
            && Character.isUpperCase(methodName.charAt(SETTER_PREFIX_LENGTH))
            && Flags.isPublic(method.getFlags()) && !Flags.isStatic(method.getFlags())
            && Signature.SIG_VOID.equals(method.getReturnType());
}

From source file:com.google.gwt.eclipse.core.wizards.rpc.NewAsyncRemoteServiceInterfaceCreationWizardPage.java

License:Open Source License

public static String createMethodContents(IType newType, ImportManagerAdapter imports,
        IMethodBinding overridableSyncMethod, boolean addComments) throws CoreException, JavaModelException {
    StringBuilder sb = new StringBuilder();

    IMethod syncMethod = (IMethod) overridableSyncMethod.getJavaElement();

    if (addComments) {
        String lineDelimiter = "\n"; // OK, since content is formatted afterwards

        // Don't go through CodeGeneration type since it can't deal with delegates
        String comment = StubUtility.getMethodComment(newType.getCompilationUnit(),
                newType.getFullyQualifiedName(), syncMethod.getElementName(), NO_STRINGS, NO_STRINGS,
                Signature.SIG_VOID, NO_STRINGS, syncMethod, true, lineDelimiter);
        if (comment != null) {
            sb.append(comment);/*from   ww w. j a v  a 2 s.c  o m*/
            sb.append(lineDelimiter);
        }
    }

    // Expand the type parameters
    ITypeParameter[] typeParameters = syncMethod.getTypeParameters();
    ITypeBinding[] typeParameterBindings = overridableSyncMethod.getTypeParameters();
    if (typeParameters.length > 0) {
        sb.append("<");
        for (int i = 0; i < typeParameters.length; ++i) {
            sb.append(typeParameters[i].getElementName());
            ITypeBinding typeParameterBinding = typeParameterBindings[i];
            ITypeBinding[] typeBounds = typeParameterBinding.getTypeBounds();
            if (typeBounds.length > 0) {
                sb.append(" extends ");
                for (int j = 0; j < typeBounds.length; ++j) {
                    if (j != 0) {
                        sb.append(" & ");
                    }
                    expandTypeBinding(typeBounds[j], sb, imports);
                }
            }
        }
        sb.append(">");
    }

    // Default to a void return type for the async method
    sb.append("void ");

    // Expand the method name
    sb.append(overridableSyncMethod.getName());

    // Expand the arguments
    sb.append("(");
    String[] parameterNames = syncMethod.getParameterNames();
    ITypeBinding[] parameterTypes = overridableSyncMethod.getParameterTypes();
    for (int i = 0; i < parameterNames.length; ++i) {
        if (i != 0) {
            sb.append(", ");
        }

        expandTypeBinding(parameterTypes[i], sb, imports);
        sb.append(" ");
        sb.append(parameterNames[i]);
    }

    if (parameterNames.length > 0) {
        sb.append(", ");
    }

    sb.append(imports.addImport(RemoteServiceUtilities.ASYNCCALLBACK_QUALIFIED_NAME));
    sb.append("<");
    ITypeBinding syncReturnType = overridableSyncMethod.getReturnType();
    if (syncReturnType.isPrimitive()) {
        String wrapperTypeName = JavaASTUtils.getWrapperTypeName(syncReturnType.getName());
        sb.append(imports.addImport(wrapperTypeName));
    } else {
        expandTypeBinding(syncReturnType, sb, imports);
    }
    sb.append("> ");
    sb.append(StringUtilities.computeUniqueName(parameterNames, "callback"));
    sb.append(");");

    return sb.toString();
}