Java Code Examples for org.eclipse.jdt.core.JavaCore#getResolvedVariablePath()

The following examples show how to use org.eclipse.jdt.core.JavaCore#getResolvedVariablePath() . 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: BinaryRefactoringHistoryWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the location URI of the classpath entry
 *
 * @param entry
 *            the classpath entry
 * @return the location URI
 */
public static URI getLocationURI(final IClasspathEntry entry) {
	IPath path= null;
	if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE)
		path= JavaCore.getResolvedVariablePath(entry.getPath());
	else
		path= entry.getPath();
	final IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
	URI location= null;
	if (root.exists(path)) {
		location= root.getFile(path).getRawLocationURI();
	} else
		location= URIUtil.toURI(path);
	return location;
}
 
Example 2
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IClasspathEntry getConvertedEntry(IClasspathEntry entry, IJavaProject project, Map<IPath, String> oldLocationMap) {
	IPath path= null;
	switch (entry.getEntryKind()) {
		case IClasspathEntry.CPE_SOURCE:
		case IClasspathEntry.CPE_PROJECT:
			return null;
		case IClasspathEntry.CPE_CONTAINER:
			convertContainer(entry, project, oldLocationMap);
			return null;
		case IClasspathEntry.CPE_LIBRARY:
			path= entry.getPath();
			break;
		case IClasspathEntry.CPE_VARIABLE:
			path= JavaCore.getResolvedVariablePath(entry.getPath());
			break;
		default:
			return null;
	}
	if (path == null) {
		return null;
	}
	IClasspathAttribute[] extraAttributes= entry.getExtraAttributes();
	for (int i= 0; i < extraAttributes.length; i++) {
		if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(extraAttributes[i].getName())) {
			return null;
		}
	}
	String libraryJavadocLocation= oldLocationMap.get(path);
	if (libraryJavadocLocation != null) {
		CPListElement element= CPListElement.createFromExisting(entry, project);
		element.setAttribute(CPListElement.JAVADOC, libraryJavadocLocation);
		return element.getClasspathEntry();
	}
	return null;
}
 
Example 3
Source File: IDEClassPathBlock.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private static IDECPListElement createCPVariableElement( IPath path )
{
	IDECPListElement elem = new IDECPListElement( IClasspathEntry.CPE_VARIABLE,
			path,
			null );
	IPath resolvedPath = JavaCore.getResolvedVariablePath( path );
	elem.setIsMissing( ( resolvedPath == null )
			|| !resolvedPath.toFile( ).exists( ) );
	return elem;
}
 
Example 4
Source File: LibrariesWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private CPListElement createCPVariableElement(IPath path) {
	CPListElement elem= new CPListElement(fCurrJProject, IClasspathEntry.CPE_VARIABLE, path, null);
	IPath resolvedPath= JavaCore.getResolvedVariablePath(path);
	elem.setIsMissing((resolvedPath == null) || !resolvedPath.toFile().exists());
	return elem;
}
 
Example 5
Source File: CPListElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static CPListElement create(Object parent, IClasspathEntry curr, boolean newElement, IJavaProject project) {
	IPath path= curr.getPath();
	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();

	// get the resource
	IResource res= null;
	boolean isMissing= false;
	IPath linkTarget= null;

	switch (curr.getEntryKind()) {
		case IClasspathEntry.CPE_CONTAINER:
			try {
				isMissing= project != null && (JavaCore.getClasspathContainer(path, project) == null);
			} catch (JavaModelException e) {
				isMissing= true;
			}
			break;
		case IClasspathEntry.CPE_VARIABLE:
			IPath resolvedPath= JavaCore.getResolvedVariablePath(path);
			isMissing=  root.findMember(resolvedPath) == null && !resolvedPath.toFile().exists();
			break;
		case IClasspathEntry.CPE_LIBRARY:
			res= root.findMember(path);
			if (res == null) {
				if (!ArchiveFileFilter.isArchivePath(path, true)) {
					if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()
							&& root.getProject(path.segment(0)).exists()) {
						res= root.getFolder(path);
					}
				}

				IPath rawPath= path;
				if (project != null) {
					IPackageFragmentRoot[] roots= project.findPackageFragmentRoots(curr);
					if (roots.length == 1)
						rawPath= roots[0].getPath();
				}
				isMissing= !rawPath.toFile().exists(); // look for external JARs and folders
			} else if (res.isLinked()) {
				linkTarget= res.getLocation();
			}
			break;
		case IClasspathEntry.CPE_SOURCE:
			path= path.removeTrailingSeparator();
			res= root.findMember(path);
			if (res == null) {
				if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) {
					res= root.getFolder(path);
				}
				isMissing= true;
			} else if (res.isLinked()) {
				linkTarget= res.getLocation();
			}
			break;
		case IClasspathEntry.CPE_PROJECT:
			res= root.findMember(path);
			isMissing= (res == null);
			break;
	}
	CPListElement elem= new CPListElement(parent, project, curr.getEntryKind(), path, newElement, res, linkTarget);
	elem.setExported(curr.isExported());
	elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath());
	elem.setAttribute(OUTPUT, curr.getOutputLocation());
	elem.setAttribute(EXCLUSION, curr.getExclusionPatterns());
	elem.setAttribute(INCLUSION, curr.getInclusionPatterns());
	elem.setAttribute(ACCESSRULES, curr.getAccessRules());
	elem.setAttribute(COMBINE_ACCESSRULES, new Boolean(curr.combineAccessRules()));

	IClasspathAttribute[] extraAttributes= curr.getExtraAttributes();
	for (int i= 0; i < extraAttributes.length; i++) {
		IClasspathAttribute attrib= extraAttributes[i];
		CPListElementAttribute attribElem= elem.findAttributeElement(attrib.getName());
		if (attribElem == null) {
			elem.createAttributeElement(attrib.getName(), attrib.getValue(), false);
		} else {
			attribElem.setValue(attrib.getValue());
		}
	}

	elem.setIsMissing(isMissing);
	return elem;
}
 
Example 6
Source File: JavaProjectHelper.java    From spotbugs with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Adds a variable entry with source attachment to a IJavaProject. Can
 * return null if variable can not be resolved.
 *
 * @param jproject
 *            The parent project
 * @param path
 *            The variable path
 * @param sourceAttachPath
 *            The source attachment path (variable path)
 * @param sourceAttachRoot
 *            The source attachment root path (variable path)
 * @return The added package fragment root
 * @throws JavaModelException
 */
public static IPackageFragmentRoot addVariableEntry(IJavaProject jproject, IPath path, IPath sourceAttachPath,
        IPath sourceAttachRoot) throws JavaModelException {
    IClasspathEntry cpe = JavaCore.newVariableEntry(path, sourceAttachPath, sourceAttachRoot);
    addToClasspath(jproject, cpe);
    IPath resolvedPath = JavaCore.getResolvedVariablePath(path);
    if (resolvedPath != null) {
        return jproject.getPackageFragmentRoot(resolvedPath.toString());
    }
    return null;
}