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


Java Invocations类代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.corext.refactoring.code.Invocations的典型用法代码示例。如果您正苦于以下问题:Java Invocations类的具体用法?Java Invocations怎么用?Java Invocations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Invocations类属于org.eclipse.jdt.internal.corext.refactoring.code包,在下文中一共展示了Invocations类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createOccurrenceUpdate

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
private OccurrenceUpdate<? extends ASTNode> createOccurrenceUpdate(
    ASTNode node, CompilationUnitRewrite cuRewrite, RefactoringStatus result) {
  if (BUG_89686
      && node instanceof SimpleName
      && node.getParent() instanceof EnumConstantDeclaration) node = node.getParent();

  if (Invocations.isInvocationWithArguments(node))
    return new ReferenceUpdate(node, cuRewrite, result);
  else if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration)
    return new DeclarationUpdate((MethodDeclaration) node.getParent(), cuRewrite, result);
  else if (node instanceof MemberRef || node instanceof MethodRef)
    return new DocReferenceUpdate(node, cuRewrite, result);
  else if (ASTNodes.getParent(node, ImportDeclaration.class) != null)
    return new StaticImportUpdate(
        (ImportDeclaration) ASTNodes.getParent(node, ImportDeclaration.class), cuRewrite, result);
  else if (node instanceof LambdaExpression)
    return new LambdaExpressionUpdate((LambdaExpression) node, cuRewrite, result);
  else if (node.getLocationInParent() == ExpressionMethodReference.NAME_PROPERTY)
    return new ExpressionMethodRefUpdate(
        (ExpressionMethodReference) node.getParent(), cuRewrite, result);
  else return new NullOccurrenceUpdate(node, cuRewrite, result);
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:ChangeSignatureProcessor.java

示例2: createOccurrenceUpdate

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
private OccurrenceUpdate<? extends ASTNode> createOccurrenceUpdate(ASTNode node, CompilationUnitRewrite cuRewrite, RefactoringStatus result) {
	if (BUG_89686 && node instanceof SimpleName && node.getParent() instanceof EnumConstantDeclaration)
		node= node.getParent();

	if (Invocations.isInvocationWithArguments(node))
		return new ReferenceUpdate(node, cuRewrite, result);

	else if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration)
		return new DeclarationUpdate((MethodDeclaration) node.getParent(), cuRewrite, result);

	else if (node instanceof MemberRef || node instanceof MethodRef)
		return new DocReferenceUpdate(node, cuRewrite, result);

	else if (ASTNodes.getParent(node, ImportDeclaration.class) != null)
		return new StaticImportUpdate((ImportDeclaration) ASTNodes.getParent(node, ImportDeclaration.class), cuRewrite, result);

	else if (node instanceof LambdaExpression)
		return new LambdaExpressionUpdate((LambdaExpression) node, cuRewrite, result);

	else if (node.getLocationInParent() == ExpressionMethodReference.NAME_PROPERTY)
		return new ExpressionMethodRefUpdate((ExpressionMethodReference) node.getParent(), cuRewrite, result);

	else
		return new NullOccurrenceUpdate(node, cuRewrite, result);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:ChangeSignatureProcessor.java

示例3: createOccurrenceUpdate

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
private OccurrenceUpdate<? extends ASTNode> createOccurrenceUpdate(ASTNode node, CompilationUnitRewrite cuRewrite, RefactoringStatus result) {
	if (BUG_89686 && node instanceof SimpleName && node.getParent() instanceof EnumConstantDeclaration)
		node= node.getParent();

	if (Invocations.isInvocationWithArguments(node))
		return new ReferenceUpdate(node, cuRewrite, result);

	else if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration)
		return new DeclarationUpdate((MethodDeclaration) node.getParent(), cuRewrite, result);

	else if (node instanceof MemberRef || node instanceof MethodRef)
		return new DocReferenceUpdate(node, cuRewrite, result);

	else if (ASTNodes.getParent(node, ImportDeclaration.class) != null)
		return new StaticImportUpdate((ImportDeclaration) ASTNodes.getParent(node, ImportDeclaration.class), cuRewrite, result);

	else
		return new NullOccurrenceUpdate(node, cuRewrite, result);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:20,代码来源:ChangeSignatureProcessor.java

示例4: addExplicitTypeArgumentsIfNecessary

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
private static void addExplicitTypeArgumentsIfNecessary(ASTRewrite rewrite, ASTRewriteCorrectionProposal proposal, Expression invocation) {
	if (Invocations.isResolvedTypeInferredFromExpectedType(invocation)) {
		ITypeBinding[] typeArguments= Invocations.getInferredTypeArguments(invocation);
		if (typeArguments == null)
			return;
		
		ImportRewrite importRewrite= proposal.getImportRewrite();
		if (importRewrite == null) {
			importRewrite= proposal.createImportRewrite((CompilationUnit) invocation.getRoot());
		}
		ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(invocation, importRewrite);
		
		AST ast= invocation.getAST();
		ListRewrite typeArgsRewrite= Invocations.getInferredTypeArgumentsRewrite(rewrite, invocation);
		
		for (int i= 0; i < typeArguments.length; i++) {
			Type typeArgumentNode= importRewrite.addImport(typeArguments[i], ast, importRewriteContext);
			typeArgsRewrite.insertLast(typeArgumentNode, null);
		}
		
		if (invocation instanceof MethodInvocation) {
			MethodInvocation methodInvocation= (MethodInvocation) invocation;
			Expression expression= methodInvocation.getExpression();
			if (expression == null) {
				IMethodBinding methodBinding= methodInvocation.resolveMethodBinding();
				if (methodBinding != null && Modifier.isStatic(methodBinding.getModifiers())) {
					expression= ast.newName(importRewrite.addImport(methodBinding.getDeclaringClass().getTypeDeclaration(), importRewriteContext));
				} else {
					expression= ast.newThisExpression();
				}
				rewrite.set(invocation, MethodInvocation.EXPRESSION_PROPERTY, expression, null);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:AdvancedQuickAssistProcessor.java

示例5: getParamgumentsRewrite

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
/** @return {@inheritDoc} (element type: Expression) */
@Override
protected ListRewrite getParamgumentsRewrite() {
  return getASTRewrite().getListRewrite(fNode, Invocations.getArgumentsProperty(fNode));
}
 
开发者ID:eclipse,项目名称:che,代码行数:6,代码来源:ChangeSignatureProcessor.java

示例6: addDeprecatedFieldsToMethodsProposals

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
public static void addDeprecatedFieldsToMethodsProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
  if (selectedNode instanceof Name) {
    IBinding binding = ((Name) selectedNode).resolveBinding();
    if (binding instanceof IVariableBinding) {
      IVariableBinding variableBinding = (IVariableBinding) binding;
      if (variableBinding.isField()) {
        String qualifiedName =
            variableBinding.getDeclaringClass().getTypeDeclaration().getQualifiedName();
        String fieldName = variableBinding.getName();
        String[] methodName = getMethod(JavaModelUtil.concatenateName(qualifiedName, fieldName));
        if (methodName != null) {
          AST ast = selectedNode.getAST();
          ASTRewrite astRewrite = ASTRewrite.create(ast);
          ImportRewrite importRewrite =
              StubUtility.createImportRewrite(context.getASTRoot(), true);

          MethodInvocation method = ast.newMethodInvocation();
          String qfn = importRewrite.addImport(methodName[0]);
          method.setExpression(ast.newName(qfn));
          method.setName(ast.newSimpleName(methodName[1]));
          ASTNode parent = selectedNode.getParent();
          ICompilationUnit cu = context.getCompilationUnit();
          // add explicit type arguments if necessary (for 1.8 and later, we're optimistic that
          // inference just works):
          if (Invocations.isInvocationWithArguments(parent)
              && !JavaModelUtil.is18OrHigher(cu.getJavaProject())) {
            IMethodBinding methodBinding = Invocations.resolveBinding(parent);
            if (methodBinding != null) {
              ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
              int i = Invocations.getArguments(parent).indexOf(selectedNode);
              if (parameterTypes.length >= i && parameterTypes[i].isParameterizedType()) {
                ITypeBinding[] typeArguments = parameterTypes[i].getTypeArguments();
                for (int j = 0; j < typeArguments.length; j++) {
                  ITypeBinding typeArgument = typeArguments[j];
                  typeArgument = Bindings.normalizeForDeclarationUse(typeArgument, ast);
                  if (!TypeRules.isJavaLangObject(typeArgument)) {
                    // add all type arguments if at least one is found to be necessary:
                    List<Type> typeArgumentsList = method.typeArguments();
                    for (int k = 0; k < typeArguments.length; k++) {
                      typeArgument = typeArguments[k];
                      typeArgument = Bindings.normalizeForDeclarationUse(typeArgument, ast);
                      typeArgumentsList.add(importRewrite.addImport(typeArgument, ast));
                    }
                    break;
                  }
                }
              }
            }
          }

          astRewrite.replace(selectedNode, method, null);

          String label =
              Messages.format(
                  CorrectionMessages
                      .LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description,
                  BasicElementLabels.getJavaElementName(ASTNodes.asString(method)));
          Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
          ASTRewriteCorrectionProposal proposal =
              new ASTRewriteCorrectionProposal(
                  label,
                  cu,
                  astRewrite,
                  IProposalRelevance.REPLACE_FIELD_ACCESS_WITH_METHOD,
                  image);
          proposal.setImportRewrite(importRewrite);
          proposals.add(proposal);
        }
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:75,代码来源:LocalCorrectionsSubProcessor.java

示例7: addExplicitTypeArgumentsIfNecessary

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
private static void addExplicitTypeArgumentsIfNecessary(
    ASTRewrite rewrite, ASTRewriteCorrectionProposal proposal, Expression invocation) {
  if (Invocations.isResolvedTypeInferredFromExpectedType(invocation)) {
    ITypeBinding[] typeArguments = Invocations.getInferredTypeArguments(invocation);
    if (typeArguments == null) return;

    ImportRewrite importRewrite = proposal.getImportRewrite();
    if (importRewrite == null) {
      importRewrite = proposal.createImportRewrite((CompilationUnit) invocation.getRoot());
    }
    ImportRewriteContext importRewriteContext =
        new ContextSensitiveImportRewriteContext(invocation, importRewrite);

    AST ast = invocation.getAST();
    ListRewrite typeArgsRewrite =
        Invocations.getInferredTypeArgumentsRewrite(rewrite, invocation);

    for (int i = 0; i < typeArguments.length; i++) {
      Type typeArgumentNode =
          importRewrite.addImport(typeArguments[i], ast, importRewriteContext);
      typeArgsRewrite.insertLast(typeArgumentNode, null);
    }

    if (invocation instanceof MethodInvocation) {
      MethodInvocation methodInvocation = (MethodInvocation) invocation;
      Expression expression = methodInvocation.getExpression();
      if (expression == null) {
        IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
        if (methodBinding != null && Modifier.isStatic(methodBinding.getModifiers())) {
          expression =
              ast.newName(
                  importRewrite.addImport(
                      methodBinding.getDeclaringClass().getTypeDeclaration(),
                      importRewriteContext));
        } else {
          expression = ast.newThisExpression();
        }
        rewrite.set(invocation, MethodInvocation.EXPRESSION_PROPERTY, expression, null);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:43,代码来源:AdvancedQuickAssistProcessor.java

示例8: getParamgumentsRewrite

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
/** @return {@inheritDoc} (element type: Expression) */
@Override
protected ListRewrite getParamgumentsRewrite() {
	return getASTRewrite().getListRewrite(fNode, Invocations.getArgumentsProperty(fNode));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:6,代码来源:ChangeSignatureProcessor.java

示例9: addDeprecatedFieldsToMethodsProposals

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
public static void addDeprecatedFieldsToMethodsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
	if (selectedNode instanceof Name) {
		IBinding binding= ((Name) selectedNode).resolveBinding();
		if (binding instanceof IVariableBinding) {
			IVariableBinding variableBinding= (IVariableBinding) binding;
			if (variableBinding.isField()) {
				String qualifiedName= variableBinding.getDeclaringClass().getTypeDeclaration().getQualifiedName();
				String fieldName= variableBinding.getName();
				String[] methodName= getMethod(JavaModelUtil.concatenateName(qualifiedName, fieldName));
				if (methodName != null) {
					AST ast= selectedNode.getAST();
					ASTRewrite astRewrite= ASTRewrite.create(ast);
					ImportRewrite importRewrite= StubUtility.createImportRewrite(context.getASTRoot(), true);

					MethodInvocation method= ast.newMethodInvocation();
					String qfn= importRewrite.addImport(methodName[0]);
					method.setExpression(ast.newName(qfn));
					method.setName(ast.newSimpleName(methodName[1]));
					ASTNode parent= selectedNode.getParent();
					ICompilationUnit cu= context.getCompilationUnit();
					// add explicit type arguments if necessary (for 1.8 and later, we're optimistic that inference just works):
					if (Invocations.isInvocationWithArguments(parent) && !JavaModelUtil.is18OrHigher(cu.getJavaProject())) {
						IMethodBinding methodBinding= Invocations.resolveBinding(parent);
						if (methodBinding != null) {
							ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
							int i= Invocations.getArguments(parent).indexOf(selectedNode);
							if (parameterTypes.length >= i && parameterTypes[i].isParameterizedType()) {
								ITypeBinding[] typeArguments= parameterTypes[i].getTypeArguments();
								for (int j= 0; j < typeArguments.length; j++) {
									ITypeBinding typeArgument= typeArguments[j];
									typeArgument= Bindings.normalizeForDeclarationUse(typeArgument, ast);
									if (! TypeRules.isJavaLangObject(typeArgument)) {
										// add all type arguments if at least one is found to be necessary:
										List<Type> typeArgumentsList= method.typeArguments();
										for (int k= 0; k < typeArguments.length; k++) {
											typeArgument= typeArguments[k];
											typeArgument= Bindings.normalizeForDeclarationUse(typeArgument, ast);
											typeArgumentsList.add(importRewrite.addImport(typeArgument, ast));
										}
										break;
									}
								}
							}
						}
					}
					
					astRewrite.replace(selectedNode, method, null);

					String label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description, BasicElementLabels.getJavaElementName(ASTNodes.asString(method)));
					Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
					ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, astRewrite, IProposalRelevance.REPLACE_FIELD_ACCESS_WITH_METHOD, image);
					proposal.setImportRewrite(importRewrite);
					proposals.add(proposal);
				}
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:60,代码来源:LocalCorrectionsSubProcessor.java

示例10: addDeprecatedFieldsToMethodsProposals

import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入依赖的package包/类
public static void addDeprecatedFieldsToMethodsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
	if (selectedNode instanceof Name) {
		IBinding binding= ((Name) selectedNode).resolveBinding();
		if (binding instanceof IVariableBinding) {
			IVariableBinding variableBinding= (IVariableBinding) binding;
			if (variableBinding.isField()) {
				String qualifiedName= variableBinding.getDeclaringClass().getTypeDeclaration().getQualifiedName();
				String fieldName= variableBinding.getName();
				String[] methodName= getMethod(JavaModelUtil.concatenateName(qualifiedName, fieldName));
				if (methodName != null) {
					AST ast= selectedNode.getAST();
					ASTRewrite astRewrite= ASTRewrite.create(ast);
					ImportRewrite importRewrite= StubUtility.createImportRewrite(context.getASTRoot(), true);

					MethodInvocation method= ast.newMethodInvocation();
					String qfn= importRewrite.addImport(methodName[0]);
					method.setExpression(ast.newName(qfn));
					method.setName(ast.newSimpleName(methodName[1]));
					ASTNode parent= selectedNode.getParent();
					// add explicit type arguments if necessary:
					if (Invocations.isInvocationWithArguments(parent)) {
						IMethodBinding methodBinding= Invocations.resolveBinding(parent);
						if (methodBinding != null) {
							ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
							int i= Invocations.getArguments(parent).indexOf(selectedNode);
							if (parameterTypes.length >= i && parameterTypes[i].isParameterizedType()) {
								ITypeBinding[] typeArguments= parameterTypes[i].getTypeArguments();
								for (int j= 0; j < typeArguments.length; j++) {
									ITypeBinding typeArgument= typeArguments[j];
									if (! TypeRules.isJavaLangObject(typeArgument)) {
										List<Type> typeArgumentsList= method.typeArguments();
										for (int k= 0; k < typeArguments.length; k++) {
											typeArgument= typeArguments[k];
											typeArgumentsList.add(importRewrite.addImport(typeArgument, ast));
										}
										break;
									}
								}
							}
						}
					}
					
					astRewrite.replace(selectedNode, method, null);

					String label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description, BasicElementLabels.getJavaElementName(ASTNodes.asString(method)));
					Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
					ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), astRewrite, 10, image);
					proposal.setImportRewrite(importRewrite);
					proposals.add(proposal);
				}
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:56,代码来源:LocalCorrectionsSubProcessor.java


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