本文整理汇总了Java中com.github.javaparser.ast.expr.VariableDeclarationExpr类的典型用法代码示例。如果您正苦于以下问题:Java VariableDeclarationExpr类的具体用法?Java VariableDeclarationExpr怎么用?Java VariableDeclarationExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VariableDeclarationExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了VariableDeclarationExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 void visit(final VariableDeclarationExpr n, final Object arg) {
printer.printLn("VariableDeclarationExpr");
printJavaComment(n.getComment(), arg);
printAnnotations(n.getAnnotations(), arg);
printModifiers(n.getModifiers());
n.getType().accept(this, arg);
printer.print(" ");
for (final Iterator<VariableDeclarator> i = n.getVars().iterator(); i.hasNext(); ) {
final VariableDeclarator v = i.next();
v.accept(this, arg);
if (i.hasNext()) {
printer.print(", ");
}
}
}
示例3: 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);
}
示例4: 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;
}
示例5: 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;
}
示例6: visit
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override public Boolean visit(final VariableDeclarationExpr n1, final Node arg) {
final VariableDeclarationExpr n2 = (VariableDeclarationExpr) arg;
if (!n1.getModifiers().equals(n2.getModifiers())) {
return false;
}
if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
return false;
}
if (!nodeEquals(n1.getElementType(), n2.getElementType())) {
return false;
}
if (!nodesEquals(n1.getVariables(), n2.getVariables())) {
return false;
}
if(!nodesEquals(n1.getArrayBracketPairsAfterElementType(), n2.getArrayBracketPairsAfterElementType())){
return false;
}
return true;
}
示例7: visit
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override
public Node visit(VariableDeclarationExpr _n, Object _arg) {
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
Type<?> type_ = cloneNodes(_n.getElementType(), _arg);
List<VariableDeclarator> vars = visit(_n.getVariables(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
List<ArrayBracketPair> arrayBracketPairsAfterType_ = visit(_n.getArrayBracketPairsAfterElementType(), _arg);
VariableDeclarationExpr r = new VariableDeclarationExpr(
_n.getRange(),
_n.getModifiers(),
annotations,
type_,
vars,
arrayBracketPairsAfterType_
);
r.setComment(comment);
return r;
}
示例8: visit
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override public void visit(final TryStmt n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getResources() != null) {
for (final VariableDeclarationExpr v : n.getResources()) {
v.accept(this, arg);
}
}
n.getTryBlock().accept(this, arg);
if (n.getCatchs() != null) {
for (final CatchClause c : n.getCatchs()) {
c.accept(this, arg);
}
}
if (n.getFinallyBlock() != null) {
n.getFinallyBlock().accept(this, arg);
}
}
示例9: visit
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override public Node visit(final TryStmt n, final A arg) {
visitComment(n, arg);
final List<VariableDeclarationExpr> types = n.getResources();
for (int i = 0; i < types.size(); i++) {
n.getResources().set(i,
(VariableDeclarationExpr) n.getResources().get(i).accept(this, arg));
}
n.setTryBlock((BlockStmt) n.getTryBlock().accept(this, arg));
final List<CatchClause> catchs = n.getCatchs();
if (catchs != null) {
for (int i = 0; i < catchs.size(); i++) {
catchs.set(i, (CatchClause) catchs.get(i).accept(this, arg));
}
removeNulls(catchs);
}
if (n.getFinallyBlock() != null) {
n.setFinallyBlock((BlockStmt) n.getFinallyBlock().accept(this, arg));
}
return n;
}
示例10: solveSymbolAsValue
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override
public Optional<Value> solveSymbolAsValue(String name, TypeSolver typeSolver) {
for (VariableDeclarationExpr expr : wrappedNode.getResources()) {
for (VariableDeclarator v : 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);
}
}
示例11: solveSymbol
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的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);
}
}
示例12: solveSymbol
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override
public SymbolReference<? extends ValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
for (Expression expression : wrappedNode.getInitialization()) {
if (expression instanceof VariableDeclarationExpr) {
VariableDeclarationExpr variableDeclarationExpr = (VariableDeclarationExpr) expression;
for (VariableDeclarator variableDeclarator : variableDeclarationExpr.getVariables()) {
if (variableDeclarator.getName().getId().equals(name)) {
return SymbolReference.solved(JavaParserSymbolDeclaration.localVar(variableDeclarator, typeSolver));
}
}
} else if (!(expression instanceof AssignExpr || expression instanceof MethodCallExpr)) {
throw new UnsupportedOperationException(expression.getClass().getCanonicalName());
}
}
if (getParentNode(wrappedNode) instanceof NodeWithStatements) {
return StatementContext.solveInBlock(name, typeSolver, wrappedNode);
} else {
return getParent().solveSymbol(name, typeSolver);
}
}
示例13: solveSymbolAsValue
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的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: solveSymbol
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的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);
}
}
示例15: solveSymbol
import com.github.javaparser.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override
public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
for (Expression expression : wrappedNode.getInitialization()) {
if (expression instanceof VariableDeclarationExpr) {
VariableDeclarationExpr variableDeclarationExpr = (VariableDeclarationExpr) expression;
for (VariableDeclarator variableDeclarator : variableDeclarationExpr.getVariables()) {
if (variableDeclarator.getName().getId().equals(name)) {
return SymbolReference.solved(JavaParserSymbolDeclaration.localVar(variableDeclarator, typeSolver));
}
}
} else if (!(expression instanceof AssignExpr || expression instanceof MethodCallExpr)) {
throw new UnsupportedOperationException(expression.getClass().getCanonicalName());
}
}
if (getParentNode(wrappedNode) instanceof NodeWithStatements) {
return StatementContext.solveInBlock(name, typeSolver, wrappedNode);
} else {
return getParent().solveSymbol(name, typeSolver);
}
}