org.eclipse.jdt.core.IPackageFragmentRoot Java Examples

The following examples show how to use org.eclipse.jdt.core.IPackageFragmentRoot. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnresolvedTypesQuickFixTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDontImportTestClassesInMainCode() throws Exception {
	IPackageFragmentRoot testSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src-tests", new Path[0], new Path[0], "bin-tests",
			new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true") });

	IPackageFragment pack1 = fSourceFolder.createPackageFragment("pp", false, null);
	StringBuilder buf1 = new StringBuilder();
	buf1.append("package pp;\n");
	buf1.append("public class C1 {\n");
	buf1.append("    Tests at=new Tests();\n");
	buf1.append("}\n");
	ICompilationUnit cu1 = pack1.createCompilationUnit("C1.java", buf1.toString(), false, null);

	IPackageFragment pack2 = testSourceFolder.createPackageFragment("pt", false, null);
	StringBuilder buf2 = new StringBuilder();
	buf2.append("package pt;\n");
	buf2.append("public class Tests {\n");
	buf2.append("}\n");
	pack2.createCompilationUnit("Tests.java", buf2.toString(), false, null);

	assertCodeActionNotExists(cu1, "Import 'Tests' (pt)");
}
 
Example #2
Source File: JdtTypeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.9
 */
protected boolean canLink(IType type) throws JavaModelException {
	IndexedJvmTypeAccess indexedJvmTypeAccess = this.getIndexedJvmTypeAccess();
	if (indexedJvmTypeAccess != null && indexedJvmTypeAccess.isIndexingPhase(getResourceSet())) {
		IResource underlyingResource = type.getUnderlyingResource();
		if (underlyingResource == null) {
			return true;
		}
		for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
				IResource srcUnderlyingResource = root.getUnderlyingResource();
				if (srcUnderlyingResource != null && srcUnderlyingResource.contains(underlyingResource)) {
					return false;
				}
			}
		}
		return true;
	}
	return true;
}
 
Example #3
Source File: CopyQualifiedNameAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getQualifiedName(Object element) throws JavaModelException {
	if (element instanceof IResource)
		return ((IResource)element).getFullPath().toString();

	if (element instanceof IJarEntryResource)
		return ((IJarEntryResource)element).getFullPath().toString();

	if (element instanceof LogicalPackage)
		return ((LogicalPackage)element).getElementName();

	if (element instanceof IJavaProject || element instanceof IPackageFragmentRoot || element instanceof ITypeRoot) {
		IResource resource= ((IJavaElement)element).getCorrespondingResource();
		if (resource != null)
			return getQualifiedName(resource);
	}

	if (element instanceof IBinding)
		return BindingLabelProvider.getBindingLabel((IBinding)element, LABEL_FLAGS);

	return TextProcessor.deprocess(JavaElementLabels.getTextLabel(element, LABEL_FLAGS));
}
 
Example #4
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean canEnable() throws JavaModelException {
	if (!super.canEnable() || fPackageFragmentRoots.length == 0) {
		return false;
	}
	for (int i= 0; i < fPackageFragmentRoots.length; i++) {
		IPackageFragmentRoot root= fPackageFragmentRoots[i];
		if (!(ReorgUtils.isSourceFolder(root) || root.isArchive() && !root.isExternal())) {
			return false;
		}
	}
	if (ReorgUtils.containsLinkedResources(fPackageFragmentRoots)) {
		return false;
	}
	return true;
}
 
Example #5
Source File: JavaClassPathResourceForIEditorInputFactoryTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test(expected=CoreException.class) public void testBug463258_05() throws Throwable {
	IJavaProject project = createJavaProject("foo");
	IPackageFragmentRoot root = project.getPackageFragmentRoot("does/not/exist.jar");
	IPackageFragment foo = root.getPackageFragment("foo");
	final JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage");
	fileInJar.setParent(foo);
	XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
	try {
		factory.createResource(editorInput);
	} catch(WrappedException e) {
		throw e.getCause();
	}
}
 
Example #6
Source File: JavaWorkingSetPageContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean hasChildren(Object element) {

	if (element instanceof IProject && !((IProject)element).isAccessible())
		return false;

	if (element instanceof IPackageFragment) {
		IPackageFragment pkg= (IPackageFragment)element;
		try {
			if (pkg.getKind() == IPackageFragmentRoot.K_BINARY) {
				// Don't show IJarEntryResource
				return pkg.getChildren().length > 0;
			}
		} catch (JavaModelException ex) {
			// use super behavior
		}
	}
	return super.hasChildren(element);
}
 
Example #7
Source File: FindStringsToExternalizeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private NonNLSElement[] doRun(IStructuredSelection selection, IProgressMonitor pm) throws CoreException {
	List<?> elements= getSelectedElementList(selection);
	if (elements == null || elements.isEmpty())
		return new NonNLSElement[0];

	pm.beginTask(ActionMessages.FindStringsToExternalizeAction_find_strings, elements.size());

	try{
		List<NonNLSElement> l= new ArrayList<NonNLSElement>();
		for (Iterator<?> iter= elements.iterator(); iter.hasNext();) {
			IJavaElement element= (IJavaElement) iter.next();
			if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT)
				l.addAll(analyze((IPackageFragment) element, new SubProgressMonitor(pm, 1)));
			else if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT)
				l.addAll(analyze((IPackageFragmentRoot) element, new SubProgressMonitor(pm, 1)));
			if (element.getElementType() == IJavaElement.JAVA_PROJECT)
				l.addAll(analyze((IJavaProject) element, new SubProgressMonitor(pm, 1)));
		}
		return l.toArray(new NonNLSElement[l.size()]);
	} finally{
		pm.done();
	}
}
 
Example #8
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Change createChange(IProgressMonitor pm) throws JavaModelException {
	IPackageFragment[] fragments= getPackages();
	pm.beginTask("", fragments.length); //$NON-NLS-1$
	CompositeChange result= new DynamicValidationStateChange(RefactoringCoreMessages.ReorgPolicy_move_package);
	result.markAsSynthetic();
	IPackageFragmentRoot root= getDestinationAsPackageFragmentRoot();
	for (int i= 0; i < fragments.length; i++) {
		if (root == null) {
			result.add(createChange(fragments[i], (IContainer)getResourceDestination()));
		} else {
			result.add(createChange(fragments[i], root));
		}
		pm.worked(1);
		if (pm.isCanceled()) {
			throw new OperationCanceledException();
		}
	}
	pm.done();
	return result;
}
 
Example #9
Source File: LibraryFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	if (element instanceof IPackageFragmentRoot) {
		IPackageFragmentRoot root= (IPackageFragmentRoot)element;
		if (root.isArchive()) {
			// don't filter out JARs contained in the project itself
			IResource resource= root.getResource();
			if (resource != null) {
				IProject jarProject= resource.getProject();
				IProject container= root.getJavaProject().getProject();
				return container.equals(jarProject);
			}
			return false;
		}
	} else if (element instanceof ClassPathContainer.RequiredProjectWrapper) {
		return false;
	}
	return true;
}
 
Example #10
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public Change createChange(IProgressMonitor pm) throws JavaModelException {
	IPackageFragment[] fragments= getPackages();
	pm.beginTask("", fragments.length); //$NON-NLS-1$
	CompositeChange result= new DynamicValidationStateChange(RefactoringCoreMessages.ReorgPolicy_move_package);
	result.markAsSynthetic();
	IPackageFragmentRoot root= getDestinationAsPackageFragmentRoot();
	for (int i= 0; i < fragments.length; i++) {
		if (root == null) {
			result.add(createChange(fragments[i], (IContainer)getResourceDestination()));
		} else {
			result.add(createChange(fragments[i], root));
		}
		pm.worked(1);
		if (pm.isCanceled())
			throw new OperationCanceledException();
	}
	pm.done();
	return result;
}
 
Example #11
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IJavaElement destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError())
		return superStatus;

	Object commonParent= new ParentChecker(getResources(), getJavaElements()).getCommonParent();
	if (destination.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && (destinationAsContainer.equals(commonParent) || commonParent instanceof IPackageFragmentRoot
			&& destinationAsContainer.equals(((IPackageFragmentRoot) commonParent).getResource())))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IPackageFragment destinationAsPackage= getDestinationAsPackageFragment();
	if (destinationAsPackage != null && (destinationAsPackage.equals(commonParent)))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);

	if (cannotUpdateReferencesForDestination())
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);

	return superStatus;
}
 
Example #12
Source File: JavadocContentAccess2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static String getSourceAttachmentEncoding(IPackageFragmentRoot root) throws JavaModelException {
	String encoding= ResourcesPlugin.getEncoding();
	IClasspathEntry entry= root.getRawClasspathEntry();

	if (entry != null) {
		int kind= entry.getEntryKind();
		if (kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_VARIABLE) {
			IClasspathAttribute[] extraAttributes= entry.getExtraAttributes();
			for (int i= 0; i < extraAttributes.length; i++) {
				IClasspathAttribute attrib= extraAttributes[i];
				if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) {
					return attrib.getValue();
				}
			}
		}
	}

	return encoding;
}
 
Example #13
Source File: PackagesView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String formatLogicalPackageMessage(LogicalPackage logicalPackage) {
	IPackageFragment[] fragments= logicalPackage.getFragments();
	StringBuffer buf= new StringBuffer(logicalPackage.getElementName());
	buf.append(JavaElementLabels.CONCAT_STRING);
	String message= ""; //$NON-NLS-1$
	boolean firstTime= true;
	for (int i= 0; i < fragments.length; i++) {
		IPackageFragment fragment= fragments[i];
		IJavaElement element= fragment.getParent();
		if (element instanceof IPackageFragmentRoot) {
			IPackageFragmentRoot root= (IPackageFragmentRoot) element;
			String label= JavaElementLabels.getElementLabel(root, JavaElementLabels.DEFAULT_QUALIFIED | JavaElementLabels.ROOT_QUALIFIED);
			if (firstTime) {
				buf.append(label);
				firstTime= false;
			}
			else
				message= Messages.format(JavaBrowsingMessages.StatusBar_concat, new String[] {message, label});
		}
	}
	buf.append(message);
	return buf.toString();
}
 
Example #14
Source File: ConvertJavaCodeHandler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private void collectCompilationUnits(IJavaElement elem, Set<ICompilationUnit> result) {
	try {
		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) {
	}
}
 
Example #15
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RefactoringModifications getModifications() throws CoreException {
	if (fModifications != null) {
		return fModifications;
	}

	fModifications= new MoveModifications();
	boolean updateReferences= getUpdateReferences();
	IPackageFragment[] packages= getPackages();
	IPackageFragmentRoot javaDestination= getDestinationAsPackageFragmentRoot();
	for (int i= 0; i < packages.length; i++) {
		if (javaDestination == null) {
			fModifications.move(packages[i].getResource(), new MoveArguments(getResourceDestination(), updateReferences));
		} else {
			fModifications.move(packages[i], new MoveArguments(javaDestination, updateReferences));
		}
	}
	return fModifications;
}
 
Example #16
Source File: AddResourcesToClientBundleDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void setPackageFragmentForTypeCompletion() {
  IPackageFragment pckgFragment = null;
  IJavaProject javaProject = getJavaProject();
  if (javaProject != null) {
    try {
      IPackageFragmentRoot[] srcRoots = javaProject.getPackageFragmentRoots();
      if (srcRoots.length > 0) {
        // Just use the default package of the first source root we find
        pckgFragment = srcRoots[0].getPackageFragment("");
      }
    } catch (JavaModelException e) {
      GWTPluginLog.logError(e);
    }
  }
  resourceTypeCompletionProcessor.setPackageFragment(pckgFragment);
}
 
Example #17
Source File: JavaElementLabelComposer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Appends the label for a package fragment. Considers the P_* flags.
 *
 * @param pack the element to render
 * @param flags the rendering flags. Flags with names starting with P_' are considered.
 */
public void appendPackageFragmentLabel(IPackageFragment pack, long flags) {
	if (getFlag(flags, JavaElementLabels.P_QUALIFIED)) {
		appendPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED);
		fBuilder.append('/');
	}
	if (pack.isDefaultPackage()) {
		fBuilder.append(JavaElementLabels.DEFAULT_PACKAGE);
	} else if (getFlag(flags, JavaElementLabels.P_COMPRESSED)) {
		appendCompressedPackageFragment(pack);
	} else {
		fBuilder.append(getElementName(pack));
	}
	if (getFlag(flags, JavaElementLabels.P_POST_QUALIFIED)) {
		fBuilder.append(JavaElementLabels.CONCAT_STRING);
		appendPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED);
	}
}
 
Example #18
Source File: SemanticHighlightingTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDidOpen_autoBoxing() throws Exception {
	String content = "package _package;\n"
			+ "\n"
			+ "public class A {\n" +
			"  public static void main(String[] args) {\n" +
			"    Integer integer = Integer.valueOf(36);\n" +
			"    System.out.println(10 + integer);\n" +
			"  }\n" +
			"}";
	int version = 1;
	IJavaProject project = newEmptyProject();
	IPackageFragmentRoot src = project.getPackageFragmentRoot(project.getProject().getFolder("src"));
	IPackageFragment _package = src.createPackageFragment("_package", false, null);
	ICompilationUnit unit = _package.createCompilationUnit("A.java", content, false, null);
	openDocument(unit, unit.getSource(), version);

	assertEquals(1, javaClient.params.size());
	List<SemanticHighlightingInformation> lines = javaClient.params.get(0).getLines();
	assertEquals(4, lines.size());
	SemanticHighlightingInformation line5 = FluentIterable.from(lines).firstMatch(line -> line.getLine() == 5).get();
	SemanticHighlightingTokens.Token unboxingToken = FluentIterable.from(decode(line5.getTokens())).firstMatch(token -> token.character == 28).get();
	assertEquals(unboxingToken.length, 7);
	assertThat(SemanticHighlightingService.getScopes(unboxingToken.scope), hasItem("variable.other.autoboxing.java"));
}
 
Example #19
Source File: DiagnosticHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUnnecessary() throws Exception {
	IJavaProject javaProject = newEmptyProject();
	IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);

	StringBuilder buf = new StringBuilder();
	buf.append("package test1;\n");
	buf.append("import java.security.*;\n");
	ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);

	CompilationUnit asRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, monitor);
	IProblem[] problems = asRoot.getProblems();
	List<Diagnostic> diagnostics = DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems), true);
	assertEquals(1, diagnostics.size());
	List<DiagnosticTag> tags = diagnostics.get(0).getTags();
	assertEquals(1, tags.size());
	assertEquals(DiagnosticTag.Unnecessary, tags.get(0));
}
 
Example #20
Source File: JavaSearchScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean encloses(IJavaElement element) {
	if (this.elements != null) {
		for (int i = 0, length = this.elements.size(); i < length; i++) {
			IJavaElement scopeElement = (IJavaElement)this.elements.get(i);
			IJavaElement searchedElement = element;
			while (searchedElement != null) {
				if (searchedElement.equals(scopeElement))
					return true;
				searchedElement = searchedElement.getParent();
			}
		}
		return false;
	}
	IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
	if (root != null && root.isArchive()) {
		// external or internal jar
		IPath rootPath = root.getPath();
		String rootPathToString = rootPath.getDevice() == null ? rootPath.toString() : rootPath.toOSString();
		IPath relativePath = getPath(element, true/*relative path*/);
		return indexOf(rootPathToString, relativePath.toString()) >= 0;
	}
	// resource in workspace
	String fullResourcePathString = getPath(element, false/*full path*/).toString();
	return indexOf(fullResourcePathString) >= 0;
}
 
Example #21
Source File: PackagesViewHierarchicalContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IPackageFragment[] findNextLevelChildrenByElementName(IPackageFragmentRoot parent, IPackageFragment fragment) {
	List<IPackageFragment> list= new ArrayList<IPackageFragment>();
	try {

		IJavaElement[] children= parent.getChildren();
		String fragmentname= fragment.getElementName();
		for (int i= 0; i < children.length; i++) {
			IJavaElement element= children[i];
			if (element instanceof IPackageFragment) {
				IPackageFragment frag= (IPackageFragment) element;

				String name= element.getElementName();
				if (name.length() > fragmentname.length() && name.charAt(fragmentname.length()) == '.' && frag.exists() && !IPackageFragment.DEFAULT_PACKAGE_NAME.equals(fragmentname) && name.startsWith(fragmentname) && !name.equals(fragmentname)) {
					String tail= name.substring(fragmentname.length() + 1);
					if (!IPackageFragment.DEFAULT_PACKAGE_NAME.equals(tail) && tail.indexOf('.') == -1) {
						list.add(frag);
					}
				}
			}
		}

	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
	return list.toArray(new IPackageFragment[list.size()]);
}
 
Example #22
Source File: JavadocProjectContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Object[] getPackageFragmentRoots(IJavaProject project) throws JavaModelException {
	ArrayList<Object> result= new ArrayList<Object>();

	IPackageFragmentRoot[] roots= project.getPackageFragmentRoots();
	for (int i= 0; i < roots.length; i++) {
		IPackageFragmentRoot root= roots[i];
		if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
			if (root.getPath().equals(root.getJavaProject().getPath())) {
				Object[] packageFragments= getPackageFragments(root);
				for (int k= 0; k < packageFragments.length; k++) {
					result.add(packageFragments[k]);
				}
			} else {
				result.add(root);
			}
		}
	}
	return result.toArray();
}
 
Example #23
Source File: JavaProjectsStateHelper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected IPackageFragmentRoot getJavaElement(final IFile file) {
	IJavaProject jp = JavaCore.create(file.getProject());
	if (!jp.exists())
		return null;
	IPackageFragmentRoot[] roots;
	try {
		roots = jp.getPackageFragmentRoots();
		for (IPackageFragmentRoot root : roots) {
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
				IResource resource2 = root.getUnderlyingResource();
				if (resource2.contains(file))
					return root;
			}
		}
	} catch (JavaModelException e) {
		if (!e.isDoesNotExist())
			log.error(e.getMessage(), e);
	}
	return null;
}
 
Example #24
Source File: JavaElementLabelComposer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Appends the label for a package fragment. Considers the P_* flags.
 *
 * @param pack the element to render
 * @param flags the rendering flags. Flags with names starting with P_' are considered.
 */
public void appendPackageFragmentLabel(IPackageFragment pack, long flags) {
	if (getFlag(flags, JavaElementLabels.P_QUALIFIED)) {
		appendPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED);
		fBuffer.append('/');
	}
	if (pack.isDefaultPackage()) {
		fBuffer.append(JavaElementLabels.DEFAULT_PACKAGE);
	} else if (getFlag(flags, JavaElementLabels.P_COMPRESSED)) {
		if (isPackageNameAbbreviationEnabled())
			appendAbbreviatedPackageFragment(pack);
		else
			appendCompressedPackageFragment(pack);
	} else {
		fBuffer.append(getElementName(pack));
	}
	if (getFlag(flags, JavaElementLabels.P_POST_QUALIFIED)) {
		int offset= fBuffer.length();
		fBuffer.append(JavaElementLabels.CONCAT_STRING);
		appendPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED);
		if (getFlag(flags, JavaElementLabels.COLORIZE)) {
			fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
		}
	}
}
 
Example #25
Source File: JavaClassPathResourceForIEditorInputFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ResourceSet getResourceSet(/* @Nullable */ IStorage storage) {
	if (storage instanceof IJarEntryResource) {
		IPackageFragmentRoot root = ((IJarEntryResource) storage).getPackageFragmentRoot();
		if (root != null) {
			IJavaProject project = root.getJavaProject();
			if (project != null)
				return getResourceSetProvider().get(project.getProject());
		}
	} 
	return super.getResourceSet(storage);
}
 
Example #26
Source File: GWTJarsRuntimeTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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);
    }
  }

  // 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"));
  }
}
 
Example #27
Source File: JdtClasspathUriResolver.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private Object[] getNonJavaResources(IPackageFragmentRoot packageFragmentRoot, IPackageFragment packageFragment)
		throws JavaModelException {
	Object[] nonJavaResources = null;
	if (packageFragment.isDefaultPackage()) {
		nonJavaResources = packageFragmentRoot.getNonJavaResources();
	} else {
		nonJavaResources = packageFragment.getNonJavaResources();
	}
	return nonJavaResources;
}
 
Example #28
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check whether the input parameter of type <code>
 * IPackageFragmentRoot</code> has either it's inclusion or
 * exclusion filter or both set (that means they are
 * not empty).
 *
 * @param root the fragment root to be inspected
 * @return <code>true</code> inclusion or exclusion filter set,
 * <code>false</code> otherwise.
 * @throws JavaModelException
 */
public static boolean filtersSet(IPackageFragmentRoot root) throws JavaModelException {
	if (root == null)
		return false;
	IClasspathEntry entry= root.getRawClasspathEntry();
	IPath[] inclusions= entry.getInclusionPatterns();
	IPath[] exclusions= entry.getExclusionPatterns();
	if (inclusions != null && inclusions.length > 0)
		return true;
	if (exclusions != null && exclusions.length > 0)
		return true;
	return false;
}
 
Example #29
Source File: LoggedCreateTargetQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void createPackageFragmentRoot(IPackageFragmentRoot root) throws CoreException {
	final IJavaProject project= root.getJavaProject();
	if (!project.exists())
		createJavaProject(project.getProject());
	final IFolder folder= project.getProject().getFolder(root.getElementName());
	if (!folder.exists())
		CoreUtility.createFolder(folder, true, true, new NullProgressMonitor());
	final List<IClasspathEntry> list= Arrays.asList(project.getRawClasspath());
	list.add(JavaCore.newSourceEntry(folder.getFullPath()));
	project.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), new NullProgressMonitor());
}
 
Example #30
Source File: BuildpathIndicatorLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void processDelta(IJavaElementDelta delta, List<IJavaElement> result) {
	IJavaElement elem= delta.getElement();

	boolean isChanged= delta.getKind() == IJavaElementDelta.CHANGED;
	boolean isRemoved= delta.getKind() == IJavaElementDelta.REMOVED;
	int flags= delta.getFlags();

	switch (elem.getElementType()) {
		case IJavaElement.JAVA_MODEL:
			processChildrenDelta(delta, result);
			return;
		case IJavaElement.JAVA_PROJECT:
			if (isRemoved || (isChanged &&
					(flags & IJavaElementDelta.F_CLOSED) != 0)) {
				return;
			}
			processChildrenDelta(delta, result);
			return;
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			if (isRemoved) {
				return;
			}
			try {
				if ((((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) ||
						((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0))
						&& ((IPackageFragmentRoot)elem).getKind() != IPackageFragmentRoot.K_SOURCE) {
					result.add(elem);
				}
			} catch (JavaModelException e) {
				// don't update
			}
			return;
		default:
			return;
	}
}