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:com.codenvy.ide.ext.java.server.internal.core.search.matching.PackageReferenceLocator.java
License:Open Source License
public static boolean isDeclaringPackageFragment(IPackageFragment packageFragment, ReferenceBinding typeBinding) {//from w ww.j a v a 2s . c om char[] fileName = typeBinding.getFileName(); if (fileName != null) { // retrieve the actual file name from the full path (sources are generally only containing it already) fileName = CharOperation.replaceOnCopy(fileName, '/', '\\'); // ensure to not do any side effect on file name (see https://bugs.eclipse // .org/bugs/show_bug.cgi?id=136016) fileName = CharOperation.lastSegment(fileName, '\\'); try { switch (packageFragment.getKind()) { case IPackageFragmentRoot.K_SOURCE: if (!org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(fileName) || !packageFragment.getCompilationUnit(new String(fileName)).exists()) { return false; // unit doesn't live in selected package } break; case IPackageFragmentRoot.K_BINARY: // if (Util.isJavaFileName(fileName)) { // binary with attached source // int length = fileName.length; // System.arraycopy(fileName, 0, fileName = new char[length], 0, length - 4); // copy all but extension // System.arraycopy(SuffixConstants.SUFFIX_class, 0, fileName, length - 4, 4); // } if (!Util.isClassFileName(fileName) || !packageFragment.getClassFile(new String(fileName)).exists()) { return false; // classfile doesn't live in selected package } break; } } catch (JavaModelException e) { // unable to determine kind; tolerate this match } } return true; // by default, do not eliminate }
From source file:com.codenvy.ide.ext.java.server.javadoc.JavaDocLocations.java
License:Open Source License
/** * Returns the reason for why the Javadoc of the Java element could not be retrieved. * * @param element whose Javadoc could not be retrieved * @param root the root of the Java element * @return the String message for why the Javadoc could not be retrieved for the Java element or * <code>null</code> if the Java element is from a source container * @since 3.9//from w w w . ja v a 2s . c o m */ public static String getExplanationForMissingJavadoc(IJavaElement element, IPackageFragmentRoot root) { String message = null; try { boolean isBinary = (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY); if (isBinary) { boolean hasAttachedJavadoc = JavaDocLocations.getJavadocBaseLocation(element) != null; boolean hasAttachedSource = root.getSourceAttachmentPath() != null; IOpenable openable = element.getOpenable(); boolean hasSource = openable.getBuffer() != null; // Provide hint why there's no Java doc if (!hasAttachedSource && !hasAttachedJavadoc) message = CorextMessages.JavaDocLocations_noAttachments; else if (!hasAttachedJavadoc && !hasSource) message = CorextMessages.JavaDocLocations_noAttachedJavadoc; else if (!hasAttachedSource) message = CorextMessages.JavaDocLocations_noAttachedSource; else if (!hasSource) message = CorextMessages.JavaDocLocations_noInformation; } } catch (JavaModelException e) { message = CorextMessages.JavaDocLocations_error_gettingJavadoc; LOG.error(message, e); } return message; }
From source file:com.drgarbage.asm.render.impl.PackageFragment.java
License:Apache License
public int getKind() throws JavaModelException { return IPackageFragmentRoot.K_BINARY; }
From source file:com.drgarbage.bytecodevisualizer.editors.NoSourceViewer.java
License:Apache License
private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root) throws JavaModelException { IClasspathEntry entry;// w ww .j a v a 2 s. com try { entry = root.getRawClasspathEntry(); } catch (JavaModelException ex) { if (ex.isDoesNotExist()) entry = null; else throw ex; } IPath containerPath = null; if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) { String s = CoreMessages.SourceAttachmentForm_message_noSource; createLabel(composite, MessageFormat.format(s, new Object[] { fFile.getElementName() })); return; } IJavaProject jproject = root.getJavaProject(); 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) { createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_cannotconfigure, new Object[] { containerPath.toString() })); return; } String containerName = container.getDescription(); IStatus status = initializer.getSourceAttachmentStatus(containerPath, jproject); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) { createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_notsupported, new Object[] { containerName })); return; } if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_readonly, new Object[] { containerName })); return; } entry = JavaModelUtil.findEntryInContainer(container, root.getPath()); Assert.isNotNull(entry); } Button button; String msg = null; String btnText = null; IPath path = entry.getSourceAttachmentPath(); if (path == null || path.isEmpty()) { msg = MessageFormat.format(CoreMessages.SourceAttachmentForm_message_noSourceAttachment, new Object[] { root.getElementName() }); btnText = CoreMessages.SourceAttachmentForm_button_attachSource; } else { msg = MessageFormat.format(CoreMessages.SourceAttachmentForm_message_noSourceInAttachment, new Object[] { fFile.getElementName() }); btnText = CoreMessages.SourceAttachmentForm_button_changeAttachedSource; } createLabel(composite, msg); createLabel(composite, CoreMessages.SourceAttachmentForm_message_pressButtonToAttach); createLabel(composite, null); button = createButton(composite, btnText); button.addSelectionListener(createButtonListener(entry, containerPath, jproject)); }
From source file:com.ebmwebsourcing.petals.common.internal.projectscnf.JarFragmentFilter.java
License:Open Source License
@Override public boolean select(Viewer viewer, Object parentElement, Object element) { IPackageFragmentRoot fragmentRoot = null; if (element instanceof IPackageFragmentRoot) { fragmentRoot = (IPackageFragmentRoot) element; } else if (element instanceof TreePath) { Object o = ((TreePath) element).getFirstSegment(); if (o instanceof IPackageFragmentRoot) fragmentRoot = (IPackageFragmentRoot) o; }/*from www.jav a2 s. c o m*/ boolean result = true; try { if (fragmentRoot != null) { result = fragmentRoot.getKind() != IPackageFragmentRoot.K_BINARY; } } catch (JavaModelException e) { PetalsCommonPlugin.log(e, IStatus.ERROR); } return result; }
From source file:com.google.gdt.eclipse.appengine.rpc.util.JavaUtils.java
License:Open Source License
public static IStatus validateContainer(String packageRootText) { StatusInfo status = new StatusInfo(); String str = packageRootText; if (str.length() == 0) { status.setError("Source folder name is empty."); //$NON-NLS-1$ return status; }/*from w w w.j ava 2 s .co m*/ IPath path = new Path(str); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource res = workspaceRoot.findMember(path); if (res != null) { int resType = res.getType(); if (resType == IResource.PROJECT || resType == IResource.FOLDER) { IProject proj = res.getProject(); if (!proj.isOpen()) { status.setError(Messages.format(NewWizardMessages.NewContainerWizardPage_error_ProjectClosed, BasicElementLabels.getPathLabel(proj.getFullPath(), false))); return status; } IJavaProject jproject = JavaCore.create(proj); IPackageFragmentRoot root = jproject.getPackageFragmentRoot(res); if (res.exists()) { if (isVirtual(res)) { status.setError("Source folder cannot be a virtual folder."); //$NON-NLS-1$ return status; } try { if (!proj.hasNature(JavaCore.NATURE_ID)) { if (resType == IResource.PROJECT) { status.setError(NewWizardMessages.NewContainerWizardPage_warning_NotAJavaProject); } else { status.setWarning( NewWizardMessages.NewContainerWizardPage_warning_NotInAJavaProject); } return status; } if (root.isArchive()) { status.setError(Messages.format( NewWizardMessages.NewContainerWizardPage_error_ContainerIsBinary, BasicElementLabels.getPathLabel(path, false))); return status; } if (root.getKind() == IPackageFragmentRoot.K_BINARY) { status.setWarning(Messages.format( NewWizardMessages.NewContainerWizardPage_warning_inside_classfolder, BasicElementLabels.getPathLabel(path, false))); } else if (!jproject.isOnClasspath(root)) { status.setWarning( Messages.format(NewWizardMessages.NewContainerWizardPage_warning_NotOnClassPath, BasicElementLabels.getPathLabel(path, false))); } } catch (JavaModelException e) { status.setWarning(NewWizardMessages.NewContainerWizardPage_warning_NotOnClassPath); } catch (CoreException e) { status.setWarning(NewWizardMessages.NewContainerWizardPage_warning_NotAJavaProject); } } return status; } else { status.setError(Messages.format(NewWizardMessages.NewContainerWizardPage_error_NotAFolder, BasicElementLabels.getPathLabel(path, false))); return status; } } else { status.setError(Messages.format(NewWizardMessages.NewContainerWizardPage_error_ContainerDoesNotExist, BasicElementLabels.getPathLabel(path, false))); return status; } }
From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java
License:Open Source License
/** * Find the classpath for get-dev.jar which is used to run super dev mode. * * @return IClasspathEntry for the path to gwt-dev.jar * @throws JavaModelException/*www . j a va2 s.c o m*/ */ private IClasspathEntry findGwtCodeServerClasspathEntry() throws JavaModelException { IType type = javaProject .findType(GwtLaunchConfigurationProcessorUtilities.SUPERDEVMODE_CODESERVER_MAIN_TYPE); if (type == null) { return null; } IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) { return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null); } return null; }
From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java
License:Open Source License
private IClasspathEntry findGwtUserClasspathEntry() throws JavaModelException { /*/*from w ww . j a va 2 s . com*/ * Note that the type that we're looking for to determine if we're part of the gwt-user library * is different than the one that is used by the superclass. This is because the class that the * superclass is querying for, "com.google.gwt.core.client.GWT", also exists in the gwt-servlet * library, and for some reason, this sometimes ends up on the build path for Maven projects. * * TODO: See why Maven is putting gwt-servlet on the build path. * * TODO: Change the class query in the superclass to "com.google.gwt.junit.client.GWTTestCase" */ IType type = javaProject.findType("com.google.gwt.junit.client.GWTTestCase"); if (type == null) { return null; } IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) { // TODO: If the Maven javadoc and source libs for gwt-dev.jar are // available, attach them here. return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null); } return null; }
From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java
License:Open Source License
private IClasspathEntry findJavaXValidationClasspathEntry() throws JavaModelException { IType type = javaProject.findType("javax.validation.Constraint"); if (type == null) { return null; }/* w w w . ja v a 2 s . co m*/ IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) { return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null); } return null; }
From source file:com.google.gwt.eclipse.core.runtime.GWTJarsRuntimeTest.java
License:Open Source License
public void testGetClasspathEntries() throws Exception { IClasspathEntry[] cpEntries = runtime.getClasspathEntries(); // Look for the gwt-specific classpath entries List<IClasspathEntry> gwtCpEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry cpEntry : cpEntries) { if (isGWTJar(runtime, cpEntry.getPath().lastSegment())) { gwtCpEntries.add(cpEntry);//from ww w . j ava 2 s . c o m } } // Make sure that there are two of them assertEquals(3, gwtCpEntries.size()); for (int i = 0; i < gwtCpEntries.size(); i++) { IClasspathEntry gwtClasspathEntry = gwtCpEntries.get(i); assertEquals(IClasspathEntry.CPE_LIBRARY, gwtClasspathEntry.getEntryKind()); assertEquals(IPackageFragmentRoot.K_BINARY, gwtClasspathEntry.getContentKind()); // Verify that our classpath entries point at the GWT javadoc. IClasspathAttribute[] extraAttributes = gwtClasspathEntry.getExtraAttributes(); assertTrue("No extra attributes seen for classpath entry: " + gwtClasspathEntry, extraAttributes.length > 0); assertEquals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, extraAttributes[0].getName()); /* * Entries should have their javadoc location point at a directory with "index.html". * Strangely, the values of these classpath attributes are specified as "file://" urls. */ File jdLocation = new File(new URL(extraAttributes[0].getValue()).getFile()); assertTrue("Javadoc file does not exist", jdLocation.exists()); List<String> files1 = Arrays.asList(jdLocation.list()); assertTrue("Javadoc file is not an index.html file.", files1.contains("index.html")); } }