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.eclipse.pde.api.tools.ui.internal.wizards.CompareOperation.java
License:Open Source License
/** * @param structuredSelection/*w w w. j av a 2 s. c o m*/ * @param monitor * @return the scope */ public static ApiScope walkStructureSelection(IStructuredSelection structuredSelection, IProgressMonitor monitor) { Object[] selected = structuredSelection.toArray(); ApiScope scope = new ApiScope(); IApiBaseline workspaceBaseline = ApiBaselineManager.getManager().getWorkspaceBaseline(); if (workspaceBaseline == null) { return scope; } Arrays.sort(selected, new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { if (o1 instanceof IJavaElement && o2 instanceof IJavaElement) { IJavaElement element = (IJavaElement) o1; IJavaElement element2 = (IJavaElement) o2; return element.getElementType() - element2.getElementType(); } return 0; } }); int length = selected.length; for (int i = 0; i < length; i++) { Object currentSelection = selected[i]; if (currentSelection instanceof IJavaElement) { IJavaElement element = (IJavaElement) currentSelection; IJavaProject javaProject = element.getJavaProject(); try { switch (element.getElementType()) { case IJavaElement.COMPILATION_UNIT: { ICompilationUnit compilationUnit = (ICompilationUnit) element; IApiComponent apiComponent = workspaceBaseline .getApiComponent(javaProject.getElementName()); if (apiComponent != null) { addElementFor(compilationUnit, apiComponent, scope); } break; } case IJavaElement.PACKAGE_FRAGMENT: { IPackageFragment fragment = (IPackageFragment) element; IApiComponent apiComponent = workspaceBaseline .getApiComponent(javaProject.getElementName()); IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) fragment .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); boolean isArchive = false; if (packageFragmentRoot != null) { isArchive = packageFragmentRoot.isArchive(); } if (apiComponent != null) { addElementFor(fragment, isArchive, apiComponent, scope); } break; } case IJavaElement.PACKAGE_FRAGMENT_ROOT: { IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot) element; IApiComponent apiComponent = workspaceBaseline .getApiComponent(javaProject.getElementName()); if (apiComponent != null) { addElementFor(fragmentRoot, apiComponent, scope); } break; } case IJavaElement.JAVA_PROJECT: IApiComponent apiComponent = workspaceBaseline .getApiComponent(javaProject.getElementName()); if (apiComponent != null) { scope.addElement(apiComponent); } break; default: break; } } catch (JavaModelException e) { ApiPlugin.log(e); } catch (CoreException e) { ApiPlugin.log(e); } } } return scope; }
From source file:org.eclipse.pde.internal.ui.search.ClassSearchParticipant.java
License:Open Source License
public void search(ISearchRequestor requestor, QuerySpecification querySpecification, IProgressMonitor monitor) throws CoreException { if (querySpecification.getLimitTo() != S_LIMIT_REF && querySpecification.getLimitTo() != S_LIMIT_ALL) return;//from www .ja va 2s . c o m String search; if (querySpecification instanceof ElementQuerySpecification) { IJavaElement element = ((ElementQuerySpecification) querySpecification).getElement(); if (element instanceof IType) search = ((IType) element).getFullyQualifiedName('.'); else search = element.getElementName(); int type = element.getElementType(); if (type == IJavaElement.TYPE) fSearchFor = S_FOR_TYPES; else if (type == IJavaElement.PACKAGE_FRAGMENT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT) fSearchFor = S_FOR_PACKAGES; } else { fSearchFor = ((PatternQuerySpecification) querySpecification).getSearchFor(); search = ((PatternQuerySpecification) querySpecification).getPattern(); } if (fSearchFor != S_FOR_TYPES && fSearchFor != S_FOR_PACKAGES) return; fSearchPattern = PatternConstructor.createPattern(search, true); fSearchRequestor = requestor; IPath[] enclosingPaths = querySpecification.getScope().enclosingProjectsAndJars(); IPluginModelBase[] pluginModels = PluginRegistry.getWorkspaceModels(); monitor.beginTask(PDEUIMessages.ClassSearchParticipant_taskMessage, pluginModels.length); for (int i = 0; i < pluginModels.length; i++) { IProject project = pluginModels[i].getUnderlyingResource().getProject(); if (!monitor.isCanceled() && encloses(enclosingPaths, project.getFullPath())) searchProject(project, monitor); } }
From source file:org.eclipse.recommenders.internal.apidocs.rcp.ApidocsView.java
License:Open Source License
private void addCurrentSelectionHeader() { final IJavaElement element = activeSelection.getElement(); final String text; switch (element.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: text = element.getElementName(); break;/*ww w. j av a 2s .c o m*/ case IJavaElement.LOCAL_VARIABLE: text = JavaElementLabels.getElementLabel(element, JavaElementLabels.F_PRE_TYPE_SIGNATURE | JavaElementLabels.F_POST_QUALIFIED); break; default: text = JavaElementLabels.getElementLabel(element, LABEL_FLAGS); break; } Composite header = new Composite(content, SWT.NONE); ApidocsViewUtils.setInfoBackgroundColor(header); header.setLayout(new GridLayout(2, false)); Label img = new Label(header, SWT.NONE); img.setImage(labelProvider.getImage(element)); setInfoForegroundColor(img); setInfoBackgroundColor(img); Label name = createLabel(header, text, true); name.setFont(JFaceResources.getHeaderFont()); }
From source file:org.eclipse.recommenders.internal.rcp.JavaElementSelections.java
License:Open Source License
public static JavaElementSelectionLocation resolveSelectionLocationFromJavaElement(final IJavaElement element) { ensureIsNotNull(element);//from w w w.j a va 2 s .co m switch (element.getElementType()) { case IJavaElement.CLASS_FILE: case IJavaElement.COMPILATION_UNIT: case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.TYPE: return TYPE_DECLARATION; case IJavaElement.METHOD: case IJavaElement.INITIALIZER: return METHOD_DECLARATION; case IJavaElement.FIELD: return FIELD_DECLARATION; case IJavaElement.LOCAL_VARIABLE: // shouldn't happen in a viewer selection, right? return METHOD_BODY; case IJavaElement.JAVA_MODEL: case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.ANNOTATION: default: return JavaElementSelectionLocation.UNKNOWN; } }
From source file:org.eclipse.umlgen.reverse.java.AbstractJava2UMLConverter.java
License:Open Source License
/** * Convert an Package or a Java project into a UML2 model. * * @param javaElement/*from w w w.j av a2s. co m*/ * the JavaElement * @param actGen * @return The UML2 model or <code>null</code> if the IJavaElement is not a Package or a Java Project. * @throws CoreException * , if the resource is null or some critical error occur while importing. */ private Package convert(IJavaElement javaElement, ActivityGeneration actGen) throws CoreException { String path = null; IResource res = javaElement.getResource(); if (res != null) { path = res.getLocation().toOSString(); } else { path = javaElement.getPath().toString(); } File dir = new File(path); Java2UMLLogListener listener = new Java2UMLLogListener(dir, modelName); logger.addLogListener(listener); LogUtils.resetTabbing(); if (emfResource == null) { throwCoreException("The resource can't be null."); } switch (javaElement.getElementType()) { case IJavaElement.JAVA_PROJECT: javaProject = (IJavaProject) javaElement; return doConvertion((IJavaProject) javaElement, actGen); case IJavaElement.PACKAGE_FRAGMENT: javaProject = ((IPackageFragment) javaElement).getJavaProject(); return doConvertion((IPackageFragment) javaElement, actGen); case IJavaElement.PACKAGE_FRAGMENT_ROOT: javaProject = ((IPackageFragmentRoot) javaElement).getJavaProject(); return doConvertion((IPackageFragmentRoot) javaElement, actGen); default: return null; } }
From source file:org.eclipse.virgo.ide.bundlor.internal.core.BundlorProjectBuilder.java
License:Open Source License
private void doGetAffectedResources(IResource resource, int kind, int deltaKind) throws CoreException { IJavaProject project = JavaCore.create(getProject()); if (project == null) { return;//from ww w .java2s.c o m } IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); // Get the source folders Set<IClasspathEntry> classpathEntries = ServerModuleDelegate .getSourceClasspathEntries(resource.getProject(), false); Set<IClasspathEntry> testClasspathEntries = ServerModuleDelegate .getSourceClasspathEntries(resource.getProject(), true); // Java source files if (!this.scanByteCode && resource.getName().endsWith("java")) { //$NON-NLS-1$ IJavaElement element = JavaCore.create(resource); if (element != null && element.getJavaProject().isOnClasspath(element)) { IPackageFragmentRoot root = (IPackageFragmentRoot) element .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); try { IClasspathEntry classpathEntry = root.getRawClasspathEntry(); for (IClasspathEntry entry : classpathEntries) { if (classpathEntry.equals(entry)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedSourceResources.add(resource); } else { this.sourceResources.add(resource); } break; } } for (IClasspathEntry entry : testClasspathEntries) { if (classpathEntry.equals(entry)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedTestResources.add(resource); } else { this.testResources.add(resource); } break; } } } catch (JavaModelException e) { // This can happen in case of .java resources not on the // classpath of the project } } } // Java byte code else if (this.scanByteCode && resource.getName().endsWith(CLASS_FILE_EXTENSION)) { IPath classFilePath = resource.getFullPath(); // Check default output folders IPath defaultOutputLocation = project.getOutputLocation(); if (defaultOutputLocation.isPrefixOf(classFilePath)) { // Ok we know that the file is a class in the default output // location; let's get the class name String className = classFilePath.removeFirstSegments(defaultOutputLocation.segmentCount()) .toString(); className = className.substring(0, className.length() - CLASS_FILE_EXTENSION.length()); int ix = className.indexOf('$'); if (ix > 0) { className = className.substring(0, ix); } className = className + ".java"; if (deltaKind == IResourceDelta.REMOVED) { this.deletedSourceResources.add(resource); this.deletedTestResources.add(resource); } else { for (IClasspathEntry entry : classpathEntries) { IPath sourceLocation = entry.getPath(); IResource sourceFolder = wsRoot.findMember(sourceLocation); if (sourceFolder instanceof IFolder) { if (((IFolder) sourceFolder).findMember(className) != null) { this.sourceResources.add(resource); break; } } } for (IClasspathEntry entry : testClasspathEntries) { IPath sourceLocation = entry.getPath(); IResource sourceFolder = wsRoot.findMember(sourceLocation); if (sourceFolder instanceof IFolder) { if (((IFolder) sourceFolder).findMember(className) != null) { this.testResources.add(resource); break; } } } } } // Check output folders of source folders for (IClasspathEntry entry : classpathEntries) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(classFilePath)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedSourceResources.add(resource); } else { this.sourceResources.add(resource); } break; } } // Check output folders for test source folders for (IClasspathEntry entry : testClasspathEntries) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(classFilePath)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedTestResources.add(resource); } else { this.testResources.add(resource); } break; } } } // Some template or actual manifest file (whether or not it actually // affects packaged build) has changed. Note that this is different // behavior than // pre-Virgo server. Still, it seems reasonably conservative as worst // case we'll be re-building the project when we really don't need to, // and best case we'll catch an edge case that we would have otherwise // missed. else if (resource.getName().equals("template.mf") || resource.getName().equals("MANIFEST.MF")) { this.forceFullBuild = true; } // Hibernate mapping files else if (resource.getName().endsWith(".hbm")) { addResourceIfInSourceFolder(resource, classpathEntries, testClasspathEntries); } // JPA persistence descriptor else if (resource.getName().equals("persistence.xml") && resource.getParent() != null && resource.getParent().getName().equals("META-INF")) { addResourceIfInSourceFolder(resource, classpathEntries, testClasspathEntries); } else if (isWebXML(resource)) { this.sourceResources.add(resource); } // Spring configuration file else if (resource.getName().endsWith(".xml")) { addResourceIfInSourceFolder(resource, classpathEntries, testClasspathEntries); } }
From source file:org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils.java
License:Open Source License
/** * @return the {@link IPackageFragmentRoot} that is parent of given {@link IJavaElement} or first * {@link IPackageFragmentRoot} of {@link IJavaProject}. *//*from w ww . ja va2s . c o m*/ public static IPackageFragmentRoot getPackageFragmentRoot(IJavaElement element) throws JavaModelException { if (element != null) { // try to find valid parent IPackageFragmentRoot { IPackageFragmentRoot root = (IPackageFragmentRoot) element .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && root.getKind() == IPackageFragmentRoot.K_SOURCE) { return root; } } // use IPackageFragmentRoot of IJavaProject { IJavaProject javaProject = element.getJavaProject(); if (javaProject != null && javaProject.exists()) { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { return root; } } } } } // invalid element return null; }
From source file:org.eclipse.wb.internal.core.utils.jdt.ui.PackageRootAndPackageSelectionDialogField.java
License:Open Source License
/** * Set package.//from w w w .j a va 2 s . c o m */ public void setPackage(IPackageFragment pkg) { if (pkg != null) { m_packageField.setPackage(pkg); m_rootField.setRoot((IPackageFragmentRoot) pkg.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT)); } else { m_packageField.setPackage(null); m_rootField.setRoot(null); } }
From source file:org.eclipse.xtend.ide.javaconverter.ConvertJavaCodeHandler.java
License:Open Source License
private void collectCompilationUnits(IJavaElement elem, Set<ICompilationUnit> result) { try {/*w w w . j av a 2s . c om*/ switch (elem.getElementType()) { case IJavaElement.TYPE: if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) { result.add((ICompilationUnit) elem.getParent()); } break; case IJavaElement.COMPILATION_UNIT: result.add((ICompilationUnit) elem); break; case IJavaElement.PACKAGE_FRAGMENT: Collections.addAll(result, ((IPackageFragment) elem).getCompilationUnits()); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: for (IJavaElement child : ((IPackageFragmentRoot) elem).getChildren()) { collectCompilationUnits(child, result); } break; } } catch (JavaModelException e) { } }
From source file:org.eclipse.xtext.common.types.ui.refactoring.JvmRenameRefactoringProvider.java
License:Open Source License
/** * Copied from {@link org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode}. There does not seem to be a * clean way to initialize a JDT refactoring from the outside. */// www . ja v a 2 s. c o m public RenameJavaElementDescriptor createRenameDescriptor(IJavaElement javaElement, String newName) throws JavaModelException { String contributionId; // see RefactoringExecutionStarter#createRenameSupport(..): int elementType = javaElement.getElementType(); switch (elementType) { case IJavaElement.JAVA_PROJECT: contributionId = IJavaRefactorings.RENAME_JAVA_PROJECT; break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: contributionId = IJavaRefactorings.RENAME_SOURCE_FOLDER; break; case IJavaElement.PACKAGE_FRAGMENT: contributionId = IJavaRefactorings.RENAME_PACKAGE; break; case IJavaElement.COMPILATION_UNIT: contributionId = IJavaRefactorings.RENAME_COMPILATION_UNIT; break; case IJavaElement.TYPE: contributionId = IJavaRefactorings.RENAME_TYPE; break; case IJavaElement.METHOD: final IMethod method = (IMethod) javaElement; if (method.isConstructor()) return createRenameDescriptor(method.getDeclaringType(), newName); else contributionId = IJavaRefactorings.RENAME_METHOD; break; case IJavaElement.FIELD: IField field = (IField) javaElement; if (field.isEnumConstant()) contributionId = IJavaRefactorings.RENAME_ENUM_CONSTANT; else contributionId = IJavaRefactorings.RENAME_FIELD; break; case IJavaElement.TYPE_PARAMETER: contributionId = IJavaRefactorings.RENAME_TYPE_PARAMETER; break; case IJavaElement.LOCAL_VARIABLE: contributionId = IJavaRefactorings.RENAME_LOCAL_VARIABLE; break; default: return null; } RenameJavaElementDescriptor descriptor = (RenameJavaElementDescriptor) RefactoringCore .getRefactoringContribution(contributionId).createDescriptor(); descriptor.setJavaElement(javaElement); descriptor.setNewName(newName); if (elementType != IJavaElement.PACKAGE_FRAGMENT_ROOT) descriptor.setUpdateReferences(true); IDialogSettings javaSettings = JavaPlugin.getDefault().getDialogSettings(); IDialogSettings refactoringSettings = javaSettings.getSection(RefactoringWizardPage.REFACTORING_SETTINGS); //TODO: undocumented API if (refactoringSettings == null) { refactoringSettings = javaSettings.addNewSection(RefactoringWizardPage.REFACTORING_SETTINGS); } switch (elementType) { case IJavaElement.METHOD: case IJavaElement.FIELD: descriptor.setDeprecateDelegate(refactoringSettings.getBoolean(DelegateUIHelper.DELEGATE_DEPRECATION)); descriptor.setKeepOriginal(refactoringSettings.getBoolean(DelegateUIHelper.DELEGATE_UPDATING)); } switch (elementType) { case IJavaElement.TYPE: // case IJavaElement.COMPILATION_UNIT: // TODO descriptor.setUpdateSimilarDeclarations( refactoringSettings.getBoolean(RenameRefactoringWizard.TYPE_UPDATE_SIMILAR_ELEMENTS)); int strategy; try { strategy = refactoringSettings.getInt(RenameRefactoringWizard.TYPE_SIMILAR_MATCH_STRATEGY); } catch (NumberFormatException e) { strategy = RenamingNameSuggestor.STRATEGY_EXACT; } descriptor.setMatchStrategy(strategy); } switch (elementType) { case IJavaElement.PACKAGE_FRAGMENT: descriptor.setUpdateHierarchy( refactoringSettings.getBoolean(RenameRefactoringWizard.PACKAGE_RENAME_SUBPACKAGES)); } switch (elementType) { case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.TYPE: String fileNamePatterns = refactoringSettings.get(RenameRefactoringWizard.QUALIFIED_NAMES_PATTERNS); if (fileNamePatterns != null && fileNamePatterns.length() != 0) { descriptor.setFileNamePatterns(fileNamePatterns); boolean updateQualifiedNames = refactoringSettings .getBoolean(RenameRefactoringWizard.UPDATE_QUALIFIED_NAMES); descriptor.setUpdateQualifiedNames(updateQualifiedNames); // fShowPreview|= updateQualifiedNames; } } switch (elementType) { case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.TYPE: case IJavaElement.FIELD: boolean updateTextualOccurrences = refactoringSettings .getBoolean(RenameRefactoringWizard.UPDATE_TEXTUAL_MATCHES); descriptor.setUpdateTextualOccurrences(updateTextualOccurrences); // fShowPreview|= updateTextualOccurrences; } switch (elementType) { case IJavaElement.FIELD: descriptor .setRenameGetters(refactoringSettings.getBoolean(RenameRefactoringWizard.FIELD_RENAME_GETTER)); descriptor .setRenameSetters(refactoringSettings.getBoolean(RenameRefactoringWizard.FIELD_RENAME_SETTER)); } return descriptor; }