Example usage for org.eclipse.jdt.core IJavaElement getElementName

List of usage examples for org.eclipse.jdt.core IJavaElement getElementName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement getElementName.

Prototype

String getElementName();

Source Link

Document

Returns the name of this element.

Usage

From source file:org.jboss.tools.ws.jaxrs.core.jdt.MemberValuePairLocationRetriever.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.NormalAnnotation)
 *///from   w  ww  .  ja  v a 2  s.com
@Override
public boolean visit(NormalAnnotation node) {
    final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.ANNOTATION);
    if (ancestor != null && ancestor.exists()
            && ancestor.getElementName().equals(node.getTypeName().getFullyQualifiedName())) {
        // keep searching
        return true;
    }
    // wrong path, stop searching from this branch of the AST
    return false;
}

From source file:org.jboss.tools.ws.jaxrs.ui.navigation.JaxrsNameBindingAnnotationHyperlink.java

License:Open Source License

public static String getDisplayNameText(final IJaxrsJavaElement element) {
    final IJavaElement javaElement = ((IJaxrsJavaElement) element).getJavaElement();
    if (javaElement.getElementType() == IJavaElement.TYPE) {
        return ((IType) javaElement).getFullyQualifiedName();
    }//from  w  w  w  . j  a  v a 2s.co  m
    return ((IJaxrsResourceMethod) element).getParentResource().getJavaElement().getFullyQualifiedName() + '.'
            + javaElement.getElementName() + "(...)";
}

From source file:org.jboss.tools.ws.jaxrs.ui.navigation.JaxrsNameBindingHyperlinkDetector.java

License:Open Source License

/**
 * /*from  w  w  w.j  ava2s.  c o m*/
 * @param input
 *            the current {@link IJavaElement}
 * @param wordRegion
 *            the selected {@link IRegion} in the {@link ITextEditor}
 * @return an array of {@link IJavaElement} matching the selection or an
 *         empty array if none was found or if an error occurred.
 */
private IJavaElement[] getSelectedElements(final IJavaElement input, final IRegion wordRegion) {
    try {
        return ((ICodeAssist) input).codeSelect(wordRegion.getOffset(), wordRegion.getLength());
    } catch (JavaModelException e) {
        // element does not exist or wordRegion was out of range.
        // We should silently ignore such a case, in which case, no navigation hyperlink shall be provided.
        Logger.debug("Failed to retrieve the selected Java Elements in the editor for" + input.getElementName(),
                e);
        return new IJavaElement[0];
    }
}

From source file:org.jboss.tools.ws.jaxrs.ui.navigation.JaxrsNameBindingHyperlinkDetector.java

License:Open Source License

/**
 * @param input the current {@link IJavaElement}
 * @return the {@link JaxrsMetamodel} associated with the given element or {@code null} if none exists (or if an exception was thrown).
 *///from   ww  w.j  a va  2 s  .  c  om
private JaxrsMetamodel getMetamodel(final IJavaElement input) {
    try {
        return JaxrsMetamodelLocator.get(input.getJavaProject());
    } catch (CoreException e) {
        Logger.error("Failed to retrieve JAX-RS Metamodel for " + input.getElementName(), e);
        return null;
    }
}

From source file:org.jboss.tools.ws.jaxrs.ui.quickfix.JaxrsMarkerResolutionGenerator.java

License:Open Source License

private IJavaCompletionProposal generateMissingAttributesCompletionProposal(final String qualifiedName,
        final IProblemLocation problemLocation, final IAnnotation annotation) throws JavaModelException {
    if (qualifiedName == null || annotation == null) {
        return null;
    }/*from   w w w . ja v a2s. c om*/
    final IJaxrsElement jaxrsElement = findJaxrsElement(annotation.getParent());
    // skip if the problem is not linked to a JAX-RS element.
    if (jaxrsElement == null) {
        return null;
    }
    final ICompilationUnit compilationUnit = (ICompilationUnit) annotation
            .getAncestor(IJavaElement.COMPILATION_UNIT);
    if (qualifiedName.equals(JaxrsClassnames.TARGET)) {
        switch (jaxrsElement.getElementKind()) {
        case HTTP_METHOD:
            return new AddHttpMethodTargetValuesCompletionProposal(compilationUnit,
                    findEffectiveSourceRange(compilationUnit, problemLocation));
        case NAME_BINDING:
            return new AddHttpMethodTargetValuesCompletionProposal(compilationUnit,
                    findEffectiveSourceRange(compilationUnit, problemLocation));
        default:
            return null;
        }
    } else if (qualifiedName.equals(JaxrsClassnames.RETENTION)) {
        switch (jaxrsElement.getElementKind()) {
        case HTTP_METHOD:
            return new AddHttpMethodRetentionValueCompletionProposal(compilationUnit,
                    findEffectiveSourceRange(compilationUnit, problemLocation));
        case NAME_BINDING:
            return new AddNameBindingRetentionValueCompletionProposal(compilationUnit,
                    findEffectiveSourceRange(compilationUnit, problemLocation));
        default:
            return null;
        }
    } else if (qualifiedName.equals(JaxrsClassnames.HTTP_METHOD)) {
        final IJavaElement httpMethodType = annotation.getAncestor(IJavaElement.TYPE);
        return new AddHttpMethodValueCompletionProposal(compilationUnit,
                "\"" + httpMethodType.getElementName() + "\"",
                findEffectiveSourceRange(compilationUnit, problemLocation));
    }
    return null;
}

From source file:org.jboss.tools.ws.jaxrs.ui.quickfix.JaxrsMarkerResolutionGenerator.java

License:Open Source License

/**
 * @param javaElement/*from  w w w . j av  a2  s. com*/
 *            the java element
 * @return the {@link IJaxrsElement} associated with the given
 *         {@link IJavaElement}, or {@code null} if none was found.
 */
private static IJaxrsElement findJaxrsElement(final IJavaElement javaElement) {
    if (javaElement != null) {
        try {
            return JaxrsMetamodelLocator.get(javaElement.getJavaProject()).findElement(javaElement);
        } catch (CoreException e) {
            Logger.error(
                    "Failed to retrieve JAX-RS Elements associated with '" + javaElement.getElementName() + "'",
                    e);
        }
    }
    return null;
}

From source file:org.jetbrains.kotlin.wizards.NewUnitWizardPage.java

License:Apache License

private String getPackageFromSelection() {
    String defaultPackage = DEFAULT_PACKAGE;

    if (selection.isEmpty()) {
        return defaultPackage;
    }/* w w  w  .j  a v  a 2 s  .c  o m*/

    Object selectedObject = selection.getFirstElement();

    if (selectedObject instanceof IJavaElement) {
        IJavaElement selectedJavaElement = (IJavaElement) selectedObject;
        switch (selectedJavaElement.getElementType()) {
        case IJavaElement.PACKAGE_FRAGMENT:
            return selectedJavaElement.getElementName();

        case IJavaElement.COMPILATION_UNIT:
            try {
                return selectedJavaElement.getJavaProject()
                        .findPackageFragment(selectedJavaElement.getPath().makeAbsolute().removeLastSegments(1))
                        .getElementName();
            } catch (Exception e) {
                KotlinLogger.logAndThrow(e);
            }
            break;
        }
    } else if (selectedObject instanceof IResource) {
        IResource selectedResource = (IResource) selectedObject;
        switch (selectedResource.getType()) {
        case IResource.FILE:
            try {
                return JavaCore.create(selectedResource.getProject())
                        .findPackageFragment(
                                selectedResource.getFullPath().makeAbsolute().removeLastSegments(1))
                        .getElementName();
            } catch (Exception e) {
                KotlinLogger.logAndThrow(e);
            }
            break;
        }
    }

    return defaultPackage;
}

From source file:org.knime.workbench.extension.wizards.NewKNIMEPluginWizardPage.java

License:Open Source License

private String getSelectedPackage() {
    if (m_selection == null || m_selection.isEmpty()) {
        return "";
    }//  w  w  w .  j a v  a2 s. c  om

    Object o = m_selection.getFirstElement();
    if (o instanceof IJavaElement) {
        if (o instanceof IPackageFragment) {
            return ((IPackageFragment) o).getElementName();
        } else {
            IJavaElement je = (IJavaElement) o;
            while (je.getParent() != null && !(je.getParent() instanceof IPackageFragment)) {
                je = je.getParent();
            }
            return je.getElementName();
        }
    }

    return "";
}

From source file:org.limy.eclipse.common.jdt.LimyJavaUtils.java

License:Open Source License

/**
 * IPackageFragmentSJavat@C? results i[?B
 * @param results i[?//from w  w  w .  j a  v  a  2  s.c om
 * @param packageFragment IPackageFragmentvf
 * @param visitor IJavaResourceVisitor
 * @throws CoreException RAO
 */
private static void appendForIPackageFragment(Collection<IJavaElement> results,
        IPackageFragment packageFragment/*, IJavaResourceVisitor visitor*/) throws CoreException {

    IPackageFragmentRoot parent = (IPackageFragmentRoot) packageFragment.getParent();

    String parentName = packageFragment.getElementName();
    if (parentName.length() > 0) {
        for (IJavaElement child : parent.getChildren()) {
            String childName = child.getElementName();

            if (childName.startsWith(parentName) && childName.lastIndexOf('.') == parentName.length()) {
                // TupbP?[WT
                appendAllJavas(results, child/*, visitor*/);
            }
        }
    }
}

From source file:org.limy.eclipse.qalab.common.LimyQalabJavaUtils.java

License:Open Source License

/**
 * JavavfbinfBNg?B//from  w ww  .j a va2 s  . c  o m
 * <p>
 * pbP?[Wvf : binfBNgTufBNg<br>
 * \?[XfBNg : binfBNg<br>
 * </p>
 * @param el Javavf
 * @return binfBNg?i?pX?j
 * @throws CoreException 
 */
public static String getBinDirPath(IJavaElement el) throws CoreException {

    if (el.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
        IPackageFragmentRoot root = (IPackageFragmentRoot) el.getParent();
        String path = LimyQalabJavaUtils.getExternalLocation(root);
        return new File(path, el.getElementName().replace('.', '/')).getAbsolutePath();
    }
    if (el.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) {
        return LimyQalabJavaUtils.getExternalLocation((IPackageFragmentRoot) el);
    }
    return null;
}