本文整理汇总了Java中org.eclipse.jdt.core.IType.getAncestor方法的典型用法代码示例。如果您正苦于以下问题:Java IType.getAncestor方法的具体用法?Java IType.getAncestor怎么用?Java IType.getAncestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IType
的用法示例。
在下文中一共展示了IType.getAncestor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findImplementations
import org.eclipse.jdt.core.IType; //导入方法依赖的package包/类
private List<Location> findImplementations(IType type, IProgressMonitor monitor) throws JavaModelException {
IType[] results = type.newTypeHierarchy(monitor).getAllSubtypes(type);
final List<Location> result = new ArrayList<>();
for (IType t : results) {
ICompilationUnit compilationUnit = (ICompilationUnit) t.getAncestor(IJavaElement.COMPILATION_UNIT);
if (compilationUnit == null) {
continue;
}
Location location = null; // JDTUtils.toLocation(t);
result.add(location);
}
return result;
}
示例2: getFixImportProposals
import org.eclipse.jdt.core.IType; //导入方法依赖的package包/类
@Override
public ClasspathFixProposal[] getFixImportProposals(final IJavaProject project, String name) throws CoreException
{
IProject requestedProject = project.getProject();
if( !requestedProject.hasNature(JPFProjectNature.NATURE_ID) )
{
return null;
}
ArrayList<ClasspathFixProposal> props = new ArrayList<ClasspathFixProposal>();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
int idx = name.lastIndexOf('.');
char[] packageName = idx != -1 ? name.substring(0, idx).toCharArray() : null;
char[] typeName = name.substring(idx + 1).toCharArray();
if( typeName.length == 1 && typeName[0] == '*' )
{
typeName = null;
}
ArrayList<TypeNameMatch> res = new ArrayList<TypeNameMatch>();
TypeNameMatchCollector requestor = new TypeNameMatchCollector(res);
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
int matchMode = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
new SearchEngine().searchAllTypeNames(packageName, matchMode, typeName, matchMode, IJavaSearchConstants.TYPE,
scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
if( res.isEmpty() )
{
return null;
}
JPFPluginModelManager service = JPFPluginModelManager.instance();
for( TypeNameMatch curr : res )
{
IType type = curr.getType();
if( type != null )
{
IPackageFragmentRoot root = (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
IPluginModel model = null;
if( root.isArchive() )
{
model = service.findModel((IFile) root.getResource());
}
else if( !root.isExternal() )
{
model = service.findModel(root.getResource().getProject());
}
if( model != null )
{
System.err.println("Found in " + model.getParsedManifest().getId());
props.add(new JPFClasspathFixProposal(project, JPFProject.getManifest(requestedProject), model));
}
}
}
return props.toArray(new ClasspathFixProposal[props.size()]);
}