本文整理汇总了Java中com.github.javaparser.ast.stmt.Statement类的典型用法代码示例。如果您正苦于以下问题:Java Statement类的具体用法?Java Statement怎么用?Java Statement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Statement类属于com.github.javaparser.ast.stmt包,在下文中一共展示了Statement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypesByVariableName
import com.github.javaparser.ast.stmt.Statement; //导入依赖的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;
}
示例2: visit
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
@Override public Node visit(final IfStmt n, final A arg) {
visitComment(n, arg);
final Expression condition = (Expression)
n.getCondition().accept(this, arg);
if (condition == null) {
return null;
}
n.setCondition(condition);
final Statement thenStmt = (Statement) n.getThenStmt().accept(this, arg);
if (thenStmt == null) {
// Remove the entire statement if the then-clause was removed.
// DumpVisitor, used for toString, has no null check for the
// then-clause.
return null;
}
n.setThenStmt(thenStmt);
if (n.getElseStmt() != null) {
n.setElseStmt((Statement) n.getElseStmt().accept(this, arg));
}
return n;
}
示例3: visit
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
@Override
public void visit(final BlockStmt n, final Object arg) {
printer.printLn("BlockStmt");
printOrphanCommentsBeforeThisChildNode(n);
printJavaComment(n.getComment(), arg);
printer.printLn("{");
if (n.getStmts() != null) {
printer.indent();
for (final Statement s : n.getStmts()) {
s.accept(this, arg);
printer.printLn();
}
printer.unindent();
}
printer.print("}");
}
示例4: visit
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
@Override
public Node visit(final BlockStmt n, final Object arg) {
if (n.getStmts() != null) {
Vector<Statement> lnewlist = new Vector<Statement>();
for (final Statement s : n.getStmts()) {
Statement mystmt = (Statement) s.accept(this, arg);
// Append the expanded list to list of Statements
if (mystmt instanceof ListExpressionStmt) {
lnewlist.addAll(((ListExpressionStmt) mystmt).getVarStmts());
} else {
lnewlist.add(mystmt);
}
}
n.setStmts(lnewlist);
}
return n;
}
示例5: visit
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
@Override
public JCTree visit(final BlockStmt n, final Object arg) {
// ARG0: long flags
// It is logically endend with Flags.STATIC is static init
long arg0 = 0;
// ARG1: List<JCStatement> stats
List<JCStatement> arg1 = List.<JCStatement>nil();
if (n.getStmts() != null) {
for (final Statement s : n.getStmts()) {
arg1 = arg1.append((JCStatement) s.accept(this, arg));
}
}
return new AJCBlock(make.Block(arg0, arg1), ((n.getComment() != null) ? n.getComment().getContent() : null));
}
示例6: visit
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
@Override public void visit(final BlockStmt n, final Object arg) {
printOrphanCommentsBeforeThisChildNode(n);
printJavaComment(n.getComment(), arg);
printer.printLn("{");
if (n.getStmts() != null) {
printer.indent();
for (final Statement s : n.getStmts()) {
s.accept(this, arg);
printer.printLn();
}
printer.unindent();
}
printOrphanCommentsEnding(n);
printer.print("}");
}
示例7: visit
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
@Override public Node visit(final ForStmt n, final A arg) {
final List<Expression> init = n.getInit();
if (init != null) {
for (int i = 0; i < init.size(); i++) {
init.set(i, (Expression) init.get(i).accept(this, arg));
}
removeNulls(init);
}
if (n.getCompare() != null) {
n.setCompare((Expression) n.getCompare().accept(this, arg));
}
final List<Expression> update = n.getUpdate();
if (update != null) {
for (int i = 0; i < update.size(); i++) {
update.set(i, (Expression) update.get(i).accept(this, arg));
}
removeNulls(update);
}
n.setBody((Statement) n.getBody().accept(this, arg));
return n;
}
示例8: solve
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
private void solve(Node node) {
if (node instanceof ClassOrInterfaceDeclaration) {
solveTypeDecl((ClassOrInterfaceDeclaration) node);
} else if (node instanceof Expression) {
if ((getParentNode(node) instanceof ImportDeclaration) || (getParentNode(node) instanceof Expression)
|| (getParentNode(node) instanceof MethodDeclaration)
|| (getParentNode(node) instanceof PackageDeclaration)) {
// skip
} else if ((getParentNode(node) instanceof Statement) || (getParentNode(node) instanceof VariableDeclarator)) {
try {
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(node);
out.println(" Line " + node.getRange().get().begin.line + ") " + node + " ==> " + ref.describe());
ok++;
} catch (UnsupportedOperationException upe) {
unsupported++;
err.println(upe.getMessage());
throw upe;
} catch (RuntimeException re) {
ko++;
err.println(re.getMessage());
throw re;
}
}
}
}
示例9: solveInBlockAsValue
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
public static Optional<Value> solveInBlockAsValue(String name, TypeSolver typeSolver, Statement stmt) {
if (!(getParentNode(stmt) instanceof NodeWithStatements)) {
throw new IllegalArgumentException();
}
NodeWithStatements<?> blockStmt = (NodeWithStatements<?>) getParentNode(stmt);
int position = -1;
for (int i = 0; i < blockStmt.getStatements().size(); i++) {
if (blockStmt.getStatements().get(i).equals(stmt)) {
position = i;
}
}
if (position == -1) {
throw new RuntimeException();
}
for (int i = position - 1; i >= 0; i--) {
SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(blockStmt.getStatements().get(i), typeSolver);
SymbolReference<? extends ResolvedValueDeclaration> symbolReference = solveWith(symbolDeclarator, name);
if (symbolReference.isSolved()) {
return Optional.of(Value.from(symbolReference.getCorrespondingDeclaration()));
}
}
// if nothing is found we should ask the parent context
return JavaParserFactory.getContext(getParentNode(stmt), typeSolver).solveSymbolAsValue(name, typeSolver);
}
示例10: solveInBlock
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
public static SymbolReference<? extends ValueDeclaration> solveInBlock(String name, TypeSolver typeSolver, Statement stmt) {
if (!(getParentNode(stmt) instanceof NodeWithStatements)) {
throw new IllegalArgumentException();
}
NodeWithStatements<?> blockStmt = (NodeWithStatements<?>) getParentNode(stmt);
int position = -1;
for (int i = 0; i < blockStmt.getStatements().size(); i++) {
if (blockStmt.getStatements().get(i).equals(stmt)) {
position = i;
}
}
if (position == -1) {
throw new RuntimeException();
}
for (int i = position - 1; i >= 0; i--) {
SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(blockStmt.getStatements().get(i), typeSolver);
SymbolReference<? extends ValueDeclaration> symbolReference = solveWith(symbolDeclarator, name);
if (symbolReference.isSolved()) {
return symbolReference;
}
}
// if nothing is found we should ask the parent context
return JavaParserFactory.getContext(getParentNode(stmt), typeSolver).solveSymbol(name, typeSolver);
}
示例11: solveInBlockAsValue
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
public static Optional<Value> solveInBlockAsValue(String name, TypeSolver typeSolver, Statement stmt) {
if (!(getParentNode(stmt) instanceof NodeWithStatements)) {
throw new IllegalArgumentException();
}
NodeWithStatements<?> blockStmt = (NodeWithStatements<?>) getParentNode(stmt);
int position = -1;
for (int i = 0; i < blockStmt.getStatements().size(); i++) {
if (blockStmt.getStatements().get(i).equals(stmt)) {
position = i;
}
}
if (position == -1) {
throw new RuntimeException();
}
for (int i = position - 1; i >= 0; i--) {
SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(blockStmt.getStatements().get(i), typeSolver);
SymbolReference<? extends ValueDeclaration> symbolReference = solveWith(symbolDeclarator, name);
if (symbolReference.isSolved()) {
return Optional.of(Value.from(symbolReference.getCorrespondingDeclaration()));
}
}
// if nothing is found we should ask the parent context
return JavaParserFactory.getContext(getParentNode(stmt), typeSolver).solveSymbolAsValue(name, typeSolver);
}
示例12: solve
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
private void solve(Node node) {
if (node instanceof ClassOrInterfaceDeclaration) {
solveTypeDecl((ClassOrInterfaceDeclaration) node);
} else if (node instanceof Expression) {
if ((getParentNode(node) instanceof ImportDeclaration) || (getParentNode(node) instanceof Expression)
|| (getParentNode(node) instanceof MethodDeclaration)
|| (getParentNode(node) instanceof PackageDeclaration)) {
// skip
} else if ((getParentNode(node) instanceof Statement) || (getParentNode(node) instanceof VariableDeclarator)) {
try {
Type ref = JavaParserFacade.get(typeSolver).getType(node);
out.println(" Line " + node.getRange().get().begin.line + ") " + node + " ==> " + ref.describe());
ok++;
} catch (UnsupportedOperationException upe) {
unsupported++;
err.println(upe.getMessage());
throw upe;
} catch (RuntimeException re) {
ko++;
err.println(re.getMessage());
throw re;
}
}
}
}
示例13: visit
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
@Override public void visit(final BlockStmt n, final Object arg) {
printOrphanCommentsBeforeThisChildNode(n);
printJavaComment(n.getComment(), arg);
printer.printLn("{");
if (n.getStmts() != null) {
printer.indent();
for (final Statement s : n.getStmts()) {
s.accept(this, arg);
printer.printLn();
}
printer.unindent();
}
printOrphanCommentsEnding(n);
printer.print("}");
}
示例14: solveInBlock
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
public static SymbolReference<? extends ResolvedValueDeclaration> solveInBlock(String name, TypeSolver typeSolver, Statement stmt) {
if (!(getParentNode(stmt) instanceof NodeWithStatements)) {
throw new IllegalArgumentException();
}
NodeWithStatements<?> blockStmt = (NodeWithStatements<?>) getParentNode(stmt);
int position = -1;
for (int i = 0; i < blockStmt.getStatements().size(); i++) {
if (blockStmt.getStatements().get(i).equals(stmt)) {
position = i;
}
}
if (position == -1) {
throw new RuntimeException();
}
for (int i = position - 1; i >= 0; i--) {
SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(blockStmt.getStatements().get(i), typeSolver);
SymbolReference<? extends ResolvedValueDeclaration> symbolReference = solveWith(symbolDeclarator, name);
if (symbolReference.isSolved()) {
return symbolReference;
}
}
// if nothing is found we should ask the parent context
return JavaParserFactory.getContext(getParentNode(stmt), typeSolver).solveSymbol(name, typeSolver);
}
示例15: visit
import com.github.javaparser.ast.stmt.Statement; //导入依赖的package包/类
@Override
public void visit(final SwitchEntryStmt n, final Void arg) {
printJavaComment(n.getComment(), arg);
if (n.getLabel().isPresent()) {
printer.print("case ");
n.getLabel().get().accept(this, arg);
printer.print(":");
} else {
printer.print("default:");
}
if (n.getStatements() != null
&& n.getStatements().size() == 1
&& n.getStatements().get(0) instanceof BlockStmt) {
printer.print(" ");
n.getStatements().get(0).accept(this, arg);
printer.println();
} else {
printer.println();
if (n.getStatements() != null) {
printer.indent();
for (final Statement s : n.getStatements()) {
s.accept(this, arg);
printer.println();
}
printer.unindent();
}
}
}