当前位置: 首页>>代码示例>>Java>>正文


Java ITypeHierarchy.getSubclasses方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.ITypeHierarchy.getSubclasses方法的典型用法代码示例。如果您正苦于以下问题:Java ITypeHierarchy.getSubclasses方法的具体用法?Java ITypeHierarchy.getSubclasses怎么用?Java ITypeHierarchy.getSubclasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.ITypeHierarchy的用法示例。


在下文中一共展示了ITypeHierarchy.getSubclasses方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAffectedSubTypes

import org.eclipse.jdt.core.ITypeHierarchy; //导入方法依赖的package包/类
private static Set<IType> getAffectedSubTypes(final ITypeHierarchy hierarchy, final IType type) throws JavaModelException {
	 IType[] types= null;
	 final boolean isInterface= type.isInterface();
	if (isInterface) {
		 final Collection<IType> remove= new ArrayList<IType>();
		 final List<IType> list= new ArrayList<IType>(Arrays.asList(hierarchy.getSubtypes(type)));
		 for (final Iterator<IType> iterator= list.iterator(); iterator.hasNext();) {
            final IType element= iterator.next();
            if (element.isInterface())
            	remove.add(element);
           }
		 list.removeAll(remove);
		 types= list.toArray(new IType[list.size()]);
	 } else
		 types= hierarchy.getSubclasses(type);
	final Set<IType> result= new HashSet<IType>();
	for (int index= 0; index < types.length; index++) {
		if (!isInterface && JdtFlags.isAbstract(types[index]))
			result.addAll(getAffectedSubTypes(hierarchy, types[index]));
		else
			result.add(types[index]);
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:PullUpRefactoringProcessor.java

示例2: checkValidInterfacesInDeclaringTypeHierarchy

import org.eclipse.jdt.core.ITypeHierarchy; //导入方法依赖的package包/类
private RefactoringStatus checkValidInterfacesInDeclaringTypeHierarchy(IMethod sourceMethod,
		Optional<IProgressMonitor> monitor) throws JavaModelException {
	RefactoringStatus status = new RefactoringStatus();

	monitor.ifPresent(m -> m.beginTask("Checking valid interfaces in declaring type hierarchy ...",
			IProgressMonitor.UNKNOWN));
	try {
		ITypeHierarchy hierarchy = this.getDeclaringTypeHierarchy(sourceMethod, monitor);
		IType[] declaringTypeSuperInterfaces = hierarchy.getAllSuperInterfaces(sourceMethod.getDeclaringType());

		// the number of methods sourceMethod is implementing.
		long numberOfImplementedMethods = Arrays.stream(declaringTypeSuperInterfaces).parallel().distinct().flatMap(
				i -> Arrays.stream(Optional.ofNullable(i.findMethods(sourceMethod)).orElse(new IMethod[] {})))
				.count();

		if (numberOfImplementedMethods > 1)
			addErrorAndMark(status, PreconditionFailure.SourceMethodImplementsMultipleMethods, sourceMethod);

		// for each subclass of the declaring type.
		for (IType subclass : hierarchy.getSubclasses(sourceMethod.getDeclaringType()))
			status.merge(checkClassForMissingSourceMethodImplementation(sourceMethod, subclass, hierarchy,
					monitor.map(m -> new SubProgressMonitor(m, IProgressMonitor.UNKNOWN))));
	} finally {
		monitor.ifPresent(IProgressMonitor::done);
	}
	return status;
}
 
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:28,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java

示例3: checkClassForMissingSourceMethodImplementation

import org.eclipse.jdt.core.ITypeHierarchy; //导入方法依赖的package包/类
/**
 * Checks the given class and its subclasses for any required
 * implementations of the source method. The required implementations are
 * deemed by the interfaces the given class implements.
 *
 * @param sourceMethod
 *            The source method being migrated to an interface.
 * @param clazz
 *            The class to check for any missing needed implementations of
 *            the source method.
 * @param declaringTypeHierarchy
 *            Hierarchy of the source method's declaring type.
 * @return {@link RefactoringStatus} indicating the result of the
 *         precondition check.
 * @throws JavaModelException
 *             When asserting that the given {@link IType} is indeed a
 *             class.
 */
private RefactoringStatus checkClassForMissingSourceMethodImplementation(IMethod sourceMethod, IType clazz,
		ITypeHierarchy declaringTypeHierarchy, Optional<IProgressMonitor> monitor) throws JavaModelException {
	RefactoringStatus status = new RefactoringStatus();

	// does the class have an implementation or declaration of the source
	// method?
	IMethod[] classMethodMatchingSourceMethod = clazz.findMethods(sourceMethod);
	if (classMethodMatchingSourceMethod != null && classMethodMatchingSourceMethod.length > 0)
		// in this case, the class has an implementation. No need to check
		// any interfaces or subclasses because any interfaces would be
		// satisfied and any unsatisfied interfaces will inherit the method
		// from this class.
		return status;
	// otherwise, no matching methods were found in the given class.
	else {
		// retrieve super interfaces of the class.
		IType[] superInterfaces = getSuperInterfaces(clazz, declaringTypeHierarchy,
				monitor.map(m -> new SubProgressMonitor(m, IProgressMonitor.UNKNOWN)));

		try {
			monitor.ifPresent(m -> m.beginTask("Checking class for missing source method implementation ...",
					superInterfaces.length));

			// retrieve the destination interface.
			IType destinationInterface = getTargetMethod(sourceMethod,
					monitor.map(m -> new SubProgressMonitor(m, IProgressMonitor.UNKNOWN))).getDeclaringType();

			// for each super interface of the given class.
			for (IType superInterface : superInterfaces) {
				// if it is not equal to the destination interface.
				if (!superInterface.equals(destinationInterface)) {
					IMethod[] interfaceMethodMatchingSourceMethod = superInterface.findMethods(sourceMethod);
					if (interfaceMethodMatchingSourceMethod != null
							&& interfaceMethodMatchingSourceMethod.length > 0)
						// there are multiple method definitions stemming
						// from interfaces. this class doesn't have an
						// implementation of the source method nor does it
						// inherit it.
						addErrorAndMark(status,
								PreconditionFailure.SourceMethodProvidesImplementationsForMultipleMethods,
								sourceMethod, superInterface);
				}
				monitor.ifPresent(m -> m.worked(1));
			}

			// check subclasses of the given class.
			for (IType subclass : declaringTypeHierarchy.getSubclasses(clazz))
				status.merge(checkClassForMissingSourceMethodImplementation(sourceMethod, subclass,
						declaringTypeHierarchy,
						monitor.map(m -> new SubProgressMonitor(m, IProgressMonitor.UNKNOWN))));

			return status;
		} finally {
			monitor.ifPresent(IProgressMonitor::done);
		}
	}
}
 
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:76,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java


注:本文中的org.eclipse.jdt.core.ITypeHierarchy.getSubclasses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。