當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodInvocation.resolveMethodBinding方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.MethodInvocation.resolveMethodBinding方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodInvocation.resolveMethodBinding方法的具體用法?Java MethodInvocation.resolveMethodBinding怎麽用?Java MethodInvocation.resolveMethodBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.MethodInvocation的用法示例。


在下文中一共展示了MethodInvocation.resolveMethodBinding方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visit

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public boolean visit(MethodInvocation node) {
	// check for calls to particular java.lang.Object
	// methods #144.
	IMethodBinding methodBinding = node.resolveMethodBinding();

	if (methodBinding != null && methodBinding.getDeclaringClass().getQualifiedName().equals("java.lang.Object")) {
		IMethod calledObjectMethod = (IMethod) methodBinding.getJavaElement();

		try {
			if (Flags.isProtected(calledObjectMethod.getFlags())) {
				this.methodContainsCallToProtectedObjectMethod = true;
				this.calledProtectedObjectMethodSet.add(calledObjectMethod);
			}
		} catch (JavaModelException e) {
			throw new RuntimeException(e);
		}
	}
	return super.visit(node);
}
 
開發者ID:ponder-lab,項目名稱:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代碼行數:21,代碼來源:SourceMethodBodyAnalysisVisitor.java

示例2: checkExpressionCondition

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
private IStatus checkExpressionCondition() {
  Expression expression = getForStatement().getExpression();
  if (!(expression instanceof MethodInvocation)) return SEMANTIC_CHANGE_WARNING_STATUS;

  MethodInvocation invoc = (MethodInvocation) expression;
  IMethodBinding methodBinding = invoc.resolveMethodBinding();
  if (methodBinding == null) return ERROR_STATUS;

  ITypeBinding declaringClass = methodBinding.getDeclaringClass();
  if (declaringClass == null) return ERROR_STATUS;

  String qualifiedName = declaringClass.getQualifiedName();
  String methodName = invoc.getName().getIdentifier();
  if (qualifiedName.startsWith("java.util.Enumeration")) { // $NON-NLS-1$
    if (!methodName.equals("hasMoreElements")) // $NON-NLS-1$
    return SEMANTIC_CHANGE_WARNING_STATUS;
  } else if (qualifiedName.startsWith("java.util.Iterator")) { // $NON-NLS-1$
    if (!methodName.equals("hasNext")) // $NON-NLS-1$
    return SEMANTIC_CHANGE_WARNING_STATUS;
    return checkIteratorCondition();
  } else {
    return SEMANTIC_CHANGE_WARNING_STATUS;
  }

  return StatusInfo.OK_STATUS;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:27,代碼來源:ConvertIterableLoopOperation.java

示例3: getExpressionType

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
private ITypeBinding getExpressionType(
    final MethodInvocation invocation, ITypeBinding typeBinding) {
  if (typeBinding == null) return null;
  for (IMethodBinding iMethodBinding : typeBinding.getDeclaredMethods()) {
    if (invocation.resolveMethodBinding() == iMethodBinding)
      return typeBinding.getTypeDeclaration();
  }
  ITypeBinding expressionType = getExpressionType(invocation, typeBinding.getSuperclass());
  if (expressionType != null) {
    return expressionType;
  }
  for (ITypeBinding interfaceBinding : typeBinding.getInterfaces()) {
    expressionType = getExpressionType(invocation, interfaceBinding);
    if (expressionType != null) {
      return expressionType;
    }
  }
  return null;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:20,代碼來源:IntroduceIndirectionRefactoring.java

示例4: visit

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public final boolean visit(MethodInvocation node) {
	IMethodBinding methodBinding = node.resolveMethodBinding();
	if (methodBinding != null) {
	    handleTypeBinding(node, methodBinding.getDeclaringClass(), false);
	    handleMethodBinding(node, methodBinding);
	}
	return true;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:10,代碼來源:DependenciesAstVisitor.java

示例5: visit

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public boolean visit(MethodInvocation loc) {
	if (currentMethod == null)
		return false;
	if (loc.resolveMethodBinding() == null)
		return false;
	if (loc.resolveMethodBinding().getMethodDeclaration() == null || loc.resolveMethodBinding().getMethodDeclaration().getJavaElement() == null)
		return true;
	if (loc.resolveMethodBinding().getMethodDeclaration().getJavaElement().isReadOnly())
		return true;
	addCalledMethod(loc.resolveMethodBinding().getMethodDeclaration());
	return true;
}
 
開發者ID:ioanaverebi,項目名稱:Sparrow,代碼行數:14,代碼來源:OutCodeVisitor.java

示例6: visit

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public boolean visit(MethodInvocation methodInvocation) {
	IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();

	if (methodBinding != null) {
		IJavaElement javaElement = methodBinding.getJavaElement();

		if (javaElement == null)
			MigrateSkeletalImplementationToInterfaceRefactoringProcessor
					.logWarning("Could not get Java element from binding: " + methodBinding + " while processing: "
							+ methodInvocation);
		else if (javaElement.equals(accessedMethod)) {
			Expression expression = methodInvocation.getExpression();
			expression = (Expression) Util.stripParenthesizedExpressions(expression);

			// FIXME: It's not really that the expression is a `this`
			// expression but that the type of the expression comes from
			// a
			// `this` expression. In other words, we may need to climb
			// the
			// AST.
			if (expression == null || expression.getNodeType() == ASTNode.THIS_EXPRESSION)
				this.encounteredThisReceiver = true;
		}
	}
	return super.visit(methodInvocation);
}
 
開發者ID:ponder-lab,項目名稱:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代碼行數:28,代碼來源:MethodReceiverAnalysisVisitor.java

示例7: visit

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
public boolean visit(MethodInvocation node)
{
  IMethodBinding mmtb = node.resolveMethodBinding();
  if (this.mtbStack.isEmpty()) {
    return true;
  }
  try
  {
    if (node.getExpression() != null) {
      if (mmtb.getDeclaringClass().getQualifiedName().startsWith("java.awt.geom.Path2D"))
      {
        Expression e = node.getExpression();
        ITypeBinding itb = e.resolveTypeBinding();
        this.facts.add(Fact.makeCallsFact(getQualifiedName((IMethodBinding)this.mtbStack.peek()), 
          getQualifiedName(itb) + "#" + getSimpleName(mmtb)));
        break label179;
      }
    }
    this.facts.add(Fact.makeCallsFact(getQualifiedName((IMethodBinding)this.mtbStack.peek()), 
      getQualifiedName(mmtb)));
  }
  catch (Exception localException)
  {
    System.err.println("Cannot resolve method invocation \"" + 
      node.getName().toString() + "\"");
  }
  label179:
  return true;
}
 
開發者ID:SEAL-UCLA,項目名稱:Ref-Finder,代碼行數:30,代碼來源:ASTVisitorAtomicChange.java

示例8: visit

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public boolean visit(MethodInvocation node) {
  IMethodBinding binding = node.resolveMethodBinding();
  if (binding != null
      && !JdtFlags.isStatic(binding)
      && node.getExpression() == null
      && Bindings.isSuperType(binding.getDeclaringClass(), fFunctionalInterface, false))
    throw new AbortSearchException();
  return true;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:11,代碼來源:LambdaExpressionsFix.java

示例9: visit

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public boolean visit(MethodInvocation node) {
  IMethodBinding methodBinding = node.resolveMethodBinding();
  if (methodBinding != null) methodBinding.getMethodDeclaration();
  if (fBinding != null
      && methodBinding != null
      && fBinding.isEqualTo(methodBinding)
      && !status.hasFatalError()) {
    status.addFatalError(
        RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_recursive_call);
    return false;
  }
  return true;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:15,代碼來源:SourceAnalyzer.java

示例10: visit

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public boolean visit(MethodInvocation node) {
	IMethodBinding iMethodBinding = node.resolveMethodBinding();
	ITypeBinding[] exceptionTypes = iMethodBinding.getExceptionTypes();
	// if there are exceptions
	if (exceptionTypes.length >= 1) {
		try {
			handleException(node, exceptionTypes);
		} catch (JavaModelException e) {
			throw new RuntimeException(e);
		}
	}

	return super.visit(node);
}
 
開發者ID:mdarefin,項目名稱:Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin,代碼行數:16,代碼來源:EnhancedForStatementVisitor.java

示例11: addExplicitTypeArgumentsIfNecessary

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
private void addExplicitTypeArgumentsIfNecessary(Expression invocation) {
  if (Invocations.isResolvedTypeInferredFromExpectedType(invocation)) {
    ASTNode referenceContext = fNewLocation.getParent();
    if (!(referenceContext instanceof VariableDeclarationFragment
        || referenceContext instanceof SingleVariableDeclaration
        || referenceContext instanceof Assignment)) {
      ITypeBinding[] typeArguments = Invocations.getInferredTypeArguments(invocation);
      ListRewrite typeArgsRewrite =
          Invocations.getInferredTypeArgumentsRewrite(fInitializerRewrite, invocation);
      for (int i = 0; i < typeArguments.length; i++) {
        Type typeArgument =
            fNewLocationCuRewrite
                .getImportRewrite()
                .addImport(
                    typeArguments[i], fNewLocationCuRewrite.getAST(), fNewLocationContext);
        fNewLocationCuRewrite.getImportRemover().registerAddedImports(typeArgument);
        typeArgsRewrite.insertLast(typeArgument, null);
      }

      if (invocation instanceof MethodInvocation) {
        MethodInvocation methodInvocation = (MethodInvocation) invocation;
        Expression expression = methodInvocation.getExpression();
        if (expression == null) {
          IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
          if (methodBinding != null) {
            expression =
                fNewLocationCuRewrite
                    .getAST()
                    .newName(
                        fNewLocationCuRewrite
                            .getImportRewrite()
                            .addImport(
                                methodBinding.getDeclaringClass().getTypeDeclaration(),
                                fNewLocationContext));
            fInitializerRewrite.set(
                invocation, MethodInvocation.EXPRESSION_PROPERTY, expression, null);
          }
        }
      }
    }
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:43,代碼來源:InlineConstantRefactoring.java

示例12: checkInitialConditions

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
  // TargetProvider must get an untampered AST with original invocation node
  // SourceProvider must get a tweaked AST with method body / parameter names replaced

  RefactoringStatus result = new RefactoringStatus();

  if (fMethod == null) {
    if (!(fSelectionTypeRoot instanceof ICompilationUnit))
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ReplaceInvocationsRefactoring_cannot_replace_in_binary);

    ICompilationUnit cu = (ICompilationUnit) fSelectionTypeRoot;
    CompilationUnit root = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, true);
    fSelectionNode = getTargetNode(cu, root, fSelectionStart, fSelectionLength);
    if (fSelectionNode == null)
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ReplaceInvocationsRefactoring_select_method_to_apply);

    if (fSelectionNode.getNodeType() == ASTNode.METHOD_DECLARATION) {
      MethodDeclaration methodDeclaration = (MethodDeclaration) fSelectionNode;
      fTargetProvider = TargetProvider.create(methodDeclaration);
      fMethodBinding = methodDeclaration.resolveBinding();
    } else {
      MethodInvocation methodInvocation = (MethodInvocation) fSelectionNode;
      fTargetProvider = TargetProvider.create(cu, methodInvocation);
      fMethodBinding = methodInvocation.resolveMethodBinding();
    }
    if (fMethodBinding == null)
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
    fMethod = (IMethod) fMethodBinding.getJavaElement();

  } else {
    ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
    parser.setProject(fMethod.getJavaProject());
    IBinding[] bindings = parser.createBindings(new IJavaElement[] {fMethod}, null);
    fMethodBinding = (IMethodBinding) bindings[0];
    if (fMethodBinding == null)
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);

    fTargetProvider = TargetProvider.create(fMethodBinding);
  }

  result.merge(fTargetProvider.checkActivation());
  return result;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:49,代碼來源:ReplaceInvocationsRefactoring.java

示例13: needsExplicitCast

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
/**
 * @param status the status
 * @return <code>true</code> if explicit cast is needed otherwise <code>false</code>
 */
private boolean needsExplicitCast(RefactoringStatus status) {
  // if the return type of the method is the same as the type of the
  // returned expression then we don't need an explicit cast.
  if (fSourceProvider.returnTypeMatchesReturnExpressions()) return false;

  List<Expression> returnExprs = fSourceProvider.getReturnExpressions();
  // it is inferred that only methods consisting of a single
  // return statement can be inlined as parameters in other
  // method invocations
  if (returnExprs.size() != 1) return false;

  if (fTargetNode.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) {
    MethodInvocation methodInvocation = (MethodInvocation) fTargetNode.getParent();
    if (methodInvocation.getExpression() == fTargetNode) return false;
    IMethodBinding method = methodInvocation.resolveMethodBinding();
    if (method == null) {
      status.addError(
          RefactoringCoreMessages.CallInliner_cast_analysis_error,
          JavaStatusContext.create(fCUnit, methodInvocation));
      return false;
    }
    ITypeBinding[] parameters = method.getParameterTypes();
    int argumentIndex = methodInvocation.arguments().indexOf(fInvocation);

    ITypeBinding parameterType = returnExprs.get(0).resolveTypeBinding();
    if (method.isVarargs() && argumentIndex >= parameters.length - 1) {
      argumentIndex = parameters.length - 1;
      parameterType = parameterType.createArrayType(1);
    }
    parameters[argumentIndex] = parameterType;

    ITypeBinding type = ASTNodes.getReceiverTypeBinding(methodInvocation);
    TypeBindingVisitor visitor =
        new AmbiguousMethodAnalyzer(
            fTypeEnvironment, method, fTypeEnvironment.create(parameters));
    if (!visitor.visit(type)) {
      return true;
    } else if (type.isInterface()) {
      return !Bindings.visitInterfaces(type, visitor);
    } else if (Modifier.isAbstract(type.getModifiers())) {
      return !Bindings.visitHierarchy(type, visitor);
    } else {
      // it is not needed to visit interfaces if receiver is a concrete class
      return !Bindings.visitSuperclasses(type, visitor);
    }
  } else {
    ITypeBinding explicitCast =
        ASTNodes.getExplicitCast(returnExprs.get(0), (Expression) fTargetNode);
    return explicitCast != null;
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:56,代碼來源:CallInliner.java

示例14: isActionCall

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
public static boolean isActionCall(MethodInvocation methodInvocation) {
	IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
	ITypeBinding declaringClass = methodBinding.getDeclaringClass();
	return typeIsAssignableFrom(declaringClass, hu.elte.txtuml.api.model.Action.class);
}
 
開發者ID:ELTE-Soft,項目名稱:txtUML,代碼行數:6,代碼來源:SharedUtils.java

示例15: retrieveResultReference

import org.eclipse.jdt.core.dom.MethodInvocation; //導入方法依賴的package包/類
private VariableReference retrieveResultReference(MethodInvocation methodInvocation) {
	VariableReference result = calleeResultMap.get(methodInvocation.toString());
	if (result != null) {
		return result;
	}
	ASTNode parent = methodInvocation.getParent();
	if (parent instanceof VariableDeclarationFragment) {
		return retrieveVariableReference(parent, null);
	}
	if (parent instanceof Assignment) {
		Assignment assignment = (Assignment) parent;
		return retrieveVariableReference(assignment.getLeftHandSide(), null);
	}
	IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
	ITypeBinding returnType = methodBinding.getReturnType();
	Class<?> resultClass = null;
	try {
		resultClass = retrieveTypeClass(returnType);
	} catch (Exception exc) {
		String localClass = methodBinding.getDeclaringClass().getQualifiedName()
		        + "." + returnType.getName();
		resultClass = loadClass(localClass);
	}
	result = retrieveVariableReference(returnType, resultClass);
	calleeResultMap.put(methodInvocation.toString(), result);
	return result;
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:28,代碼來源:TestExtractingVisitor.java


注:本文中的org.eclipse.jdt.core.dom.MethodInvocation.resolveMethodBinding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。