List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE
int K_SOURCE
To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE.
Click Source Link
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(); }/* w w w. ja v a 2 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(); }/*from w w w .j ava 2 s . c o m*/ } return null; }
From source file:org.eclipse.xtext.xbase.ui.editor.XbaseEditorInputRedirector.java
License:Open Source License
/** * @param an input//from www .j av a2 s . c o m * * @return the original source for an editor input that points to an Xtext resource copied to the output folder, the given input otherwise */ public IEditorInput findOriginalSourceForOuputFolderCopy(final IEditorInput input) { try { final IFile resource = ResourceUtil.getFile(input); if ((resource != null)) { boolean _isValid = this.fileExtensionProvider.isValid(resource.getFullPath().getFileExtension()); if (_isValid) { final IJavaProject project = JavaCore.create(resource.getProject()); boolean _exists = project.exists(); if (_exists) { boolean _isPrefixOf = project.getOutputLocation().isPrefixOf(resource.getFullPath()); if (_isPrefixOf) { final IPath relative = resource.getFullPath() .removeFirstSegments(project.getOutputLocation().segmentCount()); final Function1<IPackageFragmentRoot, Boolean> _function = ( IPackageFragmentRoot it) -> { try { int _kind = it.getKind(); return Boolean.valueOf((_kind == IPackageFragmentRoot.K_SOURCE)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; Iterable<IPackageFragmentRoot> _filter = IterableExtensions .<IPackageFragmentRoot>filter(((Iterable<IPackageFragmentRoot>) Conversions .doWrapArray(project.getPackageFragmentRoots())), _function); for (final IPackageFragmentRoot source : _filter) { { final IPath fullPath = source.getCorrespondingResource() .getProjectRelativePath().append(relative); final IFile newFile = resource.getProject().getFile(fullPath); boolean _exists_1 = newFile.exists(); if (_exists_1) { return new FileEditorInput(newFile); } } } } final Function1<IClasspathEntry, Boolean> _function_1 = (IClasspathEntry it) -> { int _entryKind = it.getEntryKind(); return Boolean.valueOf((_entryKind == IClasspathEntry.CPE_SOURCE)); }; Iterable<IClasspathEntry> _filter_1 = IterableExtensions.<IClasspathEntry>filter( ((Iterable<IClasspathEntry>) Conversions.doWrapArray(project.getRawClasspath())), _function_1); for (final IClasspathEntry sourceFolder : _filter_1) { if (((sourceFolder.getOutputLocation() != null) && sourceFolder.getOutputLocation().isPrefixOf(resource.getFullPath()))) { final IPath relative_1 = resource.getFullPath() .removeFirstSegments(sourceFolder.getOutputLocation().segmentCount()); final IPackageFragmentRoot source_1 = IterableExtensions .<IPackageFragmentRoot>head(((Iterable<IPackageFragmentRoot>) Conversions .doWrapArray(project.findPackageFragmentRoots(sourceFolder)))); final IPath fullPath = source_1.getCorrespondingResource().getProjectRelativePath() .append(relative_1); final IFile newFile = resource.getProject().getFile(fullPath); boolean _exists_1 = newFile.exists(); if (_exists_1) { return new FileEditorInput(newFile); } } } } } } return input; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
From source file:org.eclipse.xtext.xbase.ui.imports.MultiOrganizeImportsHandler.java
License:Open Source License
private void collectRelevantFiles(IPackageFragmentRoot root, Multimap<IProject, IFile> result) throws JavaModelException { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { IJavaElement[] children = root.getChildren(); for (int i = 0; i < children.length; i++) { collectRelevantFiles((IPackageFragment) children[i], result); }/* w w w . ja v a 2s. c om*/ } }
From source file:org.eclipse.xtext.xbase.ui.validation.ProjectAwareUniqueClassNameValidator.java
License:Open Source License
public boolean doCheckUniqueInProject(final QualifiedName name, final JvmDeclaredType type) throws JavaModelException { final IJavaProject javaProject = this.javaProjectProvider.getJavaProject(type.eResource().getResourceSet()); this.getContext().put(ProjectAwareUniqueClassNameValidator.OUTPUT_CONFIGS, this.outputConfigurationProvider.getOutputConfigurations(type.eResource())); final String packageName = type.getPackageName(); final String typeName = type.getSimpleName(); final Function1<IPackageFragmentRoot, Boolean> _function = (IPackageFragmentRoot it) -> { try {//from w w w .ja v a 2 s . c om int _kind = it.getKind(); return Boolean.valueOf((_kind == IPackageFragmentRoot.K_SOURCE)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; final Iterable<IPackageFragmentRoot> sourceFolders = IterableExtensions.<IPackageFragmentRoot>filter( ((Iterable<IPackageFragmentRoot>) Conversions.doWrapArray(javaProject.getPackageFragmentRoots())), _function); IndexManager indexManager = JavaModelManager.getIndexManager(); if (((((Object[]) Conversions.unwrapArray(sourceFolders, Object.class)).length == 0) || (indexManager.awaitingJobsCount() > 0))) { String _elvis = null; if (packageName != null) { _elvis = packageName; } else { _elvis = ""; } ProjectAwareUniqueClassNameValidator.SourceTraversal _doCheckUniqueInProjectSource = this .doCheckUniqueInProjectSource(_elvis, typeName, type, ((IPackageFragmentRoot[]) Conversions .unwrapArray(sourceFolders, IPackageFragmentRoot.class))); if (_doCheckUniqueInProjectSource != null) { switch (_doCheckUniqueInProjectSource) { case DUPLICATE: return false; case UNIQUE: return true; default: break; } } else { } } final HashSet<String> workingCopyPaths = CollectionLiterals.<String>newHashSet(); ICompilationUnit[] copies = this.getWorkingCopies(type); if ((copies != null)) { for (final ICompilationUnit workingCopy : copies) { { final IPath path = workingCopy.getPath(); if ((javaProject.getPath().isPrefixOf(path) && (!this.isDerived(workingCopy.getResource())))) { boolean _exists = workingCopy.getPackageDeclaration(packageName).exists(); if (_exists) { IType result = workingCopy.getType(typeName); boolean _exists_1 = result.exists(); if (_exists_1) { this.addIssue(type, workingCopy.getElementName()); return false; } } workingCopyPaths.add(workingCopy.getPath().toString()); } } } } char[] _xifexpression = null; if ((packageName == null)) { _xifexpression = CharOperation.NO_CHAR; } else { _xifexpression = packageName.toCharArray(); } char[] _charArray = typeName.toCharArray(); final TypeDeclarationPattern pattern = new TypeDeclarationPattern(_xifexpression, CharOperation.NO_CHAR_CHAR, _charArray, IIndexConstants.TYPE_SUFFIX, (SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE)); final IndexQueryRequestor _function_1 = new IndexQueryRequestor() { @Override public boolean acceptIndexMatch(final String documentPath, final SearchPattern indexRecord, final SearchParticipant participant, final AccessRuleSet access) { boolean _contains = workingCopyPaths.contains(documentPath); if (_contains) { return true; } IWorkspaceRoot _root = ResourcesPlugin.getWorkspace().getRoot(); Path _path = new Path(documentPath); IFile file = _root.getFile(_path); boolean _isDerived = ProjectAwareUniqueClassNameValidator.this.isDerived(file); boolean _not = (!_isDerived); if (_not) { ProjectAwareUniqueClassNameValidator.this.addIssue(type, file.getName()); return false; } return true; } }; IndexQueryRequestor searchRequestor = _function_1; try { SearchParticipant _defaultSearchParticipant = BasicSearchEngine.getDefaultSearchParticipant(); IJavaSearchScope _createJavaSearchScope = BasicSearchEngine.createJavaSearchScope( ((IJavaElement[]) Conversions.unwrapArray(sourceFolders, IJavaElement.class))); PatternSearchJob _patternSearchJob = new PatternSearchJob(pattern, _defaultSearchParticipant, _createJavaSearchScope, searchRequestor); indexManager.performConcurrentJob(_patternSearchJob, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); return true; } catch (final Throwable _t) { if (_t instanceof OperationCanceledException) { final OperationCanceledException oce = (OperationCanceledException) _t; return false; } else { throw Exceptions.sneakyThrow(_t); } } }
From source file:org.eclipseguru.gwt.core.GwtProject.java
License:Open Source License
/** * @param project/* w w w.ja v a 2 s .c o m*/ * @return * @throws CoreException */ protected GwtModule[] findModules() throws CoreException { final IJavaProject javaProject = getJavaProject(); final List<GwtModule> moduleFiles = new ArrayList<GwtModule>(); for (final IPackageFragmentRoot aRoot : javaProject.getPackageFragmentRoots()) { // check only in source folders. Skip others if (aRoot.getKind() != IPackageFragmentRoot.K_SOURCE) { continue; } for (final IJavaElement aPackage : aRoot.getChildren()) { // look only for packages. Skip others if (aPackage.getElementType() != IJavaElement.PACKAGE_FRAGMENT) { continue; } for (final Object aResource : ((IPackageFragment) aPackage).getNonJavaResources()) { // look only files. Skip others if (!(aResource instanceof IFile)) { continue; } final IFile aFile = (IFile) aResource; if (GwtUtil.isModuleDescriptor(aFile)) { moduleFiles.add(createModule(aFile)); } } } } return moduleFiles.toArray(new GwtModule[moduleFiles.size()]); }
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. * /*from w ww. j av a 2s.c o m*/ * @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()); } } }
From source file:org.eclipselabs.stlipse.util.ProjectUtil.java
License:Open Source License
public static IPackageFragmentRoot getFirstSourceRoot(IJavaProject project) throws JavaModelException { IPackageFragmentRoot pkgRoot = null; for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { // Use the first source folder. pkgRoot = root;/*from ww w . java 2 s.c o m*/ break; } } return pkgRoot; }
From source file:org.entirej.ide.ui.editors.descriptors.AbstractProjectSrcFileDescriptor.java
License:Apache License
@Override public String browseType() { List<IPackageFragmentRoot> elements = new ArrayList<IPackageFragmentRoot>(); IJavaProject javaProject = projectProvider.getJavaProject(); try {//from w w w .j a v a2 s . c o m IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { elements.add(roots[i]); } } } catch (JavaModelException e) { EJCoreLog.logException(e); } final List<IResource> resources = new ArrayList<IResource>(); for (IPackageFragmentRoot root : elements) { try { IResource resource = root.getResource(); if (resource instanceof IContainer) ((IContainer) resource).accept(new IResourceProxyVisitor() { public boolean visit(IResourceProxy proxy) { if (proxy.isDerived()) { return false; } int type = proxy.getType(); if ((IResource.FILE & type) != 0) { IResource res = proxy.requestResource(); resources.add(res); return true; } if (type == IResource.FILE) { return false; } return true; } }, IResource.NONE); } catch (CoreException e) { // ignore } } ResourceListSelectionDialog dialog = new ResourceListSelectionDialog(EJUIPlugin.getActiveWorkbenchShell(), resources.toArray(new IResource[0])); dialog.setTitle("Select File"); dialog.setMessage("Select a project file:"); if (dialog.open() == Window.OK) { Object[] result = dialog.getResult(); if (result != null && result.length > 0) { IResource resource = (IResource) result[0]; String chosenPath = resource.getFullPath().toPortableString(); // Return the chosen package without the source directory path for (IPackageFragmentRoot root : elements) { String sourcePath = root.getPath().toPortableString(); if (chosenPath.startsWith(sourcePath)) { chosenPath = chosenPath.replace(sourcePath, ""); break; } } return chosenPath; } } return getValue(); }
From source file:org.entirej.ide.ui.utils.JavaAccessUtils.java
License:Apache License
public static IPackageFragment[] choosePackage(Shell shell, IJavaProject javaProject, String filter, Boolean multipleSelection, IPackageFragmentFilter packageFragmentFilter) { List<IPackageFragment> elements = new ArrayList<IPackageFragment>(); if (javaProject.exists()) { try {//from w w w .j av a 2 s . com IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { IPackageFragmentRoot sourceRoot = roots[i]; if (sourceRoot != null && sourceRoot.exists()) { IJavaElement[] children = sourceRoot.getChildren(); for (IJavaElement element : children) { if (element instanceof IPackageFragment && (packageFragmentFilter == null || packageFragmentFilter.acccept((IPackageFragment) element))) elements.add((IPackageFragment) element); } } } } } catch (JavaModelException e) { EJCoreLog.logException(e); } } ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT)); dialog.setIgnoreCase(false); dialog.setTitle("Package Selection"); dialog.setMessage("Choose a folder"); dialog.setFilter(filter); dialog.setMultipleSelection(multipleSelection); dialog.setEmptyListMessage(""); dialog.setElements(elements.toArray(new IPackageFragment[0])); dialog.setHelpAvailable(false); if (dialog.open() == Window.OK) { Object[] result = dialog.getResult(); IPackageFragment[] fragments = new IPackageFragment[result.length]; for (int i = 0; i < result.length; i++) { fragments[i] = (IPackageFragment) result[i]; } return fragments; } return new IPackageFragment[0]; }