本文整理汇总了Java中com.github.javaparser.ast.stmt.ExpressionStmt类的典型用法代码示例。如果您正苦于以下问题:Java ExpressionStmt类的具体用法?Java ExpressionStmt怎么用?Java ExpressionStmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionStmt类属于com.github.javaparser.ast.stmt包,在下文中一共展示了ExpressionStmt类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getTypesByVariableName
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
Map<String, Class<?>> getTypesByVariableName( List<Statement> statements ) {
Map<String, Class<?>> typeByVariableName = new HashMap<>();
for (Statement statement : statements) {
if ( statement instanceof ExpressionStmt ) {
Expression expression = ( ( ExpressionStmt ) statement ).getExpression();
if ( expression instanceof VariableDeclarationExpr ) {
VariableDeclarationExpr varExpression = ( VariableDeclarationExpr ) expression;
@Nullable Class<?> type = typeOf( varExpression.getType() );
if ( type != null ) {
for (VariableDeclarator var : varExpression.getVars()) {
typeByVariableName.put( var.getId().getName(), type );
}
}
}
}
}
return typeByVariableName;
}
开发者ID:renatoathaydes,项目名称:osgiaas,代码行数:23,代码来源:TypeDiscoverer.java
示例2: setterDeclaration
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
private MethodDeclaration setterDeclaration(EntityField field) {
MethodDeclaration decl = new MethodDeclaration(ModifierSet.PUBLIC,
new VoidType(),
"set" + CaseConverter.pascalCase(field.getName()),
Collections.singletonList(new Parameter(
ASTHelper.createReferenceType(field.getType().getSimpleName(), 0),
new VariableDeclaratorId(field.getName()))));
BlockStmt body = new BlockStmt();
body.setStmts(
Collections.singletonList(
new ExpressionStmt(
new AssignExpr(
new FieldAccessExpr(new ThisExpr(), field.getName()),
ASTHelper.createNameExpr(field.getName()),
AssignExpr.Operator.assign
))));
decl.setBody(body);
return decl;
}
开发者ID:kawasima,项目名称:enkan,代码行数:21,代码来源:FormTask.java
示例3: visit
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
@Override
public Node visit(final ExpressionStmt n, Object arg) {
// VariableDeclarationExpr contains a list of variable declaration
// Unfolding it to several elements
Node myresult = n.getExpression().accept(this, arg);
// Checking if type is the expected one. Should be careful here.
if (myresult instanceof ListVariableDeclarationExpr) {
Vector<ExpressionStmt> mydecllist = new Vector<ExpressionStmt>();
for (final VariableDeclarationExpr newexpr : ((ListVariableDeclarationExpr) myresult).getVarExprs()) {
// Build an ExpressionStmt with same metadata as n
ExpressionStmt mynewstmt = ListExpressionStmt.makeClone(n);
// Set the unfolded variable declaration expression
mynewstmt.setExpression(newexpr);
mydecllist.add(mynewstmt);
}
return new ListExpressionStmt(mydecllist);
} else {
n.setExpression((Expression) myresult);
return n;
}
}
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:27,代码来源:ComplyToJCVisitor.java
示例4: 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;
}
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:18,代码来源:ComplyToJCVisitor.java
示例5: getDefaultValue
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
@Override
public Expression getDefaultValue(String defaultValue) {
if (!this.defaultValues.isEmpty()) {
LambdaExpr provider = new LambdaExpr();
provider.setBody(
new ExpressionStmt(
new ObjectCreationExpr(null, type, defaultValues)
)
);
provider.setParametersEnclosed(true);
return provider;
} else {
MethodReferenceExpr referenceExpr = new MethodReferenceExpr();
referenceExpr.setScope(new NameExpr(type.getName()));
referenceExpr.setIdentifier("new");
return referenceExpr;
}
}
开发者ID:WPIRoboticsProjects,项目名称:GRIP,代码行数:19,代码来源:ObjectDefaultValue.java
示例6: 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());
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:18,代码来源:FieldsResolutionTest.java
示例7: 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());
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:18,代码来源:GenericsResolutionTest.java
示例8: appearsInAssignmentContext
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
private static boolean appearsInAssignmentContext(Expression expression) {
if (expression.getParentNode().isPresent()) {
Node parent = expression.getParentNode().get();
if (parent instanceof ExpressionStmt) {
return false;
}
if (parent instanceof MethodCallExpr) {
return false;
}
if (parent instanceof ReturnStmt) {
return false;
}
throw new UnsupportedOperationException(parent.getClass().getCanonicalName());
}
return false;
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:ExpressionHelper.java
示例9: visit
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
@Override
public void visit(final ExpressionStmt n, final Object arg) {
printer.printLn("ExpressionStmt");
printOrphanCommentsBeforeThisChildNode(n);
printJavaComment(n.getComment(), arg);
n.getExpression().accept(this, arg);
printer.print(";");
}
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:9,代码来源:ASTDumpVisitor.java
示例10: visit
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
@Override
public JCTree visit(final ExpressionStmt n, final Object arg) {
//ARG0: JCExpression expr
JCExpression arg0;
JCTree mystmt = n.getExpression().accept(this, arg);
// Adding commment if
// 1 - There's actualy a comment to add
// 2 - The variable doesn't have a comment yet
// 3 - It is a variable declaration
if ((n.getComment() != null) &&
(mystmt instanceof AJCVariableDecl) &&
(!((AJCVariableDecl) mystmt).hasComment())) {
((AJCVariableDecl) mystmt).setComment(n.getComment().getContent());
}
// Case where the expression is already a subclass of JCStatement, such as JCVariableDecl
if (mystmt instanceof JCStatement) {
return mystmt;
}
arg0 = (JCExpression) mystmt;
return new AJCExpressionStatement(make.Exec(arg0), ((n.getComment() != null) ? n.getComment().getContent() : null));
}
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:28,代码来源:JavaParser2JCTree.java
示例11: visit
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
@Override
public R visit(final ExpressionStmt n, final A arg) {
{
R result = n.getExpression().accept(this, arg);
if (result != null) {
return result;
}
}
return null;
}
开发者ID:plum-umd,项目名称:java-sketch,代码行数:11,代码来源:GenericVisitorAdapter.java
示例12: visit
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
@Override public Boolean visit(final ExpressionStmt n1, final Node arg) {
final ExpressionStmt n2 = (ExpressionStmt) arg;
if (!nodeEquals(n1.getExpression(), n2.getExpression())) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
开发者ID:plum-umd,项目名称:java-sketch,代码行数:10,代码来源:EqualsVisitor.java
示例13: visit
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
@Override
public void visit(LambdaExpr n, Object arg) {
printJavaComment(n.getComment(), arg);
List<Parameter> parameters = n.getParameters();
boolean printPar = false;
printPar = n.isParametersEnclosed();
if (printPar) {
printer.print("(");
}
if (parameters != null) {
for (Iterator<Parameter> i = parameters.iterator(); i.hasNext();) {
Parameter p = i.next();
p.accept(this, arg);
if (i.hasNext()) {
printer.print(", ");
}
}
}
if (printPar) {
printer.print(")");
}
printer.print(" -> ");
Statement body = n.getBody();
if (body instanceof ExpressionStmt) {
// Print the expression directly
((ExpressionStmt) body).getExpression().accept(this, arg);
} else {
body.accept(this, arg);
}
}
开发者ID:plum-umd,项目名称:java-sketch,代码行数:34,代码来源:DumpVisitor.java
示例14: getClassDeclaration
import com.github.javaparser.ast.stmt.ExpressionStmt; //导入依赖的package包/类
private ClassOrInterfaceDeclaration getClassDeclaration() {
final ClassOrInterfaceType eventBusType = new ClassOrInterfaceType("EventBus");
final ClassOrInterfaceType eventType = new ClassOrInterfaceType("OperationAddedEvent");
// This method is how the generated code tells the rest of the application about all of the
// generated OpenCV
// operations. It sends an OperationAddedEvent with a new instance of every operation.
final MethodDeclaration addOperations = new MethodDeclaration(ModifierSet.PUBLIC |
ModifierSet.STATIC,
new VoidType(), "addOperations");
ASTHelper.addParameter(addOperations, ASTHelper.createParameter(eventBusType, "eventBus"));
addOperations.setBody(new BlockStmt(this.operations.stream()
.sorted((o1, o2) -> o1.getOperationClassName().toLowerCase().compareToIgnoreCase(o2
.getOperationClassName()))
.map(Operation::getOperationClassName)
.map(ClassOrInterfaceType::new)
// Create a new instance of each operation
.map(type -> new ObjectCreationExpr(null, type, null))
// Create a new OperationAddedEvent for every operation
.map(expr -> new ObjectCreationExpr(null, eventType, Collections.singletonList(expr)))
// Post all of the events to the event bus
.map(expr -> new MethodCallExpr(new NameExpr("eventBus"), "post", Collections
.singletonList(expr)))
.map(ExpressionStmt::new)
.collect(Collectors.toList())));
final ClassOrInterfaceDeclaration cvoperations = new ClassOrInterfaceDeclaration(ModifierSet
.PUBLIC, false,
"CVOperations");
cvoperations.setMembers(Collections.singletonList(addOperations));
return cvoperations;
}
开发者ID:WPIRoboticsProjects,项目名称:GRIP,代码行数:35,代码来源:OperationList.java
示例15: 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();
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:12,代码来源:Issue144.java
示例16: 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());
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:12,代码来源:Issue144.java
示例17: 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());
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:12,代码来源:Issue144.java
示例18: 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());
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:16,代码来源:ContextTest.java
示例19: 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());
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:16,代码来源:ContextTest.java
示例20: 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());
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:15,代码来源:GenericsResolutionTest.java
注:本文中的com.github.javaparser.ast.stmt.ExpressionStmt类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论