List of usage examples for org.eclipse.jdt.core IJavaElement getJavaProject
IJavaProject getJavaProject();
null
if this element is not contained in any Java project (for instance, the IJavaModel
is not contained in any Java project). From source file:org.switchyard.tools.ui.wizards.Java2WSDLWizard.java
License:Open Source License
private void setFilePageDefaultsForJavaElement(IJavaElement javaElement) { IResource root;/*from ww w . j a v a 2s. c o m*/ switch (javaElement.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: root = javaElement.getResource(); break; default: root = JavaUtil.getFirstResourceRoot(javaElement.getJavaProject()); if (root == null) { root = javaElement.getResource(); if (root.getType() == IResource.FILE) { root = root.getParent(); } } break; } if (root != null) { _filePage.setContainerFullPath(root.getFullPath()); } int elementType = javaElement.getElementType(); if (elementType == IJavaElement.TYPE) { _filePage.setFileName(javaElement.getElementName()); } else if (elementType == IJavaElement.COMPILATION_UNIT) { IType primaryType = ((ICompilationUnit) javaElement).findPrimaryType(); if (primaryType == null) { getBaseFileName(javaElement.getElementName()); } else { _filePage.setFileName(primaryType.getElementName()); } } }
From source file:org.switchyard.tools.ui.wizards.NewBeanServiceClassWizardPage.java
License:Open Source License
private IJavaElement getInitialContainerElement(IStructuredSelection selection, IJavaElement initialElement) { if (selection != null && !selection.isEmpty() && selection.getFirstElement() instanceof ISwitchYardNode) { ISwitchYardNode switchYardNode = (ISwitchYardNode) selection.getFirstElement(); if (initialElement == null || initialElement.getJavaProject() == null || !initialElement .getJavaProject().getProject().equals(switchYardNode.getRoot().getProject())) { return JavaCore.create(switchYardNode.getRoot().getProject()); }//from w ww .ja v a2 s . c o m } return initialElement; }
From source file:org.synyx.hades.eclipse.beans.ui.model.HadesModelLabelDecorator.java
License:Apache License
@Override protected void decorateJavaElement(IJavaElement element, IDecoration decoration) { int type = element.getElementType(); IProject project = element.getJavaProject().getProject(); try {//from www. j av a 2 s . c om if (type == IJavaElement.CLASS_FILE) { // Decorate Java class file IType javaType = ((IClassFile) element).getType(); if (HadesUtils.hasDaoBeanFor(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 (HadesUtils.hasDaoBeanFor(project, javaType)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); break; } } } } catch (JavaModelException e) { // ignore } super.decorateJavaElement(element, decoration); }
From source file:org.xpect.ui.junit.launching.LaunchShortcutUtil.java
License:Open Source License
public static ILaunchConfigurationWorkingCopy createXpectLaunchConfiguration(JUnitJavaElementDelegate element, String launchConfigurationTypeId) throws CoreException { IJavaElement javaElement = element.getJavaElement(); Preconditions.checkArgument(javaElement.getElementType() == IJavaElement.TYPE); String mainTypeQualifiedName = ((IType) javaElement).getFullyQualifiedName('.'); // don't replace, fix for binary inner types String containerHandleId = ""; String testName = getLaunchConfigTitle(element); String testKindId = TestKindRegistry.JUNIT4_TEST_KIND_ID; ILaunchConfigurationType configType = getLaunchManager() .getLaunchConfigurationType(launchConfigurationTypeId); ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(testName)); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainTypeQualifiedName); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, javaElement.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);/*w w w. ja v a 2 s. co m*/ String methodName = element.getDescription().getMethodName(); if (!Strings.isEmpty(methodName)) wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_METHOD_NAME, methodName); else wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_METHOD_NAME, element.getDescription().getClassName()); String fileInProject = element.getResource().getFullPath().removeFirstSegments(1).toString(); ensureContains(wc, IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-DxpectFiles=", fileInProject); return wc; }