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


Java Expression.getSymbolData方法代码示例

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


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

示例1: visit

import org.walkmod.javalang.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public void visit(SuperExpr n, A arg) {
    Expression classExpr = n.getClassExpr();
    Symbol<?> s = null;
    if (classExpr == null) {
        s = symbolTable.lookUpSymbolForRead("super", null, ReferenceType.VARIABLE);

    } else {
        classExpr.accept(this, arg);
        SymbolData sd = classExpr.getSymbolData();
        Class<?> aux = sd.getClazz().getSuperclass();
        if (aux == null) {
            aux = Object.class;
        }
        s = symbolTable.lookUpSymbolForRead(aux.getCanonicalName(), null, ReferenceType.TYPE);

    }
    if (n.getSymbolData() == null && s != null) {
        n.setSymbolData(s.getType());
    }
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:22,代码来源:SymbolVisitorAdapter.java

示例2: visit

import org.walkmod.javalang.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public void visit(ArrayInitializerExpr n, A arg) {

    if (n.getValues() != null) {

        List<Expression> values = n.getValues();
        SymbolType st = null;
        for (Expression expr : values) {
            expr.accept(this, arg);
            SymbolData sd = expr.getSymbolData();
            if (st == null && sd != null) {
                st = (SymbolType) sd;
                st = st.clone();

            } else if (sd != null) {
                st = (SymbolType) st.merge(sd);
            }

        }
        if (values != null && !values.isEmpty() && st != null) {
            st.setArrayCount(st.getArrayCount() + 1);
        }

        n.setSymbolData(st);
    }
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:27,代码来源:TypeVisitorAdapter.java

示例3: argTypes

import org.walkmod.javalang.ast.expr.Expression; //导入方法依赖的package包/类
private ArgTypes argTypes(List<Expression> args, A arg) {
    boolean hasFunctionalExpressions = false;
    SymbolType[] symbolTypes = null;
    if (args != null) {

        symbolTypes = new SymbolType[args.size()];
        int i = 0;

        for (Expression e : args) {
            if (!(e instanceof LambdaExpr) && !(e instanceof MethodReferenceExpr)) {
                e.accept(this, arg);
                SymbolType argType = null;
                if (e instanceof ObjectCreationExpr) {
                    ObjectCreationExpr aux = (ObjectCreationExpr) e;
                    argType = (SymbolType) aux.getType().getSymbolData();
                } else {
                    argType = (SymbolType) e.getSymbolData();
                }
                symbolTypes[i] = argType;
            } else {
                hasFunctionalExpressions = true;
            }
            i++;
        }
    } else {
        symbolTypes = new SymbolType[0];
    }
    return new ArgTypes(symbolTypes, hasFunctionalExpressions);
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:30,代码来源:TypeVisitorAdapter.java

示例4: testMethodsThatReturnsMatrixs

import org.walkmod.javalang.ast.expr.Expression; //导入方法依赖的package包/类
@Test
public void testMethodsThatReturnsMatrixs() throws Exception {
    CompilationUnit cu = run(
            "public class A { char[][] bar(){ return new char[0][0]; } void foo(String s) { int i = bar().length; }}");
    MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(1);
    ExpressionStmt stmt = (ExpressionStmt) md.getBody().getStmts().get(0);
    VariableDeclarationExpr vexpr = (VariableDeclarationExpr) stmt.getExpression();
    Expression expr = vexpr.getVars().get(0).getInit();
    SymbolData sd = expr.getSymbolData();
    Assert.assertNotNull(sd);
    Assert.assertEquals("int", sd.getName());
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:13,代码来源:SymbolVisitorAdapterTest.java

示例5: filter

import org.walkmod.javalang.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public boolean filter(Class<?> candidate) {
    boolean isCompatible = true;

    List<Method> methods = new LinkedList<Method>();

    boolean returnTypeCompatible = false;
    methods.addAll(Arrays.asList(candidate.getDeclaredMethods()));

    methods.addAll(Arrays.asList(candidate.getMethods()));
    Iterator<Method> it = methods.iterator();

    while (it.hasNext() && !returnTypeCompatible) {

        Method currentMethod = it.next();

        // checking method name
        if (currentMethod.getName().equals(requiredMethod.getName())) {
            List<Expression> args = requiredMethod.getArgs();
            Class<?>[] parameterTypes = currentMethod.getParameterTypes();
            if (args != null) {
                boolean compatibleArgs = true;
                int k = 0;

                for (Expression argExpr : args) {
                    argExpr.accept(visitor, ctx);
                    SymbolType typeArg = (SymbolType) argExpr.getSymbolData();
                    if (!Types.isCompatible(typeArg.getClazz(), parameterTypes[k])) {
                        compatibleArgs = false;
                    }
                    k++;
                }
                returnTypeCompatible = compatibleArgs;
            } else {
                returnTypeCompatible = true;
            }
        }
    }

    isCompatible = returnTypeCompatible;

    return isCompatible;
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:44,代码来源:RequiredMethodPredicate.java

示例6: filter

import org.walkmod.javalang.ast.expr.Expression; //导入方法依赖的package包/类
public boolean filter(java.lang.reflect.Type[] genericTypes, Class<?> declaringClass) throws Exception {

        boolean found = false;
        boolean containsLambda = false;
        SymbolType[] inferredTypes = null;
        if (previousPredicate != null) {
            inferredTypes = previousPredicate.getInferredMethodArgs();
        }
        if (args != null && !args.isEmpty()) {
            Iterator<Expression> it = args.iterator();
            int i = 0;
            while (it.hasNext() && !found) {
                SymbolType argType = null;
                if (inferredTypes != null) {
                    argType = inferredTypes[i];
                }
                Expression current = it.next();
                if (current instanceof LambdaExpr || current instanceof MethodReferenceExpr) {

                    containsLambda = true;
                    Class<?> interfaceToInspect = null;

                    if (inferredTypes[i].getClazz().isInterface()) {
                        interfaceToInspect = inferredTypes[i].getClazz();

                    } else if (isVarArgs && i == params.length - 1) {
                        Class<?> componentType = inferredTypes[i].getClazz();
                        if (componentType.isInterface()) {
                            interfaceToInspect = componentType;
                        }
                    }
                    if (interfaceToInspect != null) {
                        if (current instanceof LambdaExpr) {
                            found = filter((LambdaExpr) current, interfaceToInspect, genericTypes[i], argType,
                                    declaringClass);
                            if (found) {
                                calculatedTypeArgs[i] = (SymbolType) current.getSymbolData();
                            }
                        } else {
                            found = filter((MethodReferenceExpr) current, interfaceToInspect, genericTypes[i], argType,
                                    declaringClass);
                            if (found) {
                                calculatedTypeArgs[i] = (SymbolType) current.getSymbolData();
                            }
                        }
                    }

                }
                if (i < params.length - 1) {
                    i++;
                }

            }
        }

        return (found && containsLambda) || !containsLambda;
    }
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:58,代码来源:AbstractCompatibleFunctionalPredicate.java

示例7: build

import org.walkmod.javalang.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public MethodCallExpr build(MethodCallExpr n) throws Exception {
    List<Expression> args = n.getArgs();
    MethodSymbolData st = n.getSymbolData();
    if (args != null) {
        int i = 0;
        if (st == null) {
            Expression scope = n.getScope();
            String scopeName = "empty";
            if (scope != null) {
                scopeName = scope.getSymbolData().toString();
            }
            String argsTypeName = "empty";
            List<Expression> argExpr = n.getArgs();
            if (argExpr != null) {
                argsTypeName = "[";
                Iterator<Expression> it = argExpr.iterator();
                while (it.hasNext()) {
                    Expression arg = it.next();
                    if (arg != null && arg.getSymbolData() != null) {
                        argsTypeName += " " + arg.getSymbolData().toString();
                    } else {
                        argsTypeName += " null";
                    }
                    if (it.hasNext()) {
                        argsTypeName += ",";
                    }
                }
                argsTypeName += "]";
            }
            throw new Exception("Ops! The method call " + n.toString() + " is not resolved. The scope is ["
                    + scopeName + "] , and the args are : " + argsTypeName);
        }
        java.lang.reflect.Type[] argClasses = st.getMethod().getGenericParameterTypes();
        int paramCount = st.getMethod().getParameterTypes().length;
        for (Expression argument : args) {
            if (argument instanceof MethodReferenceExpr) {
                SymbolType aux = null;
                if (i < paramCount) {
                    aux = SymbolType.valueOf(argClasses[i], typeMapping);

                } else {
                    java.lang.reflect.Type componentType = null;
                    java.lang.reflect.Type lastArg = argClasses[argClasses.length - 1];
                    if (lastArg instanceof Class<?>) {
                        componentType = ((Class<?>) lastArg).getComponentType();
                    } else if (lastArg instanceof GenericArrayType) {
                        componentType = ((GenericArrayType) lastArg).getGenericComponentType();
                    }
                    aux = SymbolType.valueOf(componentType, typeMapping);
                }
                argument.setSymbolData(aux);
                argument.accept(visitor, ctxt);
            }
            i++;
        }
    }
    return null;
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:60,代码来源:SymbolDataOfMethodReferenceBuilder.java


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