本文整理汇总了Java中com.github.javaparser.ast.stmt.ExpressionStmt.getExpression方法的典型用法代码示例。如果您正苦于以下问题:Java ExpressionStmt.getExpression方法的具体用法?Java ExpressionStmt.getExpression怎么用?Java ExpressionStmt.getExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.stmt.ExpressionStmt
的用法示例。
在下文中一共展示了ExpressionStmt.getExpression方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeClone
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
protected static ExpressionStmt makeClone(ExpressionStmt n) {
ExpressionStmt myclone = new ExpressionStmt(n.getBeginLine(),
n.getBeginColumn(),
n.getEndLine(),
n.getEndColumn(),
n.getExpression());
// Clone class members inherited from Node
myclone.setParentNode(n.getParentNode());
myclone.setData(n.getData());
myclone.setComment(n.getComment());
// Orphan comments should be added one by one
for (final Comment c : n.getOrphanComments()) {
myclone.addOrphanComment(c);
}
return myclone;
}
示例2: accessClassFieldThroughThisWithCompetingSymbolInParentContext
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void accessClassFieldThroughThisWithCompetingSymbolInParentContext() throws ParseException {
CompilationUnit cu = parseSample("AccessClassMemberThroughThis");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessClassMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(clazz, "setLabel");
ExpressionStmt expressionStmt = (ExpressionStmt) method.getBody().get().getStatements().get(0);
AssignExpr assignExpr = (AssignExpr) expressionStmt.getExpression();
FieldAccessExpr fieldAccessExpr = (FieldAccessExpr) assignExpr.getTarget();
File src = adaptPath(new File("src/test/resources"));
CombinedTypeSolver typeSolver = new CombinedTypeSolver(new JavaParserTypeSolver(src), new ReflectionTypeSolver());
SymbolSolver symbolSolver = new SymbolSolver(typeSolver);
SymbolReference<? extends ResolvedValueDeclaration> ref = symbolSolver.solveSymbol(fieldAccessExpr.getField().getId(), fieldAccessExpr);
assertTrue(ref.isSolved());
assertTrue(ref.getCorrespondingDeclaration().isField());
}
示例3: resolveUsageOfGenericFieldAdvancedCase
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void resolveUsageOfGenericFieldAdvancedCase() throws ParseException {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo2");
ExpressionStmt stmt = (ExpressionStmt) method.getBody().get().getStatements().get(0);
Expression expression = stmt.getExpression();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals(false, type.isTypeVariable());
assertEquals("java.util.List<java.lang.String>", type.describe());
assertEquals(1, type.asReferenceType().typeParametersValues().size());
assertEquals(false, type.asReferenceType().typeParametersValues().get(0).isTypeVariable());
assertEquals("java.lang.String", type.asReferenceType().typeParametersValues().get(0).describe());
}
示例4: issue144
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test(expected = UnsolvedSymbolException.class)
public void issue144() throws ParseException {
CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld");
ExpressionStmt expressionStmt = (ExpressionStmt)clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
Expression firstParameter = methodCallExpr.getArgument(0);
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
javaParserFacade.solve(firstParameter).isSolved();
}
示例5: issue144WithReflectionTypeSolver
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void issue144WithReflectionTypeSolver() throws ParseException {
CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld");
ExpressionStmt expressionStmt = (ExpressionStmt)clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
Expression firstParameter = methodCallExpr.getArgument(0);
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver(true));
assertEquals(true, javaParserFacade.solve(firstParameter).isSolved());
}
示例6: issue144WithCombinedTypeSolver
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void issue144WithCombinedTypeSolver() throws ParseException {
CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld");
ExpressionStmt expressionStmt = (ExpressionStmt)clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
Expression firstParameter = methodCallExpr.getArgument(0);
JavaParserFacade javaParserFacade = JavaParserFacade.get(new CombinedTypeSolver(typeSolver, new ReflectionTypeSolver(true)));
assertEquals(true, javaParserFacade.solve(firstParameter).isSolved());
}
示例7: resolveDeclaredFieldReference
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void resolveDeclaredFieldReference() throws ParseException {
CompilationUnit cu = parseSample("ReferencesToField");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "ReferencesToField");
MethodDeclaration method1 = Navigator.demandMethod(referencesToField, "method1");
ExpressionStmt stmt = (ExpressionStmt) method1.getBody().get().getStatements().get(0);
AssignExpr assignExpr = (AssignExpr) stmt.getExpression();
SymbolSolver symbolSolver = new SymbolSolver(typeSolver);
SymbolReference symbolReference = symbolSolver.solveSymbol("i", assignExpr.getTarget());
assertEquals(true, symbolReference.isSolved());
assertEquals("i", symbolReference.getCorrespondingDeclaration().getName());
assertEquals(true, symbolReference.getCorrespondingDeclaration().isField());
}
示例8: resolveInheritedFieldReference
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void resolveInheritedFieldReference() throws ParseException {
CompilationUnit cu = parseSample("ReferencesToField");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "ReferencesToFieldExtendingClass");
MethodDeclaration method1 = Navigator.demandMethod(referencesToField, "method2");
ExpressionStmt stmt = (ExpressionStmt) method1.getBody().get().getStatements().get(0);
AssignExpr assignExpr = (AssignExpr) stmt.getExpression();
SymbolSolver symbolSolver = new SymbolSolver(typeSolver);
SymbolReference symbolReference = symbolSolver.solveSymbol("i", assignExpr.getTarget());
assertEquals(true, symbolReference.isSolved());
assertEquals("i", symbolReference.getCorrespondingDeclaration().getName());
assertEquals(true, symbolReference.getCorrespondingDeclaration().isField());
}
示例9: resolveUsageOfGenericFieldSimpleCase
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void resolveUsageOfGenericFieldSimpleCase() throws ParseException {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo1");
ExpressionStmt stmt = (ExpressionStmt) method.getBody().get().getStatements().get(0);
Expression expression = stmt.getExpression();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals(false, type.isTypeVariable());
assertEquals("java.lang.String", type.describe());
}
示例10: issue257
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void issue257() throws FileNotFoundException {
String pathToSourceFile = adaptPath("src/test/resources/issue257/A.java.txt");
CompilationUnit cu = JavaParser.parse(new File(pathToSourceFile));
Statement statement = cu.getClassByName("A").get().getMethodsByName("run").get(0).getBody().get().getStatement(0);
ExpressionStmt expressionStmt = (ExpressionStmt)statement;
Expression expression = expressionStmt.getExpression();
JavaParserFacade.get(typeSolver).getType(expression);
}
示例11: issue235
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void issue235() throws ParseException {
CompilationUnit cu = parseSample("Issue235");
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "Foo");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodDeclaration m = Navigator.demandMethod(cls, this.method);
ExpressionStmt stmt = (ExpressionStmt) m.getBody().get().getStatements().get(0);
ObjectCreationExpr expression = (ObjectCreationExpr) stmt.getExpression();
Assert.assertNotNull(javaParserFacade.convertToUsage(expression.getType()));
}
示例12: loopOnStaticallyImportedType
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void loopOnStaticallyImportedType() throws ParseException {
CompilationUnit cu = parseSampleWithStandardExtension("issue128/foo/Issue128");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
ExpressionStmt expressionStmt = (ExpressionStmt)clazz.getMethodsByName("test").get(0).getBody().get().getStatement(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
assertEquals(false, javaParserFacade.solve(methodCallExpr).isSolved());
}
示例13: testSolveStaticallyImportedMemberType
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入方法依赖的package包/类
@Test
public void testSolveStaticallyImportedMemberType() throws ParseException {
CompilationUnit cu = parseSample("Issue251");
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "Main");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodDeclaration m = Navigator.demandMethod(cls, "bar");
ExpressionStmt stmt = (ExpressionStmt) m.getBody().get().getStatements().get(1);
MethodCallExpr expression = (MethodCallExpr) stmt.getExpression();
Assert.assertNotNull(javaParserFacade.solve(expression));
}