本文整理汇总了Java中com.github.javaparser.ast.expr.VariableDeclarationExpr.getVars方法的典型用法代码示例。如果您正苦于以下问题:Java VariableDeclarationExpr.getVars方法的具体用法?Java VariableDeclarationExpr.getVars怎么用?Java VariableDeclarationExpr.getVars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.expr.VariableDeclarationExpr
的用法示例。
在下文中一共展示了VariableDeclarationExpr.getVars方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypesByVariableName
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入方法依赖的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.expr.VariableDeclarationExpr; //导入方法依赖的package包/类
@Override
public Node visit(final VariableDeclarationExpr n, Object arg) {
Vector<VariableDeclarationExpr> lexprlist = new Vector<VariableDeclarationExpr>();
for (final VariableDeclarator v : n.getVars()) {
// Clone old object
VariableDeclarationExpr lnewvar = ListVariableDeclarationExpr.makeClone(n);
// Get Type-Name (VariableDeclarator)
VariableDeclarator ltypename = (VariableDeclarator) v.accept(this, arg);
//lnewvar.setAsParentNodeOf( ltypename);
// Creates VariableDeclarationExpr (lnewvar) with a single declaration
Vector<VariableDeclarator> myunitvec = new Vector<VariableDeclarator>();
myunitvec.add(ltypename);
lnewvar.setVars(myunitvec);
lexprlist.add(lnewvar);
}
// Finally create list with variable expressions and return.
return new ListVariableDeclarationExpr(lexprlist);
}
示例3: makeClone
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入方法依赖的package包/类
protected static VariableDeclarationExpr makeClone(VariableDeclarationExpr n) {
VariableDeclarationExpr myclone = new VariableDeclarationExpr(n.getBeginLine(),
n.getBeginColumn(),
n.getEndLine(),
n.getEndColumn(),
n.getModifiers(),
n.getAnnotations(),
n.getType(),
n.getVars());
// 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;
}
示例4: visit
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入方法依赖的package包/类
@Override public Node visit(final VariableDeclarationExpr n, final A arg) {
final List<AnnotationExpr> annotations = n.getAnnotations();
if (annotations != null) {
for (int i = 0; i < annotations.size(); i++) {
annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
}
removeNulls(annotations);
}
n.setType((Type) n.getType().accept(this, arg));
final List<VariableDeclarator> vars = n.getVars();
for (int i = 0; i < vars.size(); i++) {
vars.set(i, (VariableDeclarator) vars.get(i).accept(this, arg));
}
removeNulls(vars);
return n;
}
示例5: visit
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入方法依赖的package包/类
@Override
public JCTree visit(final VariableDeclarationExpr n, final Object arg) {
//ARG0: JCModifiers mods
JCModifiers arg0 = new AJCModifiers(make.Modifiers(setJCTreeModifiers(n.getModifiers(), 0)), null);
//ARG1: Name name
Name arg1 = null;
//ARG2: JCExpression vartype
JCExpression arg2 = (JCExpression) n.getType().accept(this, arg);
//ARG3: JCExpression init
JCExpression arg3 = null;
/*
if (n.getAnnotations() != null) {
for (final AnnotationExpr a : n.getAnnotations()) {
JCTree result = a.accept(this, arg);
}
}
*/
// Multiple variable declarations per line are not supported.
// Currently only last declaration is preserved.
// We assume that ComplyJCVisitor has called before to unfold the multiple declarataions.
for (final VariableDeclarator v : n.getVars()) {
arg1 = names.fromString(v.getId().getName());
if (v.getInit() != null) {
arg3 = (JCExpression) v.getInit().accept(this, arg);
} else {
arg3 = null;
}
}
return new AJCVariableDecl(make.VarDef(arg0, arg1, arg2, arg3), ((n.getComment() != null) ? n.getComment().getContent() : null));
}