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


Java JdtFlags.isDefaultMethod方法代码示例

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


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

示例1: getCandidateDestinationInterfaces

import org.eclipse.jdt.internal.corext.util.JdtFlags; //导入方法依赖的package包/类
/**
 * Returns the possible target interfaces for the migration. NOTE: One
 * difference here between this refactoring and pull up is that we can have
 * a much more complex type hierarchy due to multiple interface inheritance
 * in Java.
 * <p>
 * TODO: It should be possible to pull up a method into an interface (i.e.,
 * "Pull Up Method To Interface") that is not implemented explicitly. For
 * example, there may be a skeletal implementation class that implements all
 * the target interface's methods without explicitly declaring so.
 * Effectively skeletal?
 *
 * @param monitor
 *            A progress monitor.
 * @return The possible target interfaces for the migration.
 * @throws JavaModelException
 *             upon Java model problems.
 */
public static IType[] getCandidateDestinationInterfaces(IMethod sourcMethod,
		final Optional<IProgressMonitor> monitor) throws JavaModelException {
	try {
		monitor.ifPresent(m -> m.beginTask("Retrieving candidate types...", IProgressMonitor.UNKNOWN));

		IType[] superInterfaces = getSuperInterfaces(sourcMethod.getDeclaringType(),
				monitor.map(m -> new SubProgressMonitor(m, 1)));

		Stream<IType> candidateStream = Stream.of(superInterfaces).parallel().filter(Objects::nonNull)
				.filter(IJavaElement::exists).filter(t -> !t.isReadOnly()).filter(t -> !t.isBinary());

		Set<IType> ret = new HashSet<>();

		for (Iterator<IType> iterator = candidateStream.iterator(); iterator.hasNext();) {
			IType superInterface = iterator.next();
			IMethod[] interfaceMethods = superInterface.findMethods(sourcMethod);
			if (interfaceMethods != null)
				// the matching methods cannot already be default.
				for (IMethod method : interfaceMethods)
					if (!JdtFlags.isDefaultMethod(method))
						ret.add(superInterface);
		}

		return ret.toArray(new IType[ret.size()]);
	} finally {
		monitor.ifPresent(IProgressMonitor::done);
	}
}
 
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:47,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java

示例2: isMoveMethodAvailable

import org.eclipse.jdt.internal.corext.util.JdtFlags; //导入方法依赖的package包/类
public static boolean isMoveMethodAvailable(final IMethod method) throws JavaModelException {
  return method.exists()
      && !method.isConstructor()
      && !method.isBinary()
      && !method.isReadOnly()
      && !JdtFlags.isStatic(method)
      && (JdtFlags.isDefaultMethod(method) || !method.getDeclaringType().isInterface());
}
 
开发者ID:eclipse,项目名称:che,代码行数:9,代码来源:RefactoringAvailabilityTester.java

示例3: getExtractedMethods

import org.eclipse.jdt.internal.corext.util.JdtFlags; //导入方法依赖的package包/类
/**
 * Returns the extracted methods from the compilation unit except the default methods.
 *
 * @param unit the compilation unit
 * @return the extracted methods except the default method
 * @throws JavaModelException if the element does not exist
 */
protected final IMethod[] getExtractedMethods(final ICompilationUnit unit) throws JavaModelException {
	Assert.isNotNull(unit);
	final List<IJavaElement> list= new ArrayList<IJavaElement>();
	for (int index= 0; index < fMembers.length; index++) {
		if (fMembers[index] instanceof IMethod) {
			final IJavaElement element= JavaModelUtil.findInCompilationUnit(unit, fMembers[index]);
			if (element instanceof IMethod && !JdtFlags.isDefaultMethod((IMethod) element))
				list.add(element);
		}
	}
	return list.toArray(new IMethod[list.size()]);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:ExtractInterfaceProcessor.java

示例4: createMethodCopy

import org.eclipse.jdt.internal.corext.util.JdtFlags; //导入方法依赖的package包/类
/**
 * Creates the necessary changes to create the delegate method with the
 * original method body.
 *
 * @param document
 *            the buffer containing the source of the source compilation
 *            unit
 * @param declaration
 *            the method declaration to use as source
 * @param rewrite
 *            the ast rewrite to use for the copy of the method body
 * @param rewrites
 *            the compilation unit rewrites
 * @param adjustments
 *            the map of elements to visibility adjustments
 * @param status
 *            the refactoring status
 * @param monitor
 *            the progress monitor to display progress
 * @throws CoreException
 *             if an error occurs
 */
protected void createMethodCopy(IDocument document, MethodDeclaration declaration, ASTRewrite rewrite, Map<ICompilationUnit, CompilationUnitRewrite> rewrites, Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, RefactoringStatus status, IProgressMonitor monitor) throws CoreException {
	Assert.isNotNull(document);
	Assert.isNotNull(declaration);
	Assert.isNotNull(rewrite);
	Assert.isNotNull(rewrites);
	Assert.isNotNull(adjustments);
	Assert.isNotNull(status);
	Assert.isNotNull(monitor);
	final CompilationUnitRewrite rewriter= getCompilationUnitRewrite(rewrites, getTargetType().getCompilationUnit());
	try {
		rewrite.set(declaration, MethodDeclaration.NAME_PROPERTY, rewrite.getAST().newSimpleName(fMethodName), null);
		boolean same= false;
		final IMethodBinding binding= declaration.resolveBinding();
		if (binding != null) {
			final ITypeBinding declaring= binding.getDeclaringClass();
			if (declaring != null && Bindings.equals(declaring.getPackage(), fTarget.getType().getPackage()))
				same= true;
			final Modifier.ModifierKeyword keyword= same ? null : Modifier.ModifierKeyword.PUBLIC_KEYWORD;
			ModifierRewrite modifierRewrite= ModifierRewrite.create(rewrite, declaration);
			if (JdtFlags.isDefaultMethod(binding) && getTargetType().isClass()) {
				// Remove 'default' modifier and add 'public' visibility
				modifierRewrite.setVisibility(Modifier.PUBLIC, null);
				modifierRewrite.setModifiers(Modifier.NONE, Modifier.DEFAULT, null);
			} else if (!JdtFlags.isDefaultMethod(binding) && getTargetType().isInterface()) {
				// Remove visibility modifiers and add 'default'
				modifierRewrite.setModifiers(Modifier.DEFAULT, Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE, null);
			} else if (MemberVisibilityAdjustor.hasLowerVisibility(binding.getModifiers(), same ? Modifier.NONE : keyword == null ? Modifier.NONE : keyword.toFlagValue())
					&& MemberVisibilityAdjustor.needsVisibilityAdjustments(fMethod, keyword, adjustments)) {
				final MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment adjustment= new MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment(fMethod, keyword, RefactoringStatus.createStatus(RefactoringStatus.WARNING, Messages.format(RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_method_warning, new String[] { MemberVisibilityAdjustor.getLabel(fMethod), MemberVisibilityAdjustor.getLabel(keyword) }), JavaStatusContext.create(fMethod), null, RefactoringStatusEntry.NO_CODE, null));
				modifierRewrite.setVisibility(keyword == null ? Modifier.NONE : keyword.toFlagValue(), null);
				adjustment.setNeedsRewriting(false);
				adjustments.put(fMethod, adjustment);
			}
		}
		for (IExtendedModifier modifier : (List<IExtendedModifier>) declaration.modifiers()) {
			if (modifier.isAnnotation()) {
				Annotation annotation= (Annotation) modifier;
				ITypeBinding typeBinding= annotation.resolveTypeBinding();
				if (typeBinding != null && typeBinding.getQualifiedName().equals("java.lang.Override")) { //$NON-NLS-1$
					rewrite.remove(annotation, null);
				}
			}
		}
		createMethodArguments(rewrites, rewrite, declaration, adjustments, status);
		createMethodTypeParameters(rewrite, declaration, status);
		createMethodComment(rewrite, declaration);
		createMethodBody(rewriter, rewrite, declaration);
	} finally {
		if (fMethod.getCompilationUnit().equals(getTargetType().getCompilationUnit()))
			rewriter.clearImportRewrites();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:75,代码来源:MoveInstanceMethodProcessor.java

示例5: isMoveMethodAvailable

import org.eclipse.jdt.internal.corext.util.JdtFlags; //导入方法依赖的package包/类
public static boolean isMoveMethodAvailable(final IMethod method) throws JavaModelException {
	return method.exists() && !method.isConstructor() && !method.isBinary() && !method.isReadOnly()
			&& !JdtFlags.isStatic(method) && (JdtFlags.isDefaultMethod(method) || !method.getDeclaringType().isInterface());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:5,代码来源:RefactoringAvailabilityTester.java


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