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

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

Introduction

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

Prototype

IJavaProject getJavaProject();

Source Link

Document

Returns the Java project this element is contained in, or null if this element is not contained in any Java project (for instance, the IJavaModel is not contained in any Java project).

Usage

From source file:org.springframework.ide.eclipse.data.beans.ui.model.RepositoriesModelLabelDecorator.java

License:Open Source License

@Override
protected void decorateJavaElement(IJavaElement element, IDecoration decoration) {
    IJavaProject javaProject = element.getJavaProject();
    if (javaProject != null) {
        int type = element.getElementType();
        IProject project = javaProject.getProject();

        try {//from www  .j a v a2 s.c  o m

            if (type == IJavaElement.CLASS_FILE) {

                // Decorate Java class file
                IType javaType = ((IClassFile) element).getType();

                if (javaType.isInterface() && SpringDataUtils.hasRepositoryBeanFor(project, javaType)) {
                    decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                }

            } else if (type == IJavaElement.COMPILATION_UNIT) {

                // Decorate Java source file
                for (IType javaType : ((ICompilationUnit) element).getTypes()) {
                    if (javaType.isInterface() && SpringDataUtils.hasRepositoryBeanFor(project, javaType)) {
                        decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                        break;
                    }
                }
            }

        } catch (JavaModelException e) {
            // ignore
        }
    }
}

From source file:org.springframework.ide.eclipse.metadata.ui.RequestMappingView.java

License:Open Source License

private IBeansModelElement getInputFromJavaElement(IJavaElement javaElement) {
    IBeansModelElement modelElement = null;
    if (javaElement != null) {
        IJavaProject project = javaElement.getJavaProject();
        if (project != null) {
            modelElement = BeansCorePlugin.getModel().getProject(project.getProject());
        }//from www .  j a  v a  2 s .c  o m
    }
    return modelElement;
}

From source file:org.springframework.ide.eclipse.quickfix.hyperlinks.AutowireHyperlinkDetector.java

License:Open Source License

private void addHyperlinksHelper(String typeSignature, IJavaElement element,
        List<IHyperlink> hyperlinksCollector) {
    String typeName = Signature.toString(typeSignature);
    try {//from ww w.ja  v a 2s .  c  om
        IType type = getParentType(element);
        if (type != null) {
            String[][] qualifiedTypeNames = type.resolveType(typeName);
            if (qualifiedTypeNames != null) {
                for (String[] typeNameSegments : qualifiedTypeNames) {
                    StringBuilder qualifiedTypeName = new StringBuilder();
                    for (String typeNameSegment : typeNameSegments) {
                        if (qualifiedTypeName.length() > 0) {
                            qualifiedTypeName.append(".");
                        }
                        qualifiedTypeName.append(typeNameSegment);
                    }

                    addHyperlinksHelper(qualifiedTypeName.toString(), element.getJavaProject().getProject(),
                            hyperlinksCollector);
                }
            }
        }
    } catch (JavaModelException e) {
        StatusHandler.log(e.getStatus());
    }
}

From source file:org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl.java

License:Open Source License

@Override
public CompletableFuture<Location> javaLocation(JavaDataParams params) {
    return CompletableFuture.supplyAsync(() -> {
        try {//from ww w. jav a 2s  .  co  m
            URI projectUri = params.getProjectUri() == null ? null : URI.create(params.getProjectUri());
            IJavaElement element = JavaData.findElement(projectUri, params.getBindingKey(),
                    JavaDataParams.isLookInOtherProjects(params));
            if (element != null) {
                IJavaProject project = element.getJavaProject() == null
                        ? ResourceUtils.getJavaProject(projectUri)
                        : element.getJavaProject();
                if (project != null) {
                    return new Location(
                            Utils.eclipseIntroUri(project.getElementName(), params.getBindingKey()).toString(),
                            null);
                }
            }
        } catch (Exception e) {
            LanguageServerCommonsActivator.logError(e,
                    "Failed to find java element for key " + params.getBindingKey());
        }
        return null;
    });
}

From source file:org.springsource.ide.eclipse.commons.ui.SpringJavaElementPropertyTester.java

License:Open Source License

private boolean isInSpringProject(IJavaElement je) {
    if (je != null) {
        IJavaProject jp = je.getJavaProject();
        if (jp != null) {
            return SpringPropertyTester.isSpringProject(jp.getProject());
        }/*from   ww w.  j  a v  a2  s. c  om*/
    }
    return false;
}

From source file:org.springsource.ide.eclipse.gradle.core.test.util.JUnitLaunchConfigUtil.java

License:Open Source License

public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement element)
        throws CoreException {
    final String testName;
    final String mainTypeQualifiedName;
    final String containerHandleId;

    switch (element.getElementType()) {
    case IJavaElement.JAVA_PROJECT:
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.PACKAGE_FRAGMENT: {
        String name = JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_FULLY_QUALIFIED);
        containerHandleId = element.getHandleIdentifier();
        mainTypeQualifiedName = EMPTY_STRING;
        testName = name.substring(name.lastIndexOf(IPath.SEPARATOR) + 1);
    }/*from   w  ww.ja v  a2  s . c o m*/
        break;
    case IJavaElement.TYPE: {
        containerHandleId = EMPTY_STRING;
        mainTypeQualifiedName = ((IType) element).getFullyQualifiedName('.'); // don't replace, fix for binary inner types
        testName = element.getElementName();
    }
        break;
    case IJavaElement.METHOD: {
        IMethod method = (IMethod) element;
        containerHandleId = EMPTY_STRING;
        mainTypeQualifiedName = method.getDeclaringType().getFullyQualifiedName('.');
        testName = method.getDeclaringType().getElementName() + '.' + method.getElementName();
    }
        break;
    default:
        throw new IllegalArgumentException(
                "Invalid element type to create a launch configuration: " + element.getClass().getName()); //$NON-NLS-1$
    }

    String testKindId = TestKindRegistry.getContainerTestKindId(element);

    ILaunchConfigurationType configType = getLaunchManager()
            .getLaunchConfigurationType(JUnitLaunchConfigurationConstants.ID_JUNIT_APPLICATION);
    ILaunchConfigurationWorkingCopy wc = configType.newInstance(null,
            getLaunchManager().generateLaunchConfigurationName(testName));

    wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainTypeQualifiedName);
    wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
            element.getJavaProject().getElementName());
    wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_KEEPRUNNING, false);
    wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_CONTAINER, containerHandleId);
    wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_RUNNER_KIND, testKindId);
    JUnitMigrationDelegate.mapResources(wc);
    AssertionVMArg.setArgDefault(wc);
    if (element instanceof IMethod) {
        wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_METHOD_NAME, element.getElementName()); // only set for methods
    }
    return wc;
}

From source file:org.summer.dsl.model.types.access.jdt.TypeURIHelper.java

License:Open Source License

public URI getFullURI(IJavaElement javaElement) {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setProject(javaElement.getJavaProject());
    IBinding[] bindings = parser.createBindings(new IJavaElement[] { javaElement }, null);
    if (bindings[0] != null) {
        return getFullURI(bindings[0]);
    }//from   w w w . j  ava  2 s.  com
    return null;
}

From source file:org.switchyard.tools.ui.common.impl.WSDLInterfaceControlAdapter.java

License:Open Source License

@Override
public boolean browse(Shell shell, IJavaElement element) {
    WSDLPortTypeSelectionDialog dialog = new WSDLPortTypeSelectionDialog(shell,
            element == null ? ResourcesPlugin.getWorkspace().getRoot() : element.getJavaProject().getProject());
    dialog.setInitialPattern("*.wsdl"); //$NON-NLS-1$
    if (dialog.open() == WSDLPortTypeSelectionDialog.OK) {
        PortType result = dialog.getSelectedPortType();
        if (result != null) {
            _interface.setInterface(getInterfaceURL(element, result));
            return true;
        }/*from   w ww .  j  av  a2s. c  o  m*/
    }
    return false;
}

From source file:org.switchyard.tools.ui.common.impl.WSDLInterfaceControlAdapter.java

License:Open Source License

private String getInterfaceURL(IJavaElement element, PortType portType) {
    IPath filePath = new Path(portType.eResource().getURI().toPlatformString(true));
    IResource resource = element.getJavaProject().getProject().getWorkspace().getRoot().getFile(filePath);
    filePath = JavaUtil.getJavaPathForResource(resource);
    return filePath.toString() + "#wsdl.porttype(" + portType.getQName().getLocalPart() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:org.switchyard.tools.ui.wizards.Java2WSDLOptionsWizardPage.java

License:Open Source License

private void initFromJavaElement(IJavaElement javaElement) {
    if (javaElement.getElementType() == IJavaElement.TYPE) {
        initFromType((IType) javaElement);
    } else if (javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
        initFromCU((ICompilationUnit) javaElement);
    } else if (javaElement.getJavaProject() != null) {
        initFromProject(javaElement.getJavaProject().getProject());
    }//w  w w .  j  a  v a2s.  com
}