本文整理汇总了Java中org.eclipse.jdt.core.ITypeHierarchy类的典型用法代码示例。如果您正苦于以下问题:Java ITypeHierarchy类的具体用法?Java ITypeHierarchy怎么用?Java ITypeHierarchy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ITypeHierarchy类属于org.eclipse.jdt.core包,在下文中一共展示了ITypeHierarchy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isGraphWalkerExecutionContextClass
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
/**
* @param testInterface
* @return
* @throws JavaModelException
*/
public static boolean isGraphWalkerExecutionContextClass(ICompilationUnit unit) throws JavaModelException {
IType[] types = unit.getAllTypes();
if (types == null || types.length == 0) {
ResourceManager.logInfo(unit.getJavaProject().getProject().getName(),
"getAllTypes return null" + unit.getPath());
return false;
}
IType execContextType = unit.getJavaProject().findType(ExecutionContext.class.getName());
for (int i = 0; i < types.length; i++) {
IType type = types[i];
String typeNname = type.getFullyQualifiedName();
String compilationUnitName = JDTManager.getJavaFullyQualifiedName(unit);
if (typeNname.equals(compilationUnitName)) {
try {
ITypeHierarchy th = types[0].newTypeHierarchy(new NullProgressMonitor());
return th.contains(execContextType);
} catch (Exception e) {
ResourceManager.logException(e);
}
}
}
return false;
}
示例2: testGetPipelineOptionsTypeForTypeNotInProjectReturnsAbsent
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
@Test
public void testGetPipelineOptionsTypeForTypeNotInProjectReturnsAbsent() throws Exception {
IType rootType = mockType(PipelineOptionsNamespaces.rootType(version));
when(rootType.getMethods()).thenReturn(new IMethod[0]);
when(rootType.exists()).thenReturn(true);
when(project.findType(PipelineOptionsNamespaces.rootType(version)))
.thenReturn(rootType);
String requestedTypeName = "foo.bar.RequestedType";
when(project.findType(requestedTypeName)).thenReturn(null);
ITypeHierarchy hierarchy = mock(ITypeHierarchy.class);
when(rootType.newTypeHierarchy(Mockito.<IProgressMonitor>any())).thenReturn(hierarchy);
PipelineOptionsType type =
pipelineOptionsHierarchy.getPipelineOptionsType(requestedTypeName);
assertNull(type);
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:21,代码来源:TypeHierarchyPipelineOptionsHierarchyTest.java
示例3: JavaProjectPipelineOptionsHierarchy
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
/**
* Creates a new {@link JavaProjectPipelineOptionsHierarchy}. This can be a long-running method,
* as it fetches the type hierarchy of the provided project.
*
* @throws JavaModelException
*/
public JavaProjectPipelineOptionsHierarchy(
IJavaProject project, MajorVersion version, IProgressMonitor monitor)
throws JavaModelException {
IType rootType = project.findType(PipelineOptionsNamespaces.rootType(version));
Preconditions.checkNotNull(rootType, "project has no PipelineOptions type");
Preconditions.checkArgument(rootType.exists(), "PipelineOptions does not exist in project");
// Flatten the class hierarchy, recording all the classes present
ITypeHierarchy hierarchy = rootType.newTypeHierarchy(monitor);
this.project = project;
this.hierarchy = hierarchy;
this.majorVersion = version;
this.knownTypes = new HashMap<>();
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:22,代码来源:JavaProjectPipelineOptionsHierarchy.java
示例4: calculateValue
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
/**
* @see IJavaModel#calculateValue
*/
@Override
public void calculateValue(ICompilationUnit unit) {
int length = 0;
try {
IType[] types = unit.getAllTypes();
for (IType type : types) {
IJavaProject ancestor = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT);
ITypeHierarchy th= type.newTypeHierarchy(ancestor, null);
if (th != null) superclassesList = th.getAllSuperclasses(type);
if (superclassesList != null) length = superclassesList.length;
Double value = new BigDecimal(length, new MathContext(2, RoundingMode.UP)).doubleValue();
setDitValue(value);
}
}catch (JavaModelException javaException) {
logger.error(javaException);
}catch (NullPointerException nullPointerException){
logger.error(nullPointerException);
}
}
示例5: calculateValue
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
/**
* @see IJavaModel#calculateValue
*/
@Override
public void calculateValue(ICompilationUnit unit) {
try {
int length = 0;
IType[] types = unit.getAllTypes();
for (IType type : types) {
ITypeHierarchy th= type.newTypeHierarchy((IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT), null);
if (th != null) subtypesList = th.getAllSubtypes(type);
if (subtypesList != null) length = subtypesList.length;
Double value = new BigDecimal(length, new MathContext(2, RoundingMode.UP)).doubleValue();
setNocValue(value);
}
}catch (JavaModelException exception1) {
logger.error(exception1);
}catch (NullPointerException exception2){
logger.error(exception2);
}
}
示例6: computeInheritancePath
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
static IType[] computeInheritancePath(IType subType, IType superType) throws JavaModelException {
if (superType == null) {
return null;
}
// optimization: avoid building the type hierarchy for the identity case
if (superType.equals(subType)) {
return new IType[] { subType };
}
ITypeHierarchy hierarchy= subType.newSupertypeHierarchy(new NullProgressMonitor());
if (!hierarchy.contains(superType))
{
return null; // no path
}
List<IType> path= new LinkedList<>();
path.add(superType);
do {
// any sub type must be on a hierarchy chain from superType to subType
superType= hierarchy.getSubtypes(superType)[0];
path.add(superType);
} while (!superType.equals(subType)); // since the equality case is handled above, we can spare one check
return path.toArray(new IType[path.size()]);
}
示例7: getCachedHierarchy
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException {
IType rep = fUnionFind.find(type);
if (rep != null) {
Collection<IType> collection = fRootReps.get(rep);
for (Iterator<IType> iter = collection.iterator(); iter.hasNext();) {
IType root = iter.next();
ITypeHierarchy hierarchy = fRootHierarchies.get(root);
if (hierarchy == null) {
hierarchy = root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1));
fRootHierarchies.put(root, hierarchy);
}
if (hierarchy.contains(type)) {
return hierarchy;
}
}
}
return null;
}
示例8: findDocInHierarchy
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
private static Reader findDocInHierarchy(IMethod method, boolean useAttachedJavadoc) throws JavaModelException {
/*
* Catch ExternalJavaProject in which case
* no hierarchy can be built.
*/
if (!method.getJavaProject().exists()) {
return null;
}
IType type= method.getDeclaringType();
ITypeHierarchy hierarchy= type.newSupertypeHierarchy(null);
MethodOverrideTester tester= new MethodOverrideTester(type, hierarchy);
IType[] superTypes= hierarchy.getAllSupertypes(type);
for (IType curr : superTypes) {
IMethod overridden= tester.findOverriddenMethodInType(curr, method);
if (overridden != null) {
Reader reader = getHTMLContentReader(overridden, false, useAttachedJavadoc);
if (reader != null) {
return reader;
}
}
}
return null;
}
示例9: loadNewTree
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
/**
*
* @param qName
* @param doClasses
* @return the new typeNode for this type, fully completed
*/
private void loadNewTree(String qName) {
try {
IType baseType = project.findType(qName);
if (baseType != null) {
ITypeHierarchy hierarchy = baseType.newTypeHierarchy(project, null);
addInHierarchy(baseType, hierarchy);
//XXX. DO NOT call GC directly!
//Yeah...that just wasted a bunch of resources. Clean up now...
// Runtime r = Runtime.getRuntime();
// r.gc();
}
} catch (JavaModelException e) {
//can't really do anything...
e.printStackTrace();
}
}
示例10: addInHierarchy
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
private void addInHierarchy(IType type, ITypeHierarchy hierarchy) throws JavaModelException {
String qName = type.getFullyQualifiedName('.');
TypeNode node = getOrCreateType(qName);
if (node.isCompleteDown())
return;
//Recurse on children
for (IType sub : hierarchy.getSubtypes(type)) {
String subName = sub.getFullyQualifiedName('.');
TypeNode subNode = getOrCreateType(subName);
node.addSubtype(subNode);
subNode.addSupertype(node);
addInHierarchy(sub, hierarchy);
}
//we now have everything below this node in the hierarchy.
node.completedDown();
}
示例11: superClassImplementsDestinationInterface
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
private static boolean superClassImplementsDestinationInterface(IType type, IType destinationInterface,
Optional<IProgressMonitor> monitor) throws JavaModelException {
monitor.ifPresent(m -> m.beginTask("Checking superclass ...", IProgressMonitor.UNKNOWN));
try {
if (type.getSuperclassName() != null) { // there's a superclass.
ITypeHierarchy superTypeHierarchy = MigrateSkeletalImplementationToInterfaceRefactoringProcessor
.getSuperTypeHierarchy(type,
monitor.map(m -> new SubProgressMonitor(m, IProgressMonitor.UNKNOWN)));
IType superclass = superTypeHierarchy.getSuperclass(type);
return Arrays.stream(superTypeHierarchy.getAllSuperInterfaces(superclass))
.anyMatch(i -> i.equals(destinationInterface));
}
} finally {
monitor.ifPresent(IProgressMonitor::done);
}
return true; // vacuously true since there's no superclass.
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:19,代码来源:SkeletalImplementatonClassRemovalUtils.java
示例12: getSuperTypeHierarchy
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
public static ITypeHierarchy getSuperTypeHierarchy(IType type, final Optional<IProgressMonitor> monitor)
throws JavaModelException {
try {
monitor.ifPresent(m -> m.subTask("Retrieving declaring super type hierarchy..."));
if (getTypeToSuperTypeHierarchyMap().containsKey(type))
return getTypeToSuperTypeHierarchyMap().get(type);
else {
ITypeHierarchy newSupertypeHierarchy = type
.newSupertypeHierarchy(monitor.orElseGet(NullProgressMonitor::new));
getTypeToSuperTypeHierarchyMap().put(type, newSupertypeHierarchy);
return newSupertypeHierarchy;
}
} finally {
monitor.ifPresent(IProgressMonitor::done);
}
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:18,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java
示例13: checkAccessedTypes
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
private RefactoringStatus checkAccessedTypes(IMethod sourceMethod, final Optional<IProgressMonitor> monitor,
final ITypeHierarchy hierarchy) throws JavaModelException {
final RefactoringStatus result = new RefactoringStatus();
final IType[] accessedTypes = getTypesReferencedInMovedMembers(sourceMethod, monitor);
final IType destination = getDestinationInterface(sourceMethod).get();
final List<IMember> pulledUpList = Arrays.asList(sourceMethod);
for (IType type : accessedTypes) {
if (!type.exists())
continue;
if (!canBeAccessedFrom(sourceMethod, type, destination, hierarchy) && !pulledUpList.contains(type)) {
final String message = org.eclipse.jdt.internal.corext.util.Messages.format(
PreconditionFailure.TypeNotAccessible.getMessage(),
new String[] { JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED),
JavaElementLabels.getTextLabel(destination, JavaElementLabels.ALL_FULLY_QUALIFIED) });
result.addEntry(RefactoringStatus.ERROR, message, JavaStatusContext.create(type),
MigrateSkeletalImplementationToInterfaceRefactoringDescriptor.REFACTORING_ID,
PreconditionFailure.TypeNotAccessible.ordinal(), sourceMethod);
this.getUnmigratableMethods().add(sourceMethod);
}
}
monitor.ifPresent(IProgressMonitor::done);
return result;
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:25,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java
示例14: checkDeclaringTypeHierarchy
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
private RefactoringStatus checkDeclaringTypeHierarchy(IMethod sourceMethod, Optional<IProgressMonitor> monitor)
throws JavaModelException {
try {
RefactoringStatus status = new RefactoringStatus();
monitor.ifPresent(m -> m.subTask("Checking declaring type hierarchy..."));
final ITypeHierarchy declaringTypeHierarchy = this.getDeclaringTypeHierarchy(sourceMethod, monitor);
status.merge(checkValidClassesInDeclaringTypeHierarchy(sourceMethod, declaringTypeHierarchy));
status.merge(checkValidInterfacesInDeclaringTypeHierarchy(sourceMethod, monitor));
return status;
} finally {
monitor.ifPresent(IProgressMonitor::done);
}
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:17,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java
示例15: checkValidClassesInDeclaringTypeHierarchy
import org.eclipse.jdt.core.ITypeHierarchy; //导入依赖的package包/类
private RefactoringStatus checkValidClassesInDeclaringTypeHierarchy(IMethod sourceMethod,
final ITypeHierarchy declaringTypeHierarchy) throws JavaModelException {
RefactoringStatus status = new RefactoringStatus();
IType[] allDeclaringTypeSuperclasses = declaringTypeHierarchy
.getAllSuperclasses(sourceMethod.getDeclaringType());
// is the source method overriding anything in the declaring type
// hierarchy? If so, don't allow the refactoring to proceed #107.
if (Stream.of(allDeclaringTypeSuperclasses).parallel().anyMatch(c -> {
IMethod[] methods = c.findMethods(sourceMethod);
return methods != null && methods.length > 0;
}))
addErrorAndMark(status, PreconditionFailure.SourceMethodOverridesMethod, sourceMethod);
return status;
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:18,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java