本文整理汇总了Java中com.github.javaparser.ast.stmt.BlockStmt类的典型用法代码示例。如果您正苦于以下问题:Java BlockStmt类的具体用法?Java BlockStmt怎么用?Java BlockStmt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlockStmt类属于com.github.javaparser.ast.stmt包,在下文中一共展示了BlockStmt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setterDeclaration
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的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;
}
示例2: visit
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的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("}");
}
示例3: visit
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的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;
}
示例4: solveSymbol
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
@Override
public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
if (wrappedNode.getVariable().getVariables().size() != 1) {
throw new IllegalStateException();
}
VariableDeclarator variableDeclarator = wrappedNode.getVariable().getVariables().get(0);
if (variableDeclarator.getName().getId().equals(name)) {
return SymbolReference.solved(JavaParserSymbolDeclaration.localVar(variableDeclarator, typeSolver));
} else {
if (getParentNode(wrappedNode) instanceof BlockStmt) {
return StatementContext.solveInBlock(name, typeSolver, wrappedNode);
} else {
return getParent().solveSymbol(name, typeSolver);
}
}
}
示例5: visit
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的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.BlockStmt; //导入依赖的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: solveSymbol
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
@Override
public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
for (Expression expr : wrappedNode.getResources()) {
if (expr instanceof VariableDeclarationExpr) {
for (VariableDeclarator v : ((VariableDeclarationExpr)expr).getVariables()) {
if (v.getName().getIdentifier().equals(name)) {
return SymbolReference.solved(JavaParserSymbolDeclaration.localVar(v, typeSolver));
}
}
}
}
if (getParentNode(wrappedNode) instanceof BlockStmt) {
return StatementContext.solveInBlock(name, typeSolver, wrappedNode);
} else {
return getParent().solveSymbol(name, typeSolver);
}
}
示例8: getNameMethod
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
/**
* Creates the Name method
*/
private MethodDeclaration getNameMethod() {
MethodDeclaration getName = new MethodDeclaration(
ModifierSet.PUBLIC,
Collections.singletonList(OVERRIDE_ANNOTATION),
null,
createReferenceType("String", 0),
"getName",
null, 0,
null,
null
);
BlockStmt methodBody = new BlockStmt(
Collections.singletonList(new ReturnStmt(
new StringLiteralExpr("CV " + definedMethod.getMethodName())))
);
getName.setBody(methodBody);
return getName;
}
示例9: getDescriptionMethod
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
/**
* Creates the description method
*/
private MethodDeclaration getDescriptionMethod() {
MethodDeclaration getDescription = new MethodDeclaration(
ModifierSet.PUBLIC,
Collections.singletonList(OVERRIDE_ANNOTATION),
null,
createReferenceType("String", 0),
"getDescription",
null, 0,
null,
null
);
BlockStmt methodBody = new BlockStmt(
Collections.singletonList(new ReturnStmt(
new StringLiteralExpr(this.definedMethod.getDescription())))
);
getDescription.setBody(methodBody);
return getDescription;
}
示例10: getPerformMethod
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
private MethodDeclaration getPerformMethod() {
String inputParamId = "inputs";
String outputParamId = "outputs";
return new MethodDeclaration(
ModifierSet.PUBLIC,
Arrays.asList(OVERRIDE_ANNOTATION),
null,
new VoidType(),
"perform",
Arrays.asList(
new Parameter(SocketHintDeclarationCollection.getSocketReturnParam("InputSocket"),
new VariableDeclaratorId(inputParamId)),
new Parameter(SocketHintDeclarationCollection.getSocketReturnParam("OutputSocket"),
new VariableDeclaratorId(outputParamId))
),
0,
null,
new BlockStmt(
getPerformExpressionList(inputParamId, outputParamId)
)
);
}
示例11: createSetter
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
/**
* Create a setter for this field, <b>will only work if this field declares only 1 identifier and if this field is
* already added to a ClassOrInterfaceDeclaration</b>
*
* @return the {@link MethodDeclaration} created
* @throws IllegalStateException if there is more than 1 variable identifier or if this field isn't attached to a
* class or enum
*/
public MethodDeclaration createSetter() {
if (getVariables().size() != 1)
throw new IllegalStateException("You can use this only when the field declares only 1 variable name");
ClassOrInterfaceDeclaration parentClass = getParentNodeOfType(ClassOrInterfaceDeclaration.class);
EnumDeclaration parentEnum = getParentNodeOfType(EnumDeclaration.class);
if ((parentClass == null && parentEnum == null) || (parentClass != null && parentClass.isInterface()))
throw new IllegalStateException(
"You can use this only when the field is attached to a class or an enum");
VariableDeclarator variable = getVariables().get(0);
String fieldName = variable.getId().getName();
String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length());
final MethodDeclaration setter;
if (parentClass != null)
setter = parentClass.addMethod("set" + fieldNameUpper, PUBLIC);
else
setter = parentEnum.addMethod("set" + fieldNameUpper, PUBLIC);
setter.setType(VOID_TYPE);
setter.getParameters().add(new Parameter(variable.getType(), new VariableDeclaratorId(fieldName)));
BlockStmt blockStmt2 = new BlockStmt();
setter.setBody(blockStmt2);
blockStmt2.addStatement(new AssignExpr(new NameExpr("this." + fieldName), new NameExpr(fieldName), Operator.assign));
return setter;
}
示例12: MethodDeclaration
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
public MethodDeclaration(final EnumSet<Modifier> modifiers,
final List<AnnotationExpr> annotations,
final List<TypeParameter> typeParameters,
final Type elementType,
final List<ArrayBracketPair> arrayBracketPairsAfterElementType,
final String name,
final List<Parameter> parameters,
final List<ArrayBracketPair> arrayBracketPairsAfterParameterList,
final List<ReferenceType> throws_,
final BlockStmt body) {
super(annotations);
setModifiers(modifiers);
setTypeParameters(typeParameters);
setElementType(elementType);
setName(name);
setParameters(parameters);
setArrayBracketPairsAfterElementType(arrayBracketPairsAfterElementType);
setArrayBracketPairsAfterParameterList(arrayBracketPairsAfterParameterList);
setThrows(throws_);
setBody(body);
}
示例13: solveSymbolAsValue
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
@Override
public Optional<Value> solveSymbolAsValue(String name, TypeSolver typeSolver) {
for (Expression expr : wrappedNode.getResources()) {
if (expr instanceof VariableDeclarationExpr) {
for (VariableDeclarator v : ((VariableDeclarationExpr)expr).getVariables()) {
if (v.getName().getIdentifier().equals(name)) {
JavaParserSymbolDeclaration decl = JavaParserSymbolDeclaration.localVar(v, typeSolver);
return Optional.of(Value.from(decl));
}
}
}
}
if (getParentNode(wrappedNode) instanceof BlockStmt) {
return StatementContext.solveInBlockAsValue(name, typeSolver, wrappedNode);
} else {
return getParent().solveSymbolAsValue(name, typeSolver);
}
}
示例14: visit
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
@Override
public Node visit(ConstructorDeclaration _n, Object _arg) {
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg);
List<Parameter> parameters = visit(_n.getParameters(), _arg);
List<ReferenceType> throws_ = visit(_n.getThrows(), _arg);
BlockStmt block = cloneNodes(_n.getBody(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
ConstructorDeclaration r = new ConstructorDeclaration(
_n.getRange(),
_n.getModifiers(), annotations, typeParameters, _n.getName(), parameters, throws_, block
);
r.setComment(comment);
return r;
}
示例15: solveSymbol
import com.github.javaparser.ast.stmt.BlockStmt; //导入依赖的package包/类
@Override
public SymbolReference<? extends ValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
for (VariableDeclarationExpr expr : wrappedNode.getResources()) {
for (VariableDeclarator v : expr.getVariables()) {
if (v.getName().getIdentifier().equals(name)) {
return SymbolReference.solved(JavaParserSymbolDeclaration.localVar(v, typeSolver));
}
}
}
if (getParentNode(wrappedNode) instanceof BlockStmt) {
return StatementContext.solveInBlock(name, typeSolver, wrappedNode);
} else {
return getParent().solveSymbol(name, typeSolver);
}
}