List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot K_BINARY
int K_BINARY
To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_BINARY.
Click Source Link
From source file:org.jboss.tools.forge.ui.ext.control.JavaPackageChooserControlBuilder.java
License:Open Source License
/** * Adds the project source packages if no completer was specified for the * input//from w w w .j a v a 2 s . c o m */ @Override protected void decorateContainerText(ForgeWizardPage page, InputComponent<?, Object> input, Text containerText) { if (InputComponents.getCompleterFor(input) != null) { return; } final IJavaProject selectedProject = getSelectedProject(page); if (selectedProject != null) { UICompleter<Object> completer = new UICompleter<Object>() { @Override public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, Object> input, String value) { Set<String> proposals = new TreeSet<String>(); try { for (IPackageFragment pkg : selectedProject.getPackageFragments()) { if (pkg.getKind() == IPackageFragmentRoot.K_BINARY) { continue; } String name = pkg.getElementName(); if (name.startsWith(value)) { proposals.add(name); } } } catch (JavaModelException jme) { ForgeUIPlugin.log(jme); } return proposals; } }; setupAutoCompleteForText(page.getUIContext(), input, completer, containerText); } }
From source file:org.jboss.tools.forge.ui.internal.ext.control.JavaPackageChooserControlBuilder.java
License:Open Source License
/** * Adds the project source packages if no completer was specified for the * input/*from w w w . j av a2 s. c o m*/ */ @Override protected void decorateContainerText(ForgeWizardPage page, InputComponent<?, ?> input, Text containerText) { if (InputComponents.getCompleterFor(input) != null) { return; } final IJavaProject selectedProject = getSelectedProject(page); if (selectedProject != null) { UICompleter<Object> completer = new UICompleter<Object>() { @Override public Iterable<Object> getCompletionProposals(UIContext context, InputComponent<?, Object> input, String value) { Set<Object> proposals = new TreeSet<>(); try { for (IPackageFragment pkg : selectedProject.getPackageFragments()) { if (pkg.getKind() == IPackageFragmentRoot.K_BINARY) { continue; } String name = pkg.getElementName(); if (name.startsWith(value)) { proposals.add(name); } } } catch (JavaModelException jme) { ForgeUIPlugin.log(jme); } return proposals; } }; setupAutoCompleteForText(page.getWizard().getUIContext(), input, completer, containerText); } }
From source file:org.jboss.tools.maven.sourcelookup.ui.internal.util.SourceLookupUtil.java
License:Open Source License
public static void attachSource(final IPackageFragmentRoot fragment, final IPath newSourcePath, boolean displayDialog) { try {/* w ww. java 2 s . c o m*/ if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) { return; } String value = SourceLookupActivator.getDefault().getAutoAddSourceAttachment(); if (SourceLookupActivator.AUTO_ADD_JBOSS_SOURCE_ATTACHMENT_NEVER.equals(value)) { return; } if (displayDialog && SourceLookupActivator.AUTO_ADD_JBOSS_SOURCE_ATTACHMENT_PROMPT.equals(value)) { final boolean[] attach = new boolean[1]; Display.getDefault().syncExec(new Runnable() { @Override public void run() { attach[0] = promptToAddSourceAttachment(fragment.getElementName(), newSourcePath.toString()); } }); if (!attach[0]) { return; } ; } IPath containerPath = null; IJavaProject jproject = fragment.getJavaProject(); IClasspathEntry entry = fragment.getRawClasspathEntry(); if (entry == null) { entry = JavaCore.newLibraryEntry(fragment.getPath(), null, null); } else { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { containerPath = entry.getPath(); ClasspathContainerInitializer initializer = JavaCore .getClasspathContainerInitializer(containerPath.segment(0)); IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, jproject); if (initializer == null || container == null) { return; } IStatus status = initializer.getSourceAttachmentStatus(containerPath, jproject); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) { return; } if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { return; } entry = JavaModelUtil.findEntryInContainer(container, fragment.getPath()); if (entry == null) { return; } } } IClasspathEntry entry1; CPListElement elem = CPListElement.createFromExisting(entry, null); elem.setAttribute(CPListElement.SOURCEATTACHMENT, newSourcePath); entry1 = elem.getClasspathEntry(); if (entry1.equals(entry)) { return; } IClasspathEntry newEntry = entry1; String[] changedAttributes = { CPListElement.SOURCEATTACHMENT }; BuildPathSupport.modifyClasspathEntry(null, newEntry, changedAttributes, jproject, containerPath, newEntry.getReferencingEntry() != null, new NullProgressMonitor()); } catch (CoreException e) { // ignore } }
From source file:org.jboss.tools.pde.sourcelookup.core.internal.utils.ClasspathUtils.java
License:Open Source License
public static boolean isBinaryFragment(IPackageFragmentRoot pfr) { try {// w ww.j a v a2 s. c o m return pfr != null && pfr.getKind() == IPackageFragmentRoot.K_BINARY; } catch (JavaModelException e) { return false; } }
From source file:org.jboss.tools.pde.sourcelookup.core.internal.utils.ClasspathUtils.java
License:Open Source License
public static void attachSource(final IPackageFragmentRoot fragment, final IPath newSourcePath, IProgressMonitor monitor) {//from w w w . ja v a 2s . c om try { if (fragment == null || fragment.getKind() != IPackageFragmentRoot.K_BINARY) { return; } if (!Objects.equals(fragment.getSourceAttachmentPath(), newSourcePath)) { // would be so cool if it refreshed the UI automatically fragment.attachSource(newSourcePath, null, monitor); // close the root so that source attachment cache is flushed. Else UI // won't update fragment.close(); // we have to manually fire a delta to notify the UI about the source // attachment. JavaModelManager manager = JavaModelManager.getJavaModelManager(); JavaElementDelta attachedSourceDelta = new JavaElementDelta(fragment.getJavaModel()); attachedSourceDelta.sourceAttached(fragment); manager.getDeltaProcessor().fire(attachedSourceDelta, ElementChangedEvent.POST_CHANGE); } } catch (CoreException e) { // ignore } }
From source file:org.jboss.tools.pde.sourcelookup.ui.internal.actions.DownloadSourcesActionDelegate.java
License:Open Source License
private boolean isBinaryProject(IPackageFragmentRoot fragment) { try {/*from ww w . j a v a 2 s.c om*/ return fragment.getKind() == IPackageFragmentRoot.K_BINARY; } catch (JavaModelException e) { return false; } }
From source file:org.seasar.s2daoplugin.util.JavaProjectUtil.java
License:Apache License
public static IPackageFragmentRoot[] findPackageFragmentRootsSharedOutputLocation(IPackageFragmentRoot root) { if (root == null) { return new IPackageFragmentRoot[0]; }//w ww . ja v a 2s .c o m IJavaProject project = root.getJavaProject(); Set result = new HashSet(); try { IPath output1 = root.getRawClasspathEntry().getOutputLocation(); if (output1 == null) { output1 = project.getOutputLocation(); } IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_BINARY) { continue; } IPath output2 = roots[i].getRawClasspathEntry().getOutputLocation(); if (output2 == null) { output2 = project.getOutputLocation(); } if (output1.equals(output2)) { result.add(roots[i]); } } } catch (JavaModelException e) { S2DaoPlugin.log(e); } return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]); }
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()); }// ww w .j a va 2s . c om } } return nonJavaResources; }
From source file:org.springframework.ide.eclipse.beans.ui.properties.NonJavaResourceContentProvider.java
License:Open Source License
private Object[] getNonJavaResources(IPackageFragmentRoot root) throws JavaModelException { Object[] nonJavaResources = root.getNonJavaResources(); // Replace JAR entries with our own wrapper if (root.getKind() == IPackageFragmentRoot.K_BINARY && root.getResource() instanceof IFile) { for (int i = 0; i < nonJavaResources.length; i++) { Object resource = nonJavaResources[i]; if (resource instanceof IStorage) { IStorage storage = (IStorage) resource; nonJavaResources[i] = new ZipEntryStorage((IFile) root.getResource(), storage.getFullPath().toString()); }/*from ww w . j av a 2 s .c om*/ } } return nonJavaResources; }
From source file:org.springframework.ide.eclipse.boot.properties.editor.StsConfigMetadataRepositoryJsonLoader.java
License:Open Source License
/** * Load the {@link ConfigMetadataRepository} with the metadata of the current * classpath using the {@link #DEFAULT_LOCATION_PATTERN}. If the same config * metadata items is held within different resources, the first that is * loaded is kept which means the result is not deterministic. */// w w w .jav a2 s . c o m public ConfigurationMetadataRepository load(IJavaProject project) throws Exception { debug(">> load ConfigurationMetadataRepository for " + project.getElementName()); IClasspathEntry[] classpath = project.getResolvedClasspath(true); for (IClasspathEntry e : classpath) { int ekind = e.getEntryKind(); int ckind = e.getContentKind(); IPath path = e.getPath(); if (ekind == IClasspathEntry.CPE_LIBRARY && ckind == IPackageFragmentRoot.K_BINARY) { //jar file dependency File jarFile = path.toFile(); if (FileUtil.isJarFile(jarFile)) { loadFromJar(jarFile); } } else if (ekind == IClasspathEntry.CPE_PROJECT) { loadFromProjectDependency(e); } else { debug("Skipped: " + ekind(ekind) + " " + ckind(ckind) + ": " + path); } } loadFromOutputFolder(project); debug("<< load ConfigurationMetadataRepository for " + project.getElementName() + ": " + repository.getAllProperties().size() + " properties"); return repository; }