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


Java ASTNodes.getTypeBinding方法代码示例

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


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

示例1: updateTypeReferences

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private void updateTypeReferences(ASTRewrite rewriter, CallContext context) {
  ImportRewrite importer = context.importer;
  for (Iterator<SimpleName> iter = fAnalyzer.getTypesToImport().iterator(); iter.hasNext(); ) {
    Name element = iter.next();
    ITypeBinding binding = ASTNodes.getTypeBinding(element);
    if (binding != null && !binding.isLocal()) {
      // We have collected names not types. So we have to import
      // the declaration type if we reference a parameterized type
      // since we have an entry for every name node (e.g. one for
      // Vector and one for Integer in Vector<Integer>.
      if (binding.isParameterizedType()) {
        binding = binding.getTypeDeclaration();
      }
      String s = importer.addImport(binding);
      if (!ASTNodes.asString(element).equals(s)) {
        rewriter.replace(element, rewriter.createStringPlaceholder(s, ASTNode.SIMPLE_NAME), null);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:SourceProvider.java

示例2: updateMethodInvocation

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private RefactoringStatus updateMethodInvocation(
    MethodInvocation originalInvocation, IMember enclosing, CompilationUnitRewrite unitRewriter)
    throws JavaModelException {

  RefactoringStatus status = new RefactoringStatus();

  // If the method invocation utilizes type arguments, skip this
  // call as the new target method may have additional parameters
  if (originalInvocation.typeArguments().size() > 0)
    return createWarningAboutCall(
        enclosing,
        originalInvocation,
        RefactoringCoreMessages.IntroduceIndirectionRefactoring_call_warning_type_arguments);

  MethodInvocation newInvocation = unitRewriter.getAST().newMethodInvocation();
  List<Expression> newInvocationArgs = newInvocation.arguments();
  List<Expression> originalInvocationArgs = originalInvocation.arguments();

  // static call => always use a qualifier
  String qualifier = unitRewriter.getImportRewrite().addImport(fIntermediaryTypeBinding);
  newInvocation.setExpression(ASTNodeFactory.newName(unitRewriter.getAST(), qualifier));
  newInvocation.setName(unitRewriter.getAST().newSimpleName(getIntermediaryMethodName()));

  final Expression expression = originalInvocation.getExpression();

  if (!isStaticTarget()) {
    // Add the expression as the first parameter
    if (expression == null) {
      // There is no expression for this call. Use a (possibly qualified) "this" expression.
      ThisExpression expr = unitRewriter.getAST().newThisExpression();
      RefactoringStatus qualifierStatus =
          qualifyThisExpression(expr, originalInvocation, enclosing, unitRewriter);
      status.merge(qualifierStatus);
      if (qualifierStatus.hasEntries())
        // warning means don't include this invocation
        return status;
      newInvocationArgs.add(expr);
    } else {
      Expression expressionAsParam =
          (Expression) unitRewriter.getASTRewrite().createMoveTarget(expression);
      newInvocationArgs.add(expressionAsParam);
    }
  } else {
    if (expression != null) {
      // Check if expression is the type name. If not, there may
      // be side effects (e.g. inside methods) -> don't update
      if (!(expression instanceof Name) || ASTNodes.getTypeBinding((Name) expression) == null)
        return createWarningAboutCall(
            enclosing,
            originalInvocation,
            RefactoringCoreMessages
                .IntroduceIndirectionRefactoring_call_warning_static_expression_access);
    }
  }

  for (int i = 0; i < originalInvocationArgs.size(); i++) {
    Expression originalInvocationArg = originalInvocationArgs.get(i);
    Expression movedArg =
        (Expression) unitRewriter.getASTRewrite().createMoveTarget(originalInvocationArg);
    newInvocationArgs.add(movedArg);
  }

  unitRewriter
      .getASTRewrite()
      .replace(
          originalInvocation,
          newInvocation,
          unitRewriter.createGroupDescription(
              RefactoringCoreMessages
                  .IntroduceIndirectionRefactoring_group_description_replace_call));

  return status;
}
 
开发者ID:eclipse,项目名称:che,代码行数:74,代码来源:IntroduceIndirectionRefactoring.java


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