Example usage for org.eclipse.jdt.core ILocalVariable getFlags

List of usage examples for org.eclipse.jdt.core ILocalVariable getFlags

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ILocalVariable getFlags.

Prototype

int getFlags();

Source Link

Document

Returns the modifier flags for this local variable.

Usage

From source file:fr.obeo.ariadne.ide.connector.java.internal.explorer.JavaExplorer.java

License:Open Source License

/**
 * Explores the given Java constructor and create a matching Ariadne constructor in the given Ariadne
 * classifier./*ww  w.  ja va2 s . c  o m*/
 * 
 * @param iMethod
 *            The Java method to analyzed
 * @param classifier
 *            The Ariadne classifier
 * @param isInterface
 *            Indicates if the Java classifier containing the method is an interface
 * @param monitor
 *            The progress monitor
 */
private void exploreConstructor(IMethod iMethod, Classifier classifier, boolean isInterface,
        IProgressMonitor monitor) {
    Constructor constructor = null;
    for (Constructor aConstructor : classifier.getConstructors()) {
        if (aConstructor.getQualifiedName().equals(this.getQualifiedName(iMethod, isInterface))) {
            constructor = aConstructor;
        }
    }

    if (constructor == null) {
        constructor = CodeFactory.eINSTANCE.createConstructor();
        constructor.setQualifiedName(this.getQualifiedName(iMethod, isInterface));
        constructor.setName(iMethod.getElementName());
    }

    if (constructor != null) {
        String javadoc = this.getJavadoc(iMethod, monitor);
        constructor.setDescription(javadoc);
        constructor.setVersion(this.getVersionFromJavadoc(javadoc));
        constructor.setVisibility(this.getVisibility(iMethod, isInterface));

        try {
            int flags = iMethod.getFlags();

            constructor.setFinal(Flags.isFinal(flags));
            constructor.setStatic(Flags.isStatic(flags));
            if (Flags.isDeprecated(flags)) {
                // Add the property "Deprecated"
                this.addDeprecatedProperty(constructor);
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }

        try {
            // Explore parameters
            ILocalVariable[] parameters = iMethod.getParameters();
            // If we don't have any parameters yet, we create them
            if (parameters.length > 0 && constructor.getParameters().size() == 0) {
                for (ILocalVariable iLocalVariable : parameters) {
                    String typeSignature = iLocalVariable.getTypeSignature();

                    Parameter parameter = CodeFactory.eINSTANCE.createParameter();
                    parameter.setQualifiedName(Signature.toString(typeSignature));
                    parameter.setFinal(Flags.isFinal(iLocalVariable.getFlags()));
                    if (Flags.isDeprecated(iLocalVariable.getFlags())) {
                        // Add the property "Deprecated"
                        this.addDeprecatedProperty(parameter);
                    }
                    constructor.getParameters().add(parameter);

                    // Set the typing dependency
                    String signature = Signature.toString(iLocalVariable.getTypeSignature());
                    Classifier ariadneClassifier = this.getOrCreateClassifier(signature);
                    if (ariadneClassifier != null) {
                        parameter.getTypes().add(ariadneClassifier);
                    }
                }
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }
    }
}

From source file:fr.obeo.ariadne.ide.connector.java.internal.explorer.JavaExplorer.java

License:Open Source License

/**
 * Explores the given Java method and create a matching Ariadne operation in the given Ariadne classifier.
 * /*from   ww w. j a  v a 2  s . com*/
 * @param iMethod
 *            The Java method to analyzed
 * @param classifier
 *            The Ariadne classifier
 * @param isInterface
 *            Indicates if the Java classifier containing the method is an interface
 * @param monitor
 *            The progress monitor
 */
private void exploreOperation(IMethod iMethod, Classifier classifier, boolean isInterface,
        IProgressMonitor monitor) {
    Operation operation = null;
    List<Operation> operations = classifier.getOperations();
    for (Operation anOperation : operations) {
        if (anOperation.getQualifiedName().equals(this.getQualifiedName(iMethod, isInterface))) {
            operation = anOperation;
        }
    }

    if (operation == null) {
        operation = CodeFactory.eINSTANCE.createOperation();
        operation.setQualifiedName(this.getQualifiedName(iMethod, isInterface));
        operation.setName(iMethod.getElementName());
        classifier.getOperations().add(operation);
    }

    if (operation != null) {
        String javadoc = this.getJavadoc(iMethod, monitor);
        operation.setDescription(javadoc);
        operation.setVersion(this.getVersionFromJavadoc(javadoc));
        operation.setVisibility(this.getVisibility(iMethod, isInterface));

        try {
            int flags = iMethod.getFlags();

            operation.setFinal(Flags.isFinal(flags));
            operation.setStatic(Flags.isStatic(flags));
            if (Flags.isDeprecated(flags)) {
                // Add the property "Deprecated"
                this.addDeprecatedProperty(operation);
            }

            // Set the return type
            String returnType = Signature.toString(iMethod.getReturnType());
            Classifier ariadneClassifier = this.getOrCreateClassifier(returnType);
            if (ariadneClassifier != null) {
                operation.getReturnTypes().add(ariadneClassifier);
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }

        try {
            // Explore parameters
            ILocalVariable[] parameters = iMethod.getParameters();
            // If we don't have any parameters yet, we create them
            if (parameters.length > 0 && operation.getParameters().size() == 0) {
                for (ILocalVariable iLocalVariable : parameters) {
                    String typeSignature = iLocalVariable.getTypeSignature();

                    Parameter parameter = CodeFactory.eINSTANCE.createParameter();
                    parameter.setName(iLocalVariable.getElementName());
                    parameter.setQualifiedName(
                            Signature.toString(typeSignature) + ' ' + iLocalVariable.getElementName());
                    parameter.setFinal(Flags.isFinal(iLocalVariable.getFlags()));
                    if (Flags.isDeprecated(iLocalVariable.getFlags())) {
                        // Add the property "Deprecated"
                        this.addDeprecatedProperty(parameter);
                    }
                    operation.getParameters().add(parameter);

                    // Set the typing dependency
                    String signature = Signature.toString(iLocalVariable.getTypeSignature());
                    Classifier ariadneClassifier = this.getOrCreateClassifier(signature);
                    if (ariadneClassifier != null) {
                        parameter.getTypes().add(ariadneClassifier);
                    }
                }
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.eclipse.recommenders.internal.completion.rcp.AccessibleCompletionProposals.java

License:Open Source License

public static AccessibleCompletionProposal newLocalRef(ILocalVariable local, int completionOffset,
        int prefixLength, int relevance) {
    AccessibleCompletionProposal proposal = new AccessibleCompletionProposal(
            CompletionProposal.LOCAL_VARIABLE_REF, completionOffset);
    String typeSignature = local.getTypeSignature();
    String simpleName = Signature.getSignatureSimpleName(typeSignature);
    proposal.setTypeName(simpleName.toCharArray());

    proposal.setSignature(typeSignature.toCharArray());
    // proposal.setPackageName(local.type.qualifiedPackageName());

    proposal.setName(local.getElementName().toCharArray());
    proposal.setCompletion(local.getElementName().toCharArray());
    proposal.setFlags(local.getFlags());
    int replaceStartIndex = completionOffset - prefixLength;
    int replaceEndIndex = completionOffset;
    proposal.setReplaceRange(replaceStartIndex, replaceEndIndex);
    // TODO we may need to respect ui settings here:
    int tokenStartIndex = replaceStartIndex;
    int tokenEndIndex = replaceEndIndex;
    proposal.setTokenRange(tokenStartIndex, tokenEndIndex);
    proposal.setRelevance(relevance);//from w  w w. j ava 2 s  .c om

    return proposal;
}