List of usage examples for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT_ROOT
int PACKAGE_FRAGMENT_ROOT
To view the source code for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT_ROOT.
Click Source Link
From source file:org.python.pydev.editor.codecompletion.revisited.javaintegration.JavaProjectModulesManager.java
License:Open Source License
/** * @param dontSearchInit: not applicable for this method (ignored) * @return the module that corresponds to the passed name. */// w ww. ja v a 2 s .c om public IModule getModuleInDirectManager(String name, IPythonNature nature, boolean dontSearchInit) { if (DEBUG_GET_MODULE) { System.out.println("Trying to get module in java project modules manager: " + name); } if (name.startsWith(".")) { //this happens when looking for a relative import return null; } try { IJavaElement javaElement = this.javaProject.findType(name); if (javaElement == null) { javaElement = this.javaProject.findElement(new Path(name.replace('.', '/'))); } if (DEBUG_GET_MODULE) { System.out.println("Found: " + javaElement); } if (javaElement != null) { //now, there's a catch here, we'll find any class in the project classpath, even if it's in the //global classpath (e.g.: rt.jar), and this shouldn't be treated in this project modules manager //(that's treated in the Jython system manager) IJavaElement ancestor = javaElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (ancestor instanceof IPackageFragmentRoot) { IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) ancestor; IClasspathEntry rawClasspathEntry = packageFragmentRoot.getRawClasspathEntry(); if (rawClasspathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { return null; } } return new JavaModuleInProject(name, this.javaProject); } } catch (Exception e) { throw new RuntimeException(e); } return null; }
From source file:org.seasar.resource.synchronizer.servlet.SelectionServlet.java
License:Apache License
private IDocument toDocument(final IType type) throws JavaModelException { IDocument document = null;/*from w w w. j av a 2 s . c o m*/ if (type.isBinary()) { IPackageFragmentRoot root = (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IPath path = root.getSourceAttachmentPath(); if (path != null) { IOpenable o = type.getOpenable(); IBuffer buf = o.getBuffer(); if (buf != null) { document = new Document(buf.getContents()); } } } else { document = new Document(type.getCompilationUnit().getSource()); } return document; }
From source file:org.springframework.ide.eclipse.beans.ui.model.BeansModelLabelDecorator.java
License:Open Source License
protected void decorateJavaElement(IJavaElement element, IDecoration decoration) { int type = element.getElementType(); if (type == IJavaElement.PACKAGE_FRAGMENT_ROOT || type == IJavaElement.CLASS_FILE || type == IJavaElement.COMPILATION_UNIT) { IBeansModel model = BeansCorePlugin.getModel(); IBeansProject project = model.getProject(element.getJavaProject().getProject()); if (project instanceof ILazyInitializedModelElement && ((ILazyInitializedModelElement) project).isInitialized()) { try { if (type == IJavaElement.PACKAGE_FRAGMENT_ROOT) { // Decorate JAR file IResource resource = ((IPackageFragmentRoot) element).getResource(); if (resource instanceof IFile) { for (IBeansConfig config : project.getConfigs()) { if (config.getElementResource().equals(resource)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); break; }/*from ww w . j av a2s. c o m*/ } } } else if (type == IJavaElement.CLASS_FILE) { // Decorate Java class file IType javaType = ((IClassFile) element).getType(); if (BeansModelUtils.isBeanClass(javaType)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); } } else if (type == IJavaElement.COMPILATION_UNIT) { // Decorate Java source file for (IType javaType : ((ICompilationUnit) element).getTypes()) { if (BeansModelUtils.isBeanClass(javaType)) { decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING); break; } } } } catch (JavaModelException e) { // Ignore } } } }
From source file:org.springframework.ide.eclipse.beans.ui.properties.NonJavaResourceContentProvider.java
License:Open Source License
private Object[] getNonJavaResources(IPackageFragment fragment) throws JavaModelException { Object[] nonJavaResources = fragment.getNonJavaResources(); IPackageFragmentRoot root = (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && root.getKind() == IPackageFragmentRoot.K_BINARY) { for (int i = 0; i < nonJavaResources.length; i++) { Object resource = nonJavaResources[i]; if (resource instanceof IFile) { nonJavaResources[i] = resource; } else if (resource instanceof IStorage && root.getResource() instanceof IFile) { IStorage storage = (IStorage) resource; nonJavaResources[i] = new ZipEntryStorage((IFile) root.getResource(), storage.getFullPath().toString()); }//from w w w .j a va 2 s . c om } } return nonJavaResources; }
From source file:org.springframework.ide.eclipse.beans.ui.properties.NonJavaResourceContentProvider.java
License:Open Source License
protected boolean isClasspathChange(IJavaElementDelta delta) { // need to test the flags only for package fragment roots if (delta.getElement().getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT) { return false; }/*from www. j a v a 2s .c o m*/ int flags = delta.getFlags(); return (delta.getKind() == IJavaElementDelta.CHANGED && ((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0) || ((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) || ((flags & IJavaElementDelta.F_REORDER) != 0)); }
From source file:org.springframework.ide.eclipse.beans.ui.refactoring.actions.BeansRenameRefactorAction.java
License:Open Source License
private boolean isRenameAvailable(IJavaElement element) throws CoreException { switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: return RefactoringAvailabilityTester.isRenameAvailable((IJavaProject) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return RefactoringAvailabilityTester.isRenameAvailable((IPackageFragmentRoot) element); case IJavaElement.PACKAGE_FRAGMENT: return RefactoringAvailabilityTester.isRenameAvailable((IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: return RefactoringAvailabilityTester.isRenameAvailable((ICompilationUnit) element); case IJavaElement.TYPE: return RefactoringAvailabilityTester.isRenameAvailable((IType) element); case IJavaElement.METHOD: final IMethod method = (IMethod) element; if (method.isConstructor()) return RefactoringAvailabilityTester.isRenameAvailable(method.getDeclaringType()); else//w w w . j a va 2s. c o m return RefactoringAvailabilityTester.isRenameAvailable(method); case IJavaElement.FIELD: final IField field = (IField) element; if (Flags.isEnum(field.getFlags())) return RefactoringAvailabilityTester.isRenameEnumConstAvailable(field); else return RefactoringAvailabilityTester.isRenameFieldAvailable(field); case IJavaElement.TYPE_PARAMETER: return RefactoringAvailabilityTester.isRenameAvailable((ITypeParameter) element); case IJavaElement.LOCAL_VARIABLE: return RefactoringAvailabilityTester.isRenameAvailable((ILocalVariable) element); } return false; }
From source file:org.springframework.ide.eclipse.boot.dash.model.requestmappings.AbstractRequestMapping.java
License:Open Source License
@Override public boolean isUserDefined() { try {// w w w . j av a2s. c o m IType type = getType(); if (type != null) { IPackageFragmentRoot pfr = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (pfr != null) { return pfr.getKind() == IPackageFragmentRoot.K_SOURCE; } } } catch (Exception e) { BootDashActivator.log(e); } return false; }
From source file:org.springframework.ide.eclipse.boot.templates.BootJavaContext.java
License:Open Source License
public boolean isTestContext() { //True if the current file is in a src folder that has a segment with name 'test' in its path. try {/*from w ww. jav a2 s. c o m*/ ICompilationUnit cu = getCompilationUnit(); if (cu != null) { IPackageFragmentRoot pfr = (IPackageFragmentRoot) cu .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (pfr != null) { IClasspathEntry cpe = pfr.getRawClasspathEntry(); if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = cpe.getPath().removeFirstSegments(1); //remove first... it doesn't count if project is called 'test'. if (sourcePath != null) { for (String segment : sourcePath.segments()) { if (segment.equals("test")) { return true; } } } } } } } catch (Exception e) { Log.log(e); } return false; }
From source file:org.springframework.tooling.jdt.ls.commons.java.JavaData.java
License:Open Source License
private ClasspathEntryData createClasspathEntryData(IMember member) { ClasspathEntryData data = new ClasspathEntryData(); IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) member .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (packageFragmentRoot != null) { try {// w ww. j a va 2s . co m IClasspathEntry entry = packageFragmentRoot.getResolvedClasspathEntry(); if (entry != null) { List<CPE> cpes = ClasspathUtil.createCpes(packageFragmentRoot.getJavaProject(), entry); Assert.isTrue(cpes.size() < 2); if (!cpes.isEmpty()) { data.setCpe(cpes.get(0)); } } } catch (JavaModelException | MalformedURLException e) { logger.log(e); } } ITypeRoot typeRoot = member.getTypeRoot(); try { if (typeRoot != null && typeRoot.getModule() != null) { data.setModule(typeRoot.getModule().getElementName()); } } catch (JavaModelException e) { logger.log(e); } return data; }
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 va 2 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; }