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


Java ImplementInterfaceProposal类代码示例

本文整理汇总了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));
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:78,代码来源:TypeMismatchSubProcessor.java

示例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));
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:59,代码来源:TypeMismatchSubProcessor.java


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