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


Java MethodCallExpr类代码示例

本文整理汇总了Java中com.github.javaparser.ast.expr.MethodCallExpr的典型用法代码示例。如果您正苦于以下问题:Java MethodCallExpr类的具体用法?Java MethodCallExpr怎么用?Java MethodCallExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MethodCallExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了MethodCallExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveStaticMethodsUsingImports

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
/**
 * Resolve static method calls using static imports
 * @param expression The expression to resolve
 */
private void resolveStaticMethodsUsingImports(Expression expression)
{
    if (expression instanceof MethodCallExpr)
    {
        MethodCallExpr methodCall = ((MethodCallExpr) expression);
        String methodName = methodCall.getName().getIdentifier();
        if (!methodCall.getScope().isPresent() && context.hasStaticMethod(methodName))
        {
            methodCall.setName(context.getFullyQualifiedNameForMethodName(methodName));
        }
    }

    // Recurse downward in the expression
    expression
        .getChildNodes()
        .stream()
        .filter(Expression.class::isInstance)
        .map(Expression.class::cast)
        .forEach(this::resolveStaticMethodsUsingImports);
}
 
开发者ID:Axellience,项目名称:vue-gwt,代码行数:25,代码来源:TemplateParser.java

示例2: parseMethodCallExpression

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
/**
 *
 * @param mcEx
 *      a github javaparser MethodCallExpression
 * @param attributes
 *      the list of attributes of the class,
 *      to potentially get a type from the name
 * @param lineNumber
 *      the starting line number of the parse method or constructor
 * @return
 *      a CallExpression structure
 */
private CallExpression parseMethodCallExpression(MethodCallExpr mcEx, List<Attribute> attributes, int lineNumber) {
    CallExpression callExpr = new CallExpression();
    FuncRef funcRef = new FuncRef();
    funcRef.setFuncName(mcEx.getName());
    if (mcEx.getScope() != null) {
        funcRef.setNamespace(mcEx.getScope().toString());
    }
    callExpr.setFunction(funcRef);
    List<Expr> arguments = new ArrayList<>();
    if (mcEx.getArgs() != null) {
        for (Expression expr : mcEx.getArgs()) {
            arguments.add(parseExpression(expr, attributes, lineNumber));
        }
    }
    callExpr.setArguments(arguments);
    callExpr.setLine(mcEx.getBeginLine() - lineNumber);
    return callExpr;
}
 
开发者ID:DevMine,项目名称:parsers,代码行数:31,代码来源:Parser.java

示例3: visit

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Override public Node visit(final MethodCallExpr n, final A arg) {
	if (n.getScope() != null) {
		n.setScope((Expression) n.getScope().accept(this, arg));
	}
	final List<Type> typeArgs = n.getTypeArgs();
	if (typeArgs != null) {
		for (int i = 0; i < typeArgs.size(); i++) {
			typeArgs.set(i, (Type) typeArgs.get(i).accept(this, arg));
		}
		removeNulls(typeArgs);
	}
	final List<Expression> args = n.getArgs();
	if (args != null) {
		for (int i = 0; i < args.size(); i++) {
			args.set(i, (Expression) args.get(i).accept(this, arg));
		}
		removeNulls(args);
	}
	return n;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:21,代码来源:ModifierVisitorAdapter.java

示例4: resolveLocalAndSeveralAnnidatedLevels

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void resolveLocalAndSeveralAnnidatedLevels() throws ParseException {
    CompilationUnit cu = parseSample("LocalVariableInParent");
    com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "LocalVariableInParent");
    MethodDeclaration method = Navigator.demandMethod(referencesToField, "foo4");
    MethodCallExpr call = Navigator.findMethodCall(method, "add");

    TypeSolver typeSolver = new ReflectionTypeSolver();

    SymbolReference<? extends ResolvedValueDeclaration> ref = JavaParserFacade.get(typeSolver).solve(call.getScope().get());
    assertTrue(ref.isSolved());
    assertEquals("java.util.List<Comment>", ref.getCorrespondingDeclaration().getType().describe());

    MethodUsage methodUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(call);
    assertEquals("add", methodUsage.getName());
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:StatementContextResolutionTest.java

示例5: resolveMethodOnGenericClass

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void resolveMethodOnGenericClass() throws ParseException {
    CompilationUnit cu = parseSample("LocalVariableInParent");
    com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "LocalVariableInParent");
    MethodDeclaration method = Navigator.demandMethod(referencesToField, "foo5");
    MethodCallExpr call = Navigator.findMethodCall(method, "add");

    TypeSolver typeSolver = new ReflectionTypeSolver();

    SymbolReference<? extends ResolvedValueDeclaration> ref = JavaParserFacade.get(typeSolver).solve(call.getScope().get());
    assertTrue(ref.isSolved());
    assertEquals("java.util.List<Comment>", ref.getCorrespondingDeclaration().getType().describe());

    MethodUsage methodUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(call);
    assertEquals("add", methodUsage.getName());
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:StatementContextResolutionTest.java

示例6: declaredOnMethodPositiveCase

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void declaredOnMethodPositiveCase() throws ParseException {
    CompilationUnit cu = parseSample("MethodTypeParameter");
    TypeSolver typeSolver = new ReflectionTypeSolver();
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    ClassOrInterfaceDeclaration classDecl = Navigator.demandClass(cu, "Foo");
    MethodDeclaration methodDecl = Navigator.demandMethod(classDecl, "usage");
    MethodCallExpr callToFoo = (MethodCallExpr) Navigator.findReturnStmt(methodDecl).getExpression().get();
    ResolvedMethodDeclaration methodDeclaration = javaParserFacade.solve(callToFoo).getCorrespondingDeclaration();
    for (ResolvedTypeParameterDeclaration tp : methodDeclaration.getTypeParameters()) {
        assertTrue(tp instanceof JavaParserTypeParameter);
        assertEquals("C", tp.getName());
        assertEquals(true, tp.declaredOnMethod());
        assertEquals(false, tp.declaredOnType());
    }
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:JavaParserTypeParameterResolutionTest.java

示例7: declaredOnMethodNegativeCase

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void declaredOnMethodNegativeCase() throws ParseException {
    CompilationUnit cu = parseSample("ClassTypeParameter");
    TypeSolver typeSolver = new ReflectionTypeSolver();
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    ClassOrInterfaceDeclaration classDecl = Navigator.demandClass(cu, "Foo");
    MethodDeclaration methodDecl = Navigator.demandMethod(classDecl, "usage");
    MethodCallExpr callToFoo = (MethodCallExpr) Navigator.findReturnStmt(methodDecl).getExpression().get();
    ResolvedMethodDeclaration methodDeclaration = javaParserFacade.solve(callToFoo).getCorrespondingDeclaration();
    ResolvedReferenceTypeDeclaration typeDeclaration = methodDeclaration.declaringType();
    assertEquals(2, typeDeclaration.getTypeParameters().size());
    assertTrue(typeDeclaration.getTypeParameters().get(0) instanceof JavaParserTypeParameter);
    assertEquals("A", typeDeclaration.getTypeParameters().get(0).getName());
    assertEquals(false, typeDeclaration.getTypeParameters().get(0).declaredOnMethod());
    assertEquals(true, typeDeclaration.getTypeParameters().get(0).declaredOnType());
    assertTrue(typeDeclaration.getTypeParameters().get(1) instanceof JavaParserTypeParameter);
    assertEquals("B", typeDeclaration.getTypeParameters().get(1).getName());
    assertEquals(false, typeDeclaration.getTypeParameters().get(1).declaredOnMethod());
    assertEquals(true, typeDeclaration.getTypeParameters().get(1).declaredOnType());

}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:22,代码来源:JavaParserTypeParameterResolutionTest.java

示例8: assertCanSolveGenericMethodCallCanInferFromArguments

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
private void assertCanSolveGenericMethodCallCanInferFromArguments(String callMethodName) throws ParseException {
    MethodCallExpr methodCallExpr = getMethodCallExpr("genericMethodTest", callMethodName);
    CombinedTypeSolver typeSolver = createTypeSolver();

    MethodCallExprContext context = new MethodCallExprContext(methodCallExpr, typeSolver);

    ResolvedReferenceTypeDeclaration stringType = typeSolver.solveType("java.lang.String");

    List<ResolvedType> argumentsTypes = new ArrayList<>();
    argumentsTypes.add(new ReferenceTypeImpl(stringType, typeSolver));

    Optional<MethodUsage> ref = context.solveMethodAsUsage(callMethodName, argumentsTypes, typeSolver);
    assertTrue(ref.isPresent());
    assertEquals("MethodCalls", ref.get().declaringType().getQualifiedName());
    assertEquals(Collections.singletonList("java.lang.String"), ref.get().typeParametersMap().getTypes().stream().map(ty -> ty.asReferenceType().describe()).collect(Collectors.toList()));
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:MethodCallExprContextResolutionTest.java

示例9: solveParameterOfLambdaInMethodCallExpr

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void solveParameterOfLambdaInMethodCallExpr() throws ParseException {
    CompilationUnit cu = parseSample("Lambda");

    com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
    MethodDeclaration method = Navigator.demandMethod(clazz, "lambdaMap");
    ReturnStmt returnStmt = Navigator.findReturnStmt(method);
    MethodCallExpr methodCallExpr = (MethodCallExpr) returnStmt.getExpression().get();
    LambdaExpr lambdaExpr = (LambdaExpr) methodCallExpr.getArguments().get(0);

    Context context = new LambdaExprContext(lambdaExpr, typeSolver);

    Optional<Value> ref = context.solveSymbolAsValue("p", typeSolver);
    assertTrue(ref.isPresent());
    assertEquals("? super java.lang.String", ref.get().getType().describe());
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:LambdaExprContextResolutionTest.java

示例10: solvingReferenceToUnsupportedOperationException

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void solvingReferenceToUnsupportedOperationException() {
    String code = "public class Bla {\n" +
            "    public void main()\n" +
            "    {\n" +
            "        try\n" +
            "        {\n" +
            "            int i = 0;\n" +
            "        }\n" +
            "        catch (UnsupportedOperationException e)\n" +
            "        {\n" +
            "            String s;\n" +
            "            e.getMessage();\n" +
            "        }\n" +
            "    }\n" +
            "}";
    MethodCallExpr methodCallExpr = Navigator.findNodeOfGivenClass(JavaParser.parse(code), MethodCallExpr.class);
    MethodUsage methodUsage = JavaParserFacade.get(new ReflectionTypeSolver()).solveMethodAsUsage(methodCallExpr);
    assertEquals("java.lang.Throwable.getMessage()", methodUsage.getQualifiedSignature());
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:21,代码来源:JavaParserFacadeResolutionTest.java

示例11: solvingReferenceToCatchClauseParam

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void solvingReferenceToCatchClauseParam() {
    String code = "public class Bla {\n" +
            "    public void main()\n" +
            "    {\n" +
            "        try\n" +
            "        {\n" +
            "            int i = 0;\n" +
            "        }\n" +
            "        catch (UnsupportedOperationException e)\n" +
            "        {\n" +
            "            String s;\n" +
            "            e.getMessage();\n" +
            "        }\n" +
            "    }\n" +
            "}";
    MethodCallExpr methodCallExpr = Navigator.findNodeOfGivenClass(JavaParser.parse(code), MethodCallExpr.class);
    NameExpr nameE = (NameExpr)methodCallExpr.getScope().get();
    SymbolReference<? extends ResolvedValueDeclaration> symbolReference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(nameE);
    assertEquals(true, symbolReference.isSolved());
    assertEquals(true, symbolReference.getCorrespondingDeclaration().isParameter());
    assertEquals("e", symbolReference.getCorrespondingDeclaration().asParameter().getName());
    assertEquals("java.lang.UnsupportedOperationException", symbolReference.getCorrespondingDeclaration().asParameter().getType().asReferenceType().getQualifiedName());
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:25,代码来源:JavaParserFacadeResolutionTest.java

示例12: resolveReferenceToMethod

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void resolveReferenceToMethod() throws ParseException, IOException {
    CompilationUnit cu = parseSample("Navigator");
    com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "Navigator");
    MethodDeclaration method = Navigator.demandMethod(referencesToField, "findType");
    MethodCallExpr callToGetTypes = Navigator.findMethodCall(method, "getTypes");

    String pathToJar = adaptPath("src/test/resources/javaparser-core-2.1.0.jar");
    TypeSolver typeSolver = new CombinedTypeSolver(new JarTypeSolver(pathToJar), new ReflectionTypeSolver(true));
    SymbolSolver symbolSolver = new SymbolSolver(typeSolver);

    MethodUsage ref = symbolSolver.solveMethod("getTypes", Collections.emptyList(), callToGetTypes);

    assertEquals("getTypes", ref.getName());
    assertEquals("com.github.javaparser.ast.CompilationUnit", ref.declaringType().getQualifiedName());

    //verify(typeSolver);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:19,代码来源:ContextTest.java

示例13: resolveGenericReturnTypeOfMethodInJar

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void resolveGenericReturnTypeOfMethodInJar() throws ParseException, IOException {
    CompilationUnit cu = parseSample("Navigator");
    com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Navigator");
    MethodDeclaration method = Navigator.demandMethod(clazz, "findType");
    MethodCallExpr call = Navigator.findMethodCall(method, "getTypes");

    String pathToJar = adaptPath("src/test/resources/javaparser-core-2.1.0.jar");
    TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JarTypeSolver(pathToJar));
    MethodUsage methodUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(call);

    assertEquals("getTypes", methodUsage.getName());
    assertEquals("java.util.List<com.github.javaparser.ast.body.TypeDeclaration>", methodUsage.returnType().describe());
    assertEquals(1, methodUsage.returnType().asReferenceType().typeParametersValues().size());
    assertEquals("com.github.javaparser.ast.body.TypeDeclaration", methodUsage.returnType().asReferenceType().typeParametersValues().get(0).describe());
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:ContextTest.java

示例14: selectMostSpecificVariadic

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void selectMostSpecificVariadic() throws ParseException {
    CompilationUnit cu = parseSample("MethodCalls");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MethodCalls");

    MethodDeclaration method = Navigator.demandMethod(clazz, "variadicTest");
    List<MethodCallExpr> calls = method.getNodesByType(MethodCallExpr.class);

    File src = adaptPath(new File("src/test/resources"));
    TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(src));

    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    MethodUsage call1 = javaParserFacade.solveMethodAsUsage(calls.get(0));
    MethodUsage call2 = javaParserFacade.solveMethodAsUsage(calls.get(1));
    assertEquals("int", call1.returnType().describe());
    assertEquals("void", call2.returnType().describe());
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:18,代码来源:VariadicResolutionTest.java

示例15: classCastScope

import com.github.javaparser.ast.expr.MethodCallExpr; //导入依赖的package包/类
@Test
public void classCastScope() throws ParseException {
    CompilationUnit cu = parseSample("ClassCast");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "ClassCast");
    MethodDeclaration method = Navigator.demandMethod(clazz, "getNodesByType");
    MethodCallExpr call = Navigator.findMethodCall(method, "cast");

    TypeSolver typeSolver = new ReflectionTypeSolver();
    Expression scope = call.getScope().get();
    ResolvedType type = JavaParserFacade.get(typeSolver).getType(scope);

    //System.out.println(typeUsage);

    assertEquals(false, type.isTypeVariable());
    assertEquals("java.lang.Class<N>", type.describe());
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:GenericsResolutionTest.java


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