本文整理汇总了Java中org.eclipse.jdt.internal.ui.text.correction.proposals.ImplementInterfaceProposal类的典型用法代码示例。如果您正苦于以下问题:Java ImplementInterfaceProposal类的具体用法?Java ImplementInterfaceProposal怎么用?Java ImplementInterfaceProposal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImplementInterfaceProposal类属于org.eclipse.jdt.internal.ui.text.correction.proposals包,在下文中一共展示了ImplementInterfaceProposal类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addChangeSenderTypeProposals
import org.eclipse.jdt.internal.ui.text.correction.proposals.ImplementInterfaceProposal; //导入依赖的package包/类
public static void addChangeSenderTypeProposals(
IInvocationContext context,
Expression nodeToCast,
ITypeBinding castTypeBinding,
boolean isAssignedNode,
int relevance,
Collection<ICommandAccess> proposals)
throws JavaModelException {
IBinding callerBinding = Bindings.resolveExpressionBinding(nodeToCast, false);
ICompilationUnit cu = context.getCompilationUnit();
CompilationUnit astRoot = context.getASTRoot();
ICompilationUnit targetCu = null;
ITypeBinding declaringType = null;
IBinding callerBindingDecl = callerBinding;
if (callerBinding instanceof IVariableBinding) {
IVariableBinding variableBinding = (IVariableBinding) callerBinding;
if (variableBinding.isEnumConstant()) {
return;
}
if (!variableBinding.isField()) {
targetCu = cu;
} else {
callerBindingDecl = variableBinding.getVariableDeclaration();
ITypeBinding declaringClass = variableBinding.getDeclaringClass();
if (declaringClass == null) {
return; // array length
}
declaringType = declaringClass.getTypeDeclaration();
}
} else if (callerBinding instanceof IMethodBinding) {
IMethodBinding methodBinding = (IMethodBinding) callerBinding;
if (!methodBinding.isConstructor()) {
declaringType = methodBinding.getDeclaringClass().getTypeDeclaration();
callerBindingDecl = methodBinding.getMethodDeclaration();
}
} else if (callerBinding instanceof ITypeBinding
&& nodeToCast.getLocationInParent() == SingleMemberAnnotation.TYPE_NAME_PROPERTY) {
declaringType = (ITypeBinding) callerBinding;
callerBindingDecl =
Bindings.findMethodInType(declaringType, "value", (String[]) null); // $NON-NLS-1$
if (callerBindingDecl == null) {
return;
}
}
if (declaringType != null && declaringType.isFromSource()) {
targetCu = ASTResolving.findCompilationUnitForBinding(cu, astRoot, declaringType);
}
if (targetCu != null
&& ASTResolving.isUseableTypeInContext(castTypeBinding, callerBindingDecl, false)) {
proposals.add(
new TypeChangeCorrectionProposal(
targetCu, callerBindingDecl, astRoot, castTypeBinding, isAssignedNode, relevance));
}
// add interface to resulting type
if (!isAssignedNode) {
ITypeBinding nodeType = nodeToCast.resolveTypeBinding();
if (castTypeBinding.isInterface()
&& nodeType != null
&& nodeType.isClass()
&& !nodeType.isAnonymous()
&& nodeType.isFromSource()) {
ITypeBinding typeDecl = nodeType.getTypeDeclaration();
ICompilationUnit nodeCu = ASTResolving.findCompilationUnitForBinding(cu, astRoot, typeDecl);
if (nodeCu != null
&& ASTResolving.isUseableTypeInContext(castTypeBinding, typeDecl, true)) {
proposals.add(
new ImplementInterfaceProposal(
nodeCu, typeDecl, astRoot, castTypeBinding, relevance - 1));
}
}
}
}
示例2: addChangeSenderTypeProposals
import org.eclipse.jdt.internal.ui.text.correction.proposals.ImplementInterfaceProposal; //导入依赖的package包/类
public static void addChangeSenderTypeProposals(IInvocationContext context, Expression nodeToCast, ITypeBinding castTypeBinding, boolean isAssignedNode, int relevance, Collection<ICommandAccess> proposals) throws JavaModelException {
IBinding callerBinding= Bindings.resolveExpressionBinding(nodeToCast, false);
ICompilationUnit cu= context.getCompilationUnit();
CompilationUnit astRoot= context.getASTRoot();
ICompilationUnit targetCu= null;
ITypeBinding declaringType= null;
IBinding callerBindingDecl= callerBinding;
if (callerBinding instanceof IVariableBinding) {
IVariableBinding variableBinding= (IVariableBinding) callerBinding;
if (variableBinding.isEnumConstant()) {
return;
}
if (!variableBinding.isField()) {
targetCu= cu;
} else {
callerBindingDecl= variableBinding.getVariableDeclaration();
ITypeBinding declaringClass= variableBinding.getDeclaringClass();
if (declaringClass == null) {
return; // array length
}
declaringType= declaringClass.getTypeDeclaration();
}
} else if (callerBinding instanceof IMethodBinding) {
IMethodBinding methodBinding= (IMethodBinding) callerBinding;
if (!methodBinding.isConstructor()) {
declaringType= methodBinding.getDeclaringClass().getTypeDeclaration();
callerBindingDecl= methodBinding.getMethodDeclaration();
}
} else if (callerBinding instanceof ITypeBinding && nodeToCast.getLocationInParent() == SingleMemberAnnotation.TYPE_NAME_PROPERTY) {
declaringType= (ITypeBinding) callerBinding;
callerBindingDecl= Bindings.findMethodInType(declaringType, "value", (String[]) null); //$NON-NLS-1$
if (callerBindingDecl == null) {
return;
}
}
if (declaringType != null && declaringType.isFromSource()) {
targetCu= ASTResolving.findCompilationUnitForBinding(cu, astRoot, declaringType);
}
if (targetCu != null && ASTResolving.isUseableTypeInContext(castTypeBinding, callerBindingDecl, false)) {
proposals.add(new TypeChangeCorrectionProposal(targetCu, callerBindingDecl, astRoot, castTypeBinding, isAssignedNode, relevance));
}
// add interface to resulting type
if (!isAssignedNode) {
ITypeBinding nodeType= nodeToCast.resolveTypeBinding();
if (castTypeBinding.isInterface() && nodeType != null && nodeType.isClass() && !nodeType.isAnonymous() && nodeType.isFromSource()) {
ITypeBinding typeDecl= nodeType.getTypeDeclaration();
ICompilationUnit nodeCu= ASTResolving.findCompilationUnitForBinding(cu, astRoot, typeDecl);
if (nodeCu != null && ASTResolving.isUseableTypeInContext(castTypeBinding, typeDecl, true)) {
proposals.add(new ImplementInterfaceProposal(nodeCu, typeDecl, astRoot, castTypeBinding, relevance - 1));
}
}
}
}