use of com.github.javaparser.ast.expr.Expression in project javaparser by javaparser.
the class LambdaResolutionTest method typeOfVoidLambda.
@Test
public void typeOfVoidLambda() {
CompilationUnit cu = parseSample("LambdaVoid");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "lambdaEmpty");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
Expression expression = returnStmt.getExpression().get();
LambdaExpr lambdaExpr = Navigator.findNodeOfGivenClass(expression, LambdaExpr.class);
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(lambdaExpr);
assertEquals("void", type.describe());
}
use of com.github.javaparser.ast.expr.Expression in project javaparser by javaparser.
the class MethodsResolutionTest method solveMethodAccessThroughSuper.
@Test
public void solveMethodAccessThroughSuper() {
CompilationUnit cu = parseSample("AccessThroughSuper");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessThroughSuper.SubClass");
MethodDeclaration method = Navigator.demandMethod(clazz, "methodTest");
ReturnStmt returnStmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = returnStmt.getExpression().get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
use of com.github.javaparser.ast.expr.Expression in project javaparser by javaparser.
the class ConstraintFormulaTest method testExpressionCompatibleWithTypeReduce1.
/**
* From JLS 18.1.2
*
* From Collections.singleton("hi"), we have the constraint formula ‹"hi" → α›.
* Through reduction, this will become the constraint formula: ‹String <: α›.
*/
@Test
public void testExpressionCompatibleWithTypeReduce1() {
ResolvedTypeParameterDeclaration tp = mock(ResolvedTypeParameterDeclaration.class);
Expression e = new StringLiteralExpr("hi");
InferenceVariable inferenceVariable = new InferenceVariable("α", tp);
ExpressionCompatibleWithType formula = new ExpressionCompatibleWithType(typeSolver, e, inferenceVariable);
ConstraintFormula.ReductionResult res1 = formula.reduce(BoundSet.empty());
assertEquals(ConstraintFormula.ReductionResult.empty().withConstraint(new TypeCompatibleWithType(typeSolver, stringType, inferenceVariable)), res1);
assertEquals(ConstraintFormula.ReductionResult.empty().withConstraint(new TypeSubtypeOfType(typeSolver, stringType, inferenceVariable)), res1.getConstraint(0).reduce(BoundSet.empty()));
}
use of com.github.javaparser.ast.expr.Expression in project javaparser by javaparser.
the class SymbolResolutionResolutionTest method conditionalExpressionExample.
@Test
public void conditionalExpressionExample() {
CompilationUnit cu = parseSample("JreConditionalExpression");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo1");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
Expression expression = returnStmt.getExpression().get();
TypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class ASTCompilerVisitor method visit.
@Override
public DirectCompilerResult visit(UnaryTestNode n) {
DirectCompilerResult value = n.getValue().accept(this);
Expression expr = Expressions.unary(n.getOperator(), value.getExpression());
Expressions.NamedLambda namedLambda = Expressions.namedUnaryLambda(expr, n.getText());
DirectCompilerResult r = DirectCompilerResult.of(namedLambda.name(), BuiltInType.UNARY_TEST).withFD(value);
r.addFieldDeclaration(namedLambda.field());
return r;
}
Aggregations