本文整理汇总了Java中org.eclipse.jdt.internal.core.PackageFragment类的典型用法代码示例。如果您正苦于以下问题:Java PackageFragment类的具体用法?Java PackageFragment怎么用?Java PackageFragment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PackageFragment类属于org.eclipse.jdt.internal.core包,在下文中一共展示了PackageFragment类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getPath
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
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);
}
}
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:JavaSearchScope.java
示例2: filterEnum
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:MatchLocator.java
示例3: getPath
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
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);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:JavaSearchScope.java
示例4: getJavaElement
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:TypeBinding.java
示例5: select
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IJavaModel) {
return true;
} else if (element instanceof JarPackageFragmentRoot) {
return false;
} else if (element instanceof IJavaProject) {
return true;
} else if (element instanceof PackageFragmentRoot) {
return true;
} else if (element instanceof PackageFragment) {
PackageFragment packageFragment = (PackageFragment) element;
if (packageFragment.isDefaultPackage()) {
return false;
}
return true;
} else if (element instanceof ICompilationUnit) {
return true;
}
return false;
}
开发者ID:ko2ic,项目名称:comment-tag-gen-plugin,代码行数:22,代码来源:SourceViewerFilter.java
示例6: getJavaElement
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:12,代码来源:RecoveredTypeBinding.java
示例7: proposePackage
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
private void proposePackage(final ContentAssistRequest contentAssistRequest,
IJavaProject project, String matchString, final int start, final int length)
throws CoreException
{
final List<ICompletionProposal> results = new ArrayList<ICompletionProposal>();
final Set<String> foundPkgs = new HashSet<String>();
int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
// Include application libraries only when package is specified (for better performance).
boolean pkgSpecified = matchString != null && matchString.indexOf('.') > 0;
if (pkgSpecified)
includeMask |= IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES;
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[]{
project
}, includeMask);
SearchRequestor requestor = new SearchRequestor()
{
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException
{
PackageFragment element = (PackageFragment)match.getElement();
String pkg = element.getElementName();
if (pkg != null && pkg.length() > 0 && !foundPkgs.contains(pkg))
{
foundPkgs.add(pkg);
results.add(new CompletionProposal(pkg, start, length, pkg.length(),
Activator.getIcon(), pkg, null, null));
}
}
};
searchPackage(matchString, scope, requestor);
addProposals(contentAssistRequest, results);
}
开发者ID:mybatis,项目名称:mybatipse,代码行数:33,代码来源:XmlCompletionProposalComputer.java
示例8: selectionChanged
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
/**
* @see IActionDelegate#selectionChanged(IAction, ISelection)
* @param action
* action
* @param selection
* selection
*/
public void selectionChanged(IAction action, ISelection selection)
{
try {
IAdaptable adaptable = null;
this.selected = "unknown";
if (selection instanceof IStructuredSelection) {
adaptable = (IAdaptable) ((IStructuredSelection) selection).getFirstElement();
if (adaptable == null) {
return;
}
this.selectedClass = adaptable.getClass();
if (adaptable instanceof IResource) {
this.selected = (IResource) adaptable;
} else if (adaptable instanceof PackageFragment
&& ((PackageFragment) adaptable).getPackageFragmentRoot() instanceof JarPackageFragmentRoot) {
this.selected = getJarFile(((PackageFragment) adaptable)
.getPackageFragmentRoot());
} else if (adaptable instanceof JarPackageFragmentRoot) {
this.selected = getJarFile(adaptable);
} else {
this.selected = (IResource) adaptable.getAdapter(IResource.class);
}
}
} catch (Throwable e) {
EasyExploreActivator.log(e);
}
}
开发者ID:winture,项目名称:wt-studio,代码行数:35,代码来源:EasyExploreAction.java
示例9: getPackageName
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
private String getPackageName(PackageSelectionDialog dialog) {
PackageFragment packageFragment = (PackageFragment) dialog
.getFirstResult();
return packageFragment.getElementName();
}
开发者ID:bsteker,项目名称:bdf2,代码行数:6,代码来源:SelectClassPage.java
示例10: convert
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
private CompilationUnitDeclaration convert(
ISourceType[] sourceTypes, CompilationResult compilationResult) throws JavaModelException {
this.unit = new CompilationUnitDeclaration(this.problemReporter, compilationResult, 0);
// not filled at this point
if (sourceTypes.length == 0) return this.unit;
SourceTypeElementInfo topLevelTypeInfo = (SourceTypeElementInfo) sourceTypes[0];
org.eclipse.jdt.core.ICompilationUnit cuHandle =
topLevelTypeInfo.getHandle().getCompilationUnit();
this.cu = (ICompilationUnit) cuHandle;
final CompilationUnitElementInfo compilationUnitElementInfo =
(CompilationUnitElementInfo) ((JavaElement) this.cu).getElementInfo();
if (this.has1_5Compliance
&& (compilationUnitElementInfo.annotationNumber
>= CompilationUnitElementInfo.ANNOTATION_THRESHOLD_FOR_DIET_PARSE
|| (compilationUnitElementInfo.hasFunctionalTypes && (this.flags & LOCAL_TYPE) != 0))) {
// If more than 10 annotations, diet parse as this is faster, but not if
// the client wants local and anonymous types to be converted
// (https://bugs.eclipse.org/bugs/show_bug.cgi?id=254738)
// Also see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=405843
if ((this.flags & LOCAL_TYPE) == 0) {
return new Parser(this.problemReporter, true).dietParse(this.cu, compilationResult);
} else {
return new Parser(this.problemReporter, true).parse(this.cu, compilationResult);
}
}
/* only positions available */
int start = topLevelTypeInfo.getNameSourceStart();
int end = topLevelTypeInfo.getNameSourceEnd();
/* convert package and imports */
String[] packageName = ((PackageFragment) cuHandle.getParent()).names;
if (packageName.length > 0)
// if its null then it is defined in the default package
this.unit.currentPackage =
createImportReference(packageName, start, end, false, ClassFileConstants.AccDefault);
IImportDeclaration[] importDeclarations =
topLevelTypeInfo.getHandle().getCompilationUnit().getImports();
int importCount = importDeclarations.length;
this.unit.imports = new ImportReference[importCount];
for (int i = 0; i < importCount; i++) {
ImportDeclaration importDeclaration = (ImportDeclaration) importDeclarations[i];
ISourceImport sourceImport = (ISourceImport) importDeclaration.getElementInfo();
String nameWithoutStar = importDeclaration.getNameWithoutStar();
this.unit.imports[i] =
createImportReference(
Util.splitOn('.', nameWithoutStar, 0, nameWithoutStar.length()),
sourceImport.getDeclarationSourceStart(),
sourceImport.getDeclarationSourceEnd(),
importDeclaration.isOnDemand(),
sourceImport.getModifiers());
}
/* convert type(s) */
try {
int typeCount = sourceTypes.length;
final TypeDeclaration[] types = new TypeDeclaration[typeCount];
/*
* We used a temporary types collection to prevent this.unit.types from being null during a call to
* convert(...) when the source is syntactically incorrect and the parser is flushing the unit's types.
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97466
*/
for (int i = 0; i < typeCount; i++) {
SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) sourceTypes[i];
types[i] = convert((SourceType) typeInfo.getHandle(), compilationResult);
}
this.unit.types = types;
return this.unit;
} catch (AnonymousMemberFound e) {
return new Parser(this.problemReporter, true).parse(this.cu, compilationResult);
}
}
开发者ID:eclipse,项目名称:che,代码行数:74,代码来源:SourceTypeConverter.java
示例11: getDiagramFile
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
private IFile getDiagramFile() {
final String diagramName = getDiagramName();
if (StringUtils.isBlank(diagramName)) {
return null;
}
IProject project = null;
IFolder diagramFolder = null;
// Added check on IJavaProject
// Kept IProject check for future facet implementation
Object element = getSelection().getFirstElement();
if (element instanceof IProject) {
project = (IProject) element;
} else if (element instanceof IJavaProject) {
IJavaProject javaProject = (IJavaProject) element;
project = javaProject.getProject();
} else if (element instanceof AbstractInstancesOfTypeContainerNode) {
AbstractInstancesOfTypeContainerNode aiocn = (AbstractInstancesOfTypeContainerNode) element;
project = aiocn.getProject();
} else if (element instanceof IFolder) {
diagramFolder = (IFolder) element;
project = diagramFolder.getProject();
} else if (element instanceof PackageFragment) { // access is
// discouraged, but
// inevitable when
// the selection is
// the diagrams
// package itself
PackageFragment fragment = (PackageFragment) element;
project = fragment.getJavaProject().getProject();
}
if (project == null || !project.isAccessible()) {
String error = "No open project was found for the current selection. Select a project and restart the wizard.";
IStatus status = new Status(IStatus.ERROR, ActivitiPlugin.getID(), error);
ErrorDialog.openError(getShell(), "No Project Found", null, status);
return null;
}
if (diagramFolder == null) {
diagramFolder = project.getFolder(ActivitiBPMNDiagramConstants.DIAGRAM_FOLDER);
}
return diagramFolder.getFile(diagramName);
}
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:49,代码来源:CreateDefaultActivitiDiagramWizard.java
示例12: getResource
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
static public Resource getResource(Object myObj) {
Object object = null;
// handle IEditorPart
if (myObj instanceof IEditorPart) {
IEditorPart editorPart = (IEditorPart)myObj;
IEditorInput input = editorPart.getEditorInput();
if (input instanceof IFileEditorInput) {
object = ((IFileEditorInput)input).getFile();
} else {
Object adapter = input.getAdapter(IFile.class);
if(adapter instanceof IFile){
object = (IFile) adapter;
} else {
adapter = editorPart.getAdapter(IFile.class);
if(adapter instanceof IFile){
object = (IFile) adapter;
} else {
object = input;
}
}
}
} else {
object = myObj;
}
// the most input types first
if (object instanceof Resource) {
return new Resource((Resource)object);
}
if (object instanceof IFile) {
return new Resource(((IFile) object));
}
if (object instanceof File) {
return new Resource((File) object);
}
// still adaptable
if (object instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) object;
// IFile
IFile iFile = (IFile) adaptable.getAdapter(IFile.class);
if (iFile != null) {
return new Resource(iFile);
}
// IResource
IResource ires = (IResource) adaptable.getAdapter(IResource.class);
if (ires != null) {
IPath path = ires.getLocation();
if (path != null) {
return new Resource(ires);
}
}
// FileStoreEditorInput
if (adaptable instanceof FileStoreEditorInput) {
URI fileuri = ((FileStoreEditorInput) adaptable).getURI();
return new Resource(new File(fileuri.getPath()));
}
// optional org.eclipse.jdt.core
Bundle bundle = Platform.getBundle("org.eclipse.jdt.core");
if (bundle != null) {
if ( (adaptable instanceof PackageFragment) &&
( ((PackageFragment) adaptable).getPackageFragmentRoot() instanceof JarPackageFragmentRoot) ) {
return new Resource(getJarFile(((PackageFragment) adaptable)
.getPackageFragmentRoot()));
} else if (adaptable instanceof JarPackageFragmentRoot) {
return new Resource(getJarFile(adaptable));
}
}
// File
File file = (File) adaptable.getAdapter(File.class);
if (file != null) {
return new Resource(file);
}
}
return null;
}
开发者ID:anb0s,项目名称:EasyShell,代码行数:78,代码来源:ResourceUtils.java
示例13: AssistCompilationUnit
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
public AssistCompilationUnit(ICompilationUnit compilationUnit, WorkingCopyOwner owner, Map bindingCache, Map infoCache) {
super((PackageFragment)compilationUnit.getParent(), compilationUnit.getElementName(), owner);
this.bindingCache = bindingCache;
this.infoCache = infoCache;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:6,代码来源:AssistCompilationUnit.java
示例14: newWorkingCopy
import org.eclipse.jdt.internal.core.PackageFragment; //导入依赖的package包/类
/**
* 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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:52,代码来源:WorkingCopyOwner.java
注:本文中的org.eclipse.jdt.internal.core.PackageFragment类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论