org.eclipse.jdt.internal.core.PackageFragment Java Examples
The following examples show how to use
org.eclipse.jdt.internal.core.PackageFragment.
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: WorkspaceEventsHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private ICompilationUnit createCompilationUnit(ICompilationUnit unit) { try { unit.getResource().refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor()); if (unit.getResource().exists()) { IJavaElement parent = unit.getParent(); if (parent instanceof PackageFragment) { PackageFragment pkg = (PackageFragment) parent; if (JavaModelManager.determineIfOnClasspath(unit.getResource(), unit.getJavaProject()) != null) { OpenableElementInfo elementInfo = (OpenableElementInfo) pkg.getElementInfo(); elementInfo.addChild(unit); } } } } catch (CoreException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return unit; }
Example #2
Source File: MatchLocator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean filterEnum(SearchMatch match) { // filter org.apache.commons.lang.enum package for projects above 1.5 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=317264 IJavaElement element = (IJavaElement)match.getElement(); PackageFragment pkg = (PackageFragment)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (pkg != null) { // enum was found in org.apache.commons.lang.enum at index 5 if (pkg.names.length == 5 && pkg.names[4].equals("enum")) { //$NON-NLS-1$ if (this.options == null) { IJavaProject proj = (IJavaProject)pkg.getAncestor(IJavaElement.JAVA_PROJECT); String complianceStr = proj.getOption(CompilerOptions.OPTION_Source, true); if (CompilerOptions.versionToJdkLevel(complianceStr) >= ClassFileConstants.JDK1_5) return true; } else if (this.options.sourceLevel >= ClassFileConstants.JDK1_5) { return true; } } } return false; }
Example #3
Source File: JavaSearchScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IPath getPath(IJavaElement element, boolean relativeToRoot) { switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: return Path.EMPTY; case IJavaElement.JAVA_PROJECT: return element.getPath(); case IJavaElement.PACKAGE_FRAGMENT_ROOT: if (relativeToRoot) return Path.EMPTY; return element.getPath(); case IJavaElement.PACKAGE_FRAGMENT: String relativePath = Util.concatWith(((PackageFragment) element).names, '/'); return getPath(element.getParent(), relativeToRoot).append(new Path(relativePath)); case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return getPath(element.getParent(), relativeToRoot).append(new Path(element.getElementName())); default: return getPath(element.getParent(), relativeToRoot); } }
Example #4
Source File: TypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public IJavaElement getJavaElement() { JavaElement element = getUnresolvedJavaElement(); if (element != null) return element.resolved(this.binding); if (isRecovered()) { IPackageBinding packageBinding = getPackage(); if (packageBinding != null) { final IJavaElement javaElement = packageBinding.getJavaElement(); if (javaElement != null && javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { // best effort: we don't know if the recovered binding is a binary or source binding, so go with a simple source type return ((PackageFragment) javaElement).getCompilationUnit(new String(this.binding.sourceName()) + SuffixConstants.SUFFIX_STRING_java).getType(this.getName()); } } return null; } return null; }
Example #5
Source File: Util.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static final boolean isExcluded(IJavaElement element) { int elementType = element.getElementType(); switch (elementType) { case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: return false; case IJavaElement.PACKAGE_FRAGMENT: PackageFragmentRoot root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IResource resource = ((PackageFragment) element).resource(); return resource != null && isExcluded(resource, root.fullInclusionPatternChars(), root.fullExclusionPatternChars()); case IJavaElement.COMPILATION_UNIT: root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); resource = element.getResource(); if (resource == null) return false; if (isExcluded(resource, root.fullInclusionPatternChars(), root.fullExclusionPatternChars())) return true; return isExcluded(element.getParent()); default: IJavaElement cu = element.getAncestor(IJavaElement.COMPILATION_UNIT); return cu != null && isExcluded(cu); } }
Example #6
Source File: RecoveredTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public IJavaElement getJavaElement() { IPackageBinding packageBinding = getPackage(); if (packageBinding != null) { final IJavaElement javaElement = packageBinding.getJavaElement(); if (javaElement != null && javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { // best effort: we don't know if the recovered binding is a binary or source binding, so go with a simple source type return ((PackageFragment) javaElement).getCompilationUnit(getInternalName() + SuffixConstants.SUFFIX_STRING_java).getType(this.getName()); } } return null; }
Example #7
Source File: BonitaExplorerLabelProvider.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public Image getImage(Object element) { RepositoryManager repositoryManager = RepositoryManager.getInstance(); if (!repositoryManager.hasActiveRepository() || !repositoryManager.getCurrentRepository().isLoaded()) { return super.getImage(element); } if (!(element instanceof IJavaElement)) { if (element instanceof IResource) { Optional<? extends IRepositoryFileStore> fileStore = asFileStore(element, repositoryManager); if (fileStore.isPresent()) { return fileStore .map(IRepositoryFileStore::getIcon) .map(icon -> packageExplorerProblemsDecorator.decorateImage(icon, element)) .orElse(super.getImage(element)); } } } if (!(element instanceof PackageFragment)) { Optional<IRepositoryStore<? extends IRepositoryFileStore>> repositoryStore = repositoryManager .getRepositoryStore(element); if (repositoryStore.isPresent()) { IRepositoryStore<? extends IRepositoryFileStore> store = repositoryStore.get(); return packageExplorerProblemsDecorator.decorateImage(store.getIcon(), element); } } return super.getImage(element); }
Example #8
Source File: CustomGroovyLanguageSupport.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public CompilationUnit newCompilationUnit(PackageFragment parent, String name, WorkingCopyOwner owner) { if (ContentTypeUtils.isGroovyLikeFileName(name)) { return new BonitaScriptGroovyCompilationUnit(parent, name, owner) ; } else { return new CompilationUnit(parent, name, owner); } }
Example #9
Source File: AbstractNewXtendElementWizardPage.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
private ICompilationUnit getCompilationUnitStub() { String compilationUnitName = getCompilationUnitName(getTypeName()); return new CompilationUnit((PackageFragment) getPackageFragment(), compilationUnitName, DefaultWorkingCopyOwner.PRIMARY); }
Example #10
Source File: AssistCompilationUnit.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public AssistCompilationUnit(ICompilationUnit compilationUnit, WorkingCopyOwner owner, Map bindingCache, Map infoCache) { super((PackageFragment)compilationUnit.getParent(), compilationUnit.getElementName(), owner); this.bindingCache = bindingCache; this.infoCache = infoCache; }
Example #11
Source File: AbstractNewSarlElementWizardPage.java From sarl with Apache License 2.0 | 4 votes |
private ICompilationUnit getCompilationUnitStub() { final String compilationUnitName = getCompilationUnitName(getTypeName()); return new CompilationUnit((PackageFragment) getPackageFragment(), compilationUnitName, DefaultWorkingCopyOwner.PRIMARY); }
Example #12
Source File: BonitaScriptGroovyCompilationUnit.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
public BonitaScriptGroovyCompilationUnit(PackageFragment parent, String name, WorkingCopyOwner owner) { super(parent, name, owner); }
Example #13
Source File: WorkingCopyOwner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Returns a new working copy with the given name using this working copy owner to * create its buffer. * <p> * This working copy always belongs to the default package in a package * fragment root that corresponds to its Java project, and this Java project never exists. * However this Java project has the given classpath that is used when resolving names * in this working copy. * </p><p> * A DOM AST created using this working copy will have bindings resolved using the given * classpath, and problem are reported to the given problem requestor. * <p></p> * <code>JavaCore#getOptions()</code> is used to create the DOM AST as it is not * possible to set the options on the non-existing Java project. * </p><p> * When the working copy instance is created, an {@link IJavaElementDelta#ADDED added delta} is * reported on this working copy. * </p><p> * Once done with the working copy, users of this method must discard it using * {@link ICompilationUnit#discardWorkingCopy()}. * </p><p> * Note that when such working copy is committed, only its buffer is saved (see * {@link IBuffer#save(IProgressMonitor, boolean)}) but no resource is created. * </p><p> * This method is not intended to be overriden by clients. * </p> * * @param name the name of the working copy (e.g. "X.java") * @param classpath the classpath used to resolve names in this working copy * @param problemRequestor a requestor which will get notified of problems detected during * reconciling as they are discovered. The requestor can be set to <code>null</code> indicating * that the client is not interested in problems. * @param monitor a progress monitor used to report progress while opening the working copy * or <code>null</code> if no progress should be reported * @throws JavaModelException if the contents of this working copy can * not be determined. * @return a new working copy * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor) * @since 3.2 * * @deprecated Use {@link #newWorkingCopy(String, IClasspathEntry[], IProgressMonitor)} instead. * Note that if this deprecated method is used, problems may be reported twice * if the given requestor is not the same as the current working copy owner one. */ public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException { ExternalJavaProject project = new ExternalJavaProject(classpath); IPackageFragment parent = ((PackageFragmentRoot) project.getPackageFragmentRoot(project.getProject())).getPackageFragment(CharOperation.NO_STRINGS); CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this); result.becomeWorkingCopy(problemRequestor, monitor); return result; }
Example #14
Source File: WorkingCopyOwner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Returns a new working copy with the given name using this working copy owner to * create its buffer. * <p> * This working copy always belongs to the default package in a package * fragment root that corresponds to its Java project, and this Java project never exists. * However this Java project has the given classpath that is used when resolving names * in this working copy. * </p><p> * If a DOM AST is created using this working copy, then given classpath will be used * if bindings need to be resolved. Problems will be reported to the problem requestor * of the current working copy owner problem if it is not <code>null</code>. * <p></p> * Options used to create the DOM AST are got from {@link JavaCore#getOptions()} * as it is not possible to set the options on a non-existing Java project. * </p><p> * When the working copy instance is created, an {@link IJavaElementDelta#ADDED added delta} is * reported on this working copy. * </p><p> * Once done with the working copy, users of this method must discard it using * {@link ICompilationUnit#discardWorkingCopy()}. * </p><p> * Note that when such working copy is committed, only its buffer is saved (see * {@link IBuffer#save(IProgressMonitor, boolean)}) but no resource is created. * </p><p> * This method is not intended to be overriden by clients. * </p> * * @param name the name of the working copy (e.g. "X.java") * @param classpath the classpath used to resolve names in this working copy * @param monitor a progress monitor used to report progress while opening the working copy * or <code>null</code> if no progress should be reported * @throws JavaModelException if the contents of this working copy can * not be determined. * @return a new working copy * @see ICompilationUnit#becomeWorkingCopy(IProgressMonitor) * * @since 3.3 */ public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProgressMonitor monitor) throws JavaModelException { ExternalJavaProject project = new ExternalJavaProject(classpath); IPackageFragment parent = ((PackageFragmentRoot) project.getPackageFragmentRoot(project.getProject())).getPackageFragment(CharOperation.NO_STRINGS); CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this); result.becomeWorkingCopy(getProblemRequestor(result), monitor); return result; }