List of usage examples for org.eclipse.jdt.core IJavaProject getElementName
String getElementName();
From source file:org.eclipse.xtext.builder.impl.javasupport.JdtToBeBuiltComputer.java
License:Open Source License
protected boolean isBuiltByUpstream(IPackageFragmentRoot root, IProject project, IProject[] projectsInCorrectBuildOrder) { for (IProject p : projectsInCorrectBuildOrder) { if (p.equals(project)) return false; if (XtextProjectHelper.hasNature(p) && XtextProjectHelper.hasBuilder(p)) { IJavaProject javaProject = JavaCore.create(p); if (javaProject.exists()) { if (javaProject.isOnClasspath(root)) { if (log.isTraceEnabled()) log.trace("Build of project '" + project.getName() + "' skips indexing classpath entry '" + root.getPath() + "' because it already indexed by " + javaProject.getElementName()); return true; }//from w w w. j av a2 s . co m } } } return false; }
From source file:org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.java
License:Open Source License
/** * @since 2.7//from w w w . j ava 2 s .com */ protected JvmDeclaredType createType(IType jdtType, IJavaProject javaProject) { if (jdtType.getDeclaringType() != null) throw new IllegalArgumentException( "Cannot create type from non-toplevel-type: '" + jdtType.getFullyQualifiedName() + "'."); IBinding binding = resolveBindings(jdtType, javaProject); if (binding == null) { IJavaProject fallbackProject = jdtType.getJavaProject(); // fallback to the project of the given jdtType if it is different from the explicitly given project if (!fallbackProject.equals(javaProject)) { binding = resolveBindings(jdtType, fallbackProject); if (binding == null) { throw new IllegalStateException("Could not create binding for '" + jdtType.getFullyQualifiedName() + "' in context of projects '" + javaProject.getElementName() + "' and '" + fallbackProject.getElementName() + "'."); } } else { throw new IllegalStateException("Could not create binding for '" + jdtType.getFullyQualifiedName() + "' in context of project '" + javaProject.getElementName() + "'."); } } if (binding instanceof ITypeBinding) { createType.start(); ITypeBinding typeBinding = (ITypeBinding) binding; setMayTolerateMissingType(typeBinding); JvmDeclaredType result = createType(jdtType, typeBinding); // Clear the cached information. // clearCache(); createType.stop(); return result; } else { throw new IllegalStateException("Expected ITypeBinding for '" + jdtType.getFullyQualifiedName() + "', but got '" + binding.toString() + "'."); } }
From source file:org.eclipse.xtext.common.types.access.jdt.WorkingCopyOwnerProvider.java
License:Open Source License
@Override public WorkingCopyOwner getWorkingCopyOwner(final IJavaProject javaProject, final ResourceSet resourceSet) { return new WorkingCopyOwner() { @Override// www .jav a 2 s .co m public String findSource(String typeName, String packageName) { if (packageName.startsWith("java")) return super.findSource(typeName, packageName); QualifiedName qn = toQualifiedName(packageName, typeName); final IResourceDescriptions descriptions = descriptionsProvider .getResourceDescriptions(resourceSet); Iterator<IEObjectDescription> exportedObjects = descriptions .getExportedObjects(TypesPackage.Literals.JVM_DECLARED_TYPE, qn, false).iterator(); while (exportedObjects.hasNext()) { IEObjectDescription candidate = exportedObjects.next(); URI uri = candidate.getEObjectURI(); if (uri.isPlatformResource() && URI.decode(uri.segment(1)).equals(javaProject.getElementName())) { IResourceDescription resourceDescription = descriptions .getResourceDescription(uri.trimFragment()); return getSource(typeName, packageName, candidate, resourceSet, resourceDescription); } } return super.findSource(typeName, packageName); } /** * not implemented because we don't have a proper index for Java package names and the very rare cases in which this would * cause trouble are not worth the general degrade in performance. */ @Override public boolean isPackage(String[] pkg) { return super.isPackage(pkg); } }; }
From source file:org.eclipse.xtext.common.types.xtext.ui.JdtIndexedJvmTypeAccess.java
License:Open Source License
@Override protected EObject findAccessibleType(String fragment, ResourceSet resourceSet, Iterator<IEObjectDescription> fromIndex) throws UnknownNestedTypeException { // we know that the iterator is not empty thus we can directly obtain the handles et al without additional guards IJavaProject javaProject = javaProjectProvider.getJavaProject(resourceSet); List<String> allVisibleContainerHandles = Lists .newArrayList(javaProjectsState.getVisibleContainerHandles(javaProject.getHandleIdentifier())); // some models are not in source folders thus we also use the WorkspaceProjectsState (e.g. relevant for Xcore) allVisibleContainerHandles/*from w ww . j a v a 2s. c o m*/ .addAll(plainProjectsState.getVisibleContainerHandles(javaProject.getElementName())); List<String> visibleContainerHandles = allVisibleContainerHandles; IEObjectDescription bestDescription = null; while (fromIndex.hasNext() && !visibleContainerHandles.isEmpty()) { // find the description that is the best match, e.g. the one that is in the container closest to the first IEObjectDescription description = fromIndex.next(); URI trimFragment = description.getEObjectURI().trimFragment(); String handle = javaProjectsState.getContainerHandle(trimFragment); int idx = visibleContainerHandles.indexOf(handle); if (idx >= 0) { bestDescription = description; // reduce the search scope - only check containers that are better than the current visibleContainerHandles = allVisibleContainerHandles.subList(0, idx); } } if (bestDescription != null) { return getAccessibleType(bestDescription, fragment, resourceSet); } return null; }
From source file:org.eclipse.xtext.common.types.xtext.ui.ProjectAwareResourceDescriptionsProvider.java
License:Open Source License
@Override protected String getProjectName(final ResourceSet resourceSet) { final IJavaProject javaProject = this.projectProvider.getJavaProject(resourceSet); String _elementName = null;/* w ww .j a v a 2 s.co m*/ if (javaProject != null) { _elementName = javaProject.getElementName(); } return _elementName; }
From source file:org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl.java
License:Open Source License
/** * @since 2.4/*from www . j a v a 2 s . co m*/ */ private void updateCache(IJavaProject project) { Set<PackageFragmentRootData> datas = newHashSet(); try { if (project.exists() && project.getProject().isAccessible()) { for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) { boolean isCachable = root.isArchive() || root.isExternal(); if (isCachable) datas.add(getCachedData(root)); } } } catch (JavaModelException e) { if (!e.isDoesNotExist()) log.error("Error getting package fragments roots of " + project.getElementName(), e); } finally { clearCache(project, datas); } }
From source file:org.eclipse.xtext.ui.util.JdtClasspathUriResolver.java
License:Open Source License
private URI findResourceInProjectRoot(IJavaProject javaProject, String path, Set<String> visited) throws CoreException { boolean includeAll = visited.isEmpty(); if (visited.add(javaProject.getElementName())) { IProject project = javaProject.getProject(); IResource resourceFromProjectRoot = project.findMember(path); if (resourceFromProjectRoot != null && resourceFromProjectRoot.exists()) { return createPlatformResourceURI(resourceFromProjectRoot); }//from w ww . j a va2 s.c o m for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { if (includeAll || entry.isExported()) { IResource referencedProject = project.getWorkspace().getRoot().findMember(entry.getPath()); if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) { IJavaProject referencedJavaProject = JavaCore.create((IProject) referencedProject); if (referencedJavaProject.exists()) { URI result = findResourceInProjectRoot(referencedJavaProject, path, visited); if (result != null) { return result; } } } break; } } } } return null; }
From source file:org.eclipse.xtext.xbase.ui.validation.XbaseUIValidator.java
License:Open Source License
protected void checkRestrictedType(final EObject context, final EStructuralFeature feature, final JvmDeclaredType typeToCheck) { @SuppressWarnings("unchecked") Map<JvmDeclaredType, RestrictionKind> validationContext = (Map<JvmDeclaredType, RestrictionKind>) getContext() .get(RestrictionKind.class); if (validationContext == null) { validationContext = Maps.newHashMap(); getContext().put(RestrictionKind.class, validationContext); }// w w w .j a va2 s . co m RestrictionKind restriction = validationContext.get(typeToCheck); IJavaProject javaProject = null; if (restriction == null) { final IJavaElement javaElement = javaElementFinder.findElementFor(typeToCheck); if (javaElement == null || !(javaElement instanceof IType)) { validationContext.put(typeToCheck, RestrictionKind.VALID); return; } javaProject = javaElement.getJavaProject(); restriction = computeRestriction(projectProvider.getJavaProject(context.eResource().getResourceSet()), (IType) javaElement); validationContext.put(typeToCheck, restriction); } if (restriction == RestrictionKind.FORBIDDEN) { if (javaProject == null) javaProject = projectProvider.getJavaProject(context.eResource().getResourceSet()); addIssue("Access restriction: The type " + typeToCheck.getSimpleName() + " is not accessible due to restriction on required project " + javaProject.getElementName(), context, feature, IssueCodes.FORBIDDEN_REFERENCE); } else if (restriction == RestrictionKind.DISCOURAGED) { if (javaProject == null) javaProject = projectProvider.getJavaProject(context.eResource().getResourceSet()); addIssue("Discouraged access: The type " + typeToCheck.getSimpleName() + " is not accessible due to restriction on required project " + javaProject.getElementName(), context, feature, IssueCodes.DISCOURAGED_REFERENCE); } }
From source file:org.eclipse.zest.dot.internal.ZestBuilder.java
License:Open Source License
private void importToGeneratedSourceFolder(final IFile dotFile) { try {/*from w ww.jav a2 s .co m*/ IJavaProject javaProject = JavaCore.create(dotFile.getProject()); String sourceGenPath = "/" + javaProject.getElementName() + "/" + ZestProjectWizard.SRC_GEN; IPackageFragmentRoot packageRoot = javaProject.findPackageFragmentRoot(new Path(sourceGenPath)); IPackageFragment targetPackage = packageRoot.getPackageFragment(ZestProjectWizard.PACKAGE); IResource targetFolder = targetPackage.getCorrespondingResource(); new DotImport(dotFile).newGraphSubclass((IContainer) targetFolder); targetFolder.refreshLocal(1, null); } catch (CoreException e) { e.printStackTrace(); } }
From source file:org.evolizer.famix.importer.ProjectParser.java
License:Apache License
/** * Main parsing method. Traverses Eclipse Java project tree, creates package structure and parses each contained * compilation unit.//from ww w . jav a 2s . c o m * * @param project * Selected Eclipse Java project. * @param monitor * Progress monitor. * @return Status. */ protected IStatus parseProject(IJavaProject project, IProgressMonitor monitor) { sLogger.debug("Processing Java-Project: " + project.getElementName()); IStatus status = Status.OK_STATUS; // try { List<IPackageFragment> fragments = getSourcePackages(project); SubMonitor progress = SubMonitor.convert(monitor, 100); progress.setTaskName("Parse project " + project.getElementName()); SubMonitor loopProgress = progress.newChild(100).setWorkRemaining(fragments.size()); // float tick = 100F / fragments.size(); // int workDone = 0; for (IPackageFragment lFragment : fragments) { status = parsePackageFragment(lFragment, loopProgress.newChild(1)); // workDone += tick; // progress.setWorkRemaining(100-workDone); if (status.getSeverity() == IStatus.CANCEL) { break; } } // } catch (JavaModelException e) { // sLogger.error("Can not get package fragments of the Java-Project " + // project.getElementName()+": "+e.getMessage(),e); // } sLogger.debug("Processing of Java-Project " + project.getElementName() + " complete"); return status; }