List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getResource
IResource getResource();
From source file:org.eclipse.viatra.query.patternlanguage.emf.ui.util.JavaProjectExpectedPackageNameProvider.java
License:Open Source License
/** * Based on org.eclipse.xtend.ide.validator.XtendUIValidator.java *//*from www . ja v a 2 s.c om*/ @Override public String getExpectedPackageName(PatternModel model) { URI fileURI = model.eResource().getURI(); for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileURI)) { if (storage.getFirst() instanceof IFile) { IPath fileWorkspacePath = storage.getFirst().getFullPath(); IJavaProject javaProject = JavaCore.create(storage.getSecond()); if (javaProject != null && javaProject.exists() && javaProject.isOpen()) { try { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (!root.isArchive() && !root.isExternal()) { IResource resource = root.getResource(); if (resource != null) { IPath sourceFolderPath = resource.getFullPath(); if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) { IPath classpathRelativePath = fileWorkspacePath .makeRelativeTo(sourceFolderPath); return classpathRelativePath.removeLastSegments(1).toString().replace("/", "."); } } } } } catch (JavaModelException e) { logger.error("Error resolving package declaration for Pattern Model", e); } } } } return null; }
From source file:org.eclipse.xtend.ide.validator.XtendUIValidator.java
License:Open Source License
protected String getExpectedPackageName(XtendFile xtendFile) { URI fileURI = xtendFile.eResource().getURI(); for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileURI)) { if (storage.getFirst() instanceof IFile) { IPath fileWorkspacePath = storage.getFirst().getFullPath(); IJavaProject javaProject = JavaCore.create(storage.getSecond()); if (javaProject != null && javaProject.exists() && javaProject.isOpen()) { try { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (!root.isArchive() && !root.isExternal()) { IResource resource = root.getResource(); if (resource != null) { IPath sourceFolderPath = resource.getFullPath(); if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) { IPath claspathRelativePath = fileWorkspacePath .makeRelativeTo(sourceFolderPath); return claspathRelativePath.removeLastSegments(1).toString().replace("/", "."); }//from w w w .j a v a 2 s . c o m } } } } catch (JavaModelException e) { LOG.error("Error resolving expected path for XtendFile", e); } } } } return null; }
From source file:org.eclipse.xtext.common.types.ui.trace.JarEntryAwareTrace.java
License:Open Source License
protected AbsoluteURI resolvePath(IJavaProject javaProject, SourceRelativeURI path) { try {/*from w ww .j a v a2 s . com*/ for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { IResource resource = root.getResource(); if (resource instanceof IFolder) { IFolder folder = (IFolder) resource; String decodedPath = URI.decode(path.toString()); IResource candidate = folder.findMember(decodedPath); if (candidate != null && candidate.exists()) return new AbsoluteURI(URI .createPlatformResourceURI(resource.getFullPath() + "/" + decodedPath, true)); } } } catch (JavaModelException e) { log.error("Error resolving path", e); } return null; }
From source file:org.eclipse.xtext.ui.containers.JavaProjectsStateHelper.java
License:Open Source License
protected IPackageFragmentRoot getJarWithEntry(URI uri) { Iterable<Pair<IStorage, IProject>> storages = getStorages(uri); IPackageFragmentRoot result = null;/*from w w w . ja v a2 s. c om*/ for (Pair<IStorage, IProject> storage2Project : storages) { IStorage storage = storage2Project.getFirst(); if (storage instanceof IJarEntryResource) { IPackageFragmentRoot fragmentRoot = ((IJarEntryResource) storage).getPackageFragmentRoot(); if (fragmentRoot != null) { // IPackageFragmentRoot has some unexpected caching - it may return a different project // thus we use the one that was used to record the IPackageFragmentRoot IProject actualProject = storage2Project.getSecond(); IJavaProject javaProject = JavaCore.create(actualProject); if (!javaProject.exists()) { javaProject = fragmentRoot.getJavaProject(); } if (isAccessibleXtextProject(javaProject.getProject())) { // if both projects are the same - fine if (javaProject.equals(fragmentRoot.getJavaProject())) return fragmentRoot; // otherwise re-obtain the fragment root from the real project if (fragmentRoot.isExternal()) { IPackageFragmentRoot actualRoot = javaProject .getPackageFragmentRoot(fragmentRoot.getPath().toString()); if (actualProject.exists()) { return actualRoot; } } else { IPackageFragmentRoot actualRoot = javaProject .getPackageFragmentRoot(fragmentRoot.getResource()); if (actualRoot.exists()) { return actualRoot; } } result = fragmentRoot; } if (result == null) result = fragmentRoot; } } } return result; }
From source file:org.eclipse.xtext.ui.generator.trace.DefaultUITraceURIConverter.java
License:Open Source License
protected URI computeTraceURI(URI uri, IJavaProject javaProject) throws JavaModelException { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { URI prefix = URI.createPlatformResourceURI( root.getResource().getFullPath().addTrailingSeparator().toString(), true); if (isPrefix(prefix, uri)) return uri.deresolve(prefix).trimFragment().trimQuery(); }/*from w w w .j a v a2 s . c o m*/ return super.getURIForTrace(uri); }
From source file:org.eclipse.xtext.ui.generator.trace.JavaProjectAwareTraceContribution.java
License:Open Source License
@Nullable protected URI computeTraceURI(URI uri, IJavaProject javaProject) throws JavaModelException { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { URI prefix = URI.createPlatformResourceURI( root.getResource().getFullPath().addTrailingSeparator().toString(), true); if (traceURIHelper.isPrefix(prefix, uri)) return uri.deresolve(prefix).trimFragment().trimQuery(); }// www.j a v a 2s. c o m } return null; }
From source file:org.eclipse.xtext.ui.resource.JarEntryURIHelper.java
License:Open Source License
public static URI getUriForPackageFragmentRoot(IPackageFragmentRoot root) { IResource underlyingResource = root.getResource(); if (underlyingResource == null) { return URI.createFileURI(root.getPath().toString()); } else {//www .j ava 2s . c om return URI.createPlatformResourceURI(underlyingResource.getFullPath().toString(), true); } }
From source file:org.eclipse.xtext.ui.util.JdtClasspathUriResolver.java
License:Open Source License
protected URI findResourceInWorkspace(IJavaProject javaProject, URI classpathUri) throws CoreException { if (javaProject.exists()) { String packagePath = classpathUri.trimSegments(1).path(); String fullPath = classpathUri.path(); String fileName = classpathUri.lastSegment(); IPath filePath = new Path(fileName); String packageName = isEmpty(packagePath) ? "" : packagePath.substring(1).replace('/', '.'); for (IPackageFragmentRoot packageFragmentRoot : javaProject.getAllPackageFragmentRoots()) { IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(packageName); if (packageFragment.exists()) { IResource packageFragmentResource = packageFragment.getResource(); if (packageFragmentResource instanceof IContainer) { IFile file = ((IContainer) packageFragmentResource).getFile(filePath); if (file.exists()) return createPlatformResourceURI(file); } else { // jar file or external class folder if (packageFragmentRoot.isArchive()) { // jar file Object[] nonJavaResources = getNonJavaResources(packageFragmentRoot, packageFragment); for (Object nonJavaResource : nonJavaResources) { IJarEntryResource jarEntryResource = (IJarEntryResource) nonJavaResource; if (fullPath.equals(jarEntryResource.getFullPath().toString())) { IResource packageFragmentRootResource = packageFragmentRoot.getResource(); if (packageFragmentRootResource != null) { // we have a resource - use nested platform/resource URI packageFragmentRootURI = createPlatformResourceURI( packageFragmentRootResource); URI result = createArchiveURI(packageFragmentRootURI, fullPath); return result; } else { // no resource - use file uri IPath packageFragmentRootPath = packageFragmentRoot.getPath(); URI packageFragmentRootURI = URI .createFileURI(packageFragmentRootPath.toString()); URI result = createArchiveURI(packageFragmentRootURI, fullPath); return result; }/*from www . j a v a2 s . c o m*/ } } } else if (packageFragmentRoot.isExternal()) { // external class folder Object[] nonJavaResources = getNonJavaResources(packageFragmentRoot, packageFragment); for (Object nonJavaResource : nonJavaResources) { IJarEntryResource jarEntryResource = (IJarEntryResource) nonJavaResource; if (fileName.equals(jarEntryResource.getName())) { IResource packageFragmentRootResource = ((ExternalPackageFragmentRoot) packageFragmentRoot) .resource(); IPath absolutePath = packageFragmentRootResource.getFullPath(); absolutePath = absolutePath.append(fullPath); return createPlatformResourceURI(absolutePath); } } } } } } // not found in a source folder - look for a resource relative to project root // of this project or one of its dependencies URI result = findResourceInProjectRoot(javaProject, classpathUri.path(), Sets.<String>newHashSet()); if (result != null) { return result; } } return classpathUri; }
From source file:org.eclipse.xtext.xbase.ui.validation.ProjectAwareUniqueClassNameValidator.java
License:Open Source License
private ProjectAwareUniqueClassNameValidator.SourceTraversal doCheckUniqueInProjectSource( final String packageName, final String typeName, final JvmDeclaredType type, final IPackageFragmentRoot[] sourceFolders) throws JavaModelException { final IndexManager indexManager = JavaModelManager.getIndexManager(); for (final IPackageFragmentRoot sourceFolder : sourceFolders) { int _awaitingJobsCount = indexManager.awaitingJobsCount(); boolean _greaterThan = (_awaitingJobsCount > 0); if (_greaterThan) { boolean _isDerived = this.isDerived(sourceFolder.getResource()); boolean _not = (!_isDerived); if (_not) { IPackageFragment packageFragment = sourceFolder.getPackageFragment(packageName); boolean _exists = packageFragment.exists(); if (_exists) { ICompilationUnit[] units = packageFragment.getCompilationUnits(); for (final ICompilationUnit unit : units) { {//from w w w. ja v a 2s . c o m final IResource resource = unit.getResource(); boolean _isDerived_1 = this.isDerived(resource); boolean _not_1 = (!_isDerived_1); if (_not_1) { IType javaType = unit.getType(typeName); boolean _exists_1 = javaType.exists(); if (_exists_1) { this.addIssue(type, unit.getElementName()); return ProjectAwareUniqueClassNameValidator.SourceTraversal.DUPLICATE; } } } } } } } else { return ProjectAwareUniqueClassNameValidator.SourceTraversal.INTERRUPT; } } return ProjectAwareUniqueClassNameValidator.SourceTraversal.UNIQUE; }
From source file:org.eclipseguru.gwt.core.launch.GwtLaunchUtil.java
License:Open Source License
/** * Adds the source folder from the specified project to the classpath list. * /* w w w .j a v a 2 s . c om*/ * @param gwtProject * @param classpath * @throws JavaModelException */ private static void addSourceFolderToClasspath(final IJavaProject project, final List<String> classpath) throws JavaModelException { if ((null == project) || !project.exists()) { return; } final IPackageFragmentRoot[] packageFragmentRoots = project.getPackageFragmentRoots(); for (final IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { classpath.add(packageFragmentRoot.getResource().getLocation().toOSString()); } } }