本文整理汇总了Java中com.github.javaparser.ast.body.VariableDeclarator类的典型用法代码示例。如果您正苦于以下问题:Java VariableDeclarator类的具体用法?Java VariableDeclarator怎么用?Java VariableDeclarator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VariableDeclarator类属于com.github.javaparser.ast.body包,在下文中一共展示了VariableDeclarator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypesByVariableName
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的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: changePropertyType
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的package包/类
public void changePropertyType(ClassOrInterfaceType newType) {
VariableDeclarator vd = getVariableDeclaration();
if(null != vd) {
vd.setType(newType);
}
MethodDeclaration getter = getGetter();
if(null != getter) {
getter.setType(newType);
}
MethodDeclaration setter = getSetter();
if(null != setter) {
setter.getParameter(0).setType(newType);
}
m_propertyType = newType;
}
示例3: parseFields
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的package包/类
private void parseFields(NodeList<ImportDeclaration> imports, List<FieldDeclaration> fields) {
fields.forEach(f -> {
// Map field type
String type = trimType(f.getElementType().asString());
int typeStart = toIndex(f.getElementType().getBegin().get());
String full = getQuantified(imports, type);
ClassMapping cm = jremap.getJarReader().getMapping().getMapping(full);
if (cm != null) {
fill(typeStart - 1, type, cm);
}
// Map field name
VariableDeclarator var = f.getVariable(0);
String name = var.getNameAsString();
String desc = getArr(f.getElementType()) + (full.length() == 1 ? full : "L" + full + ";");
int start = toIndex(var.getBegin().get()) - 1;
MemberMapping mm = jremap.getCurrentClass().getMemberMappingWithRenaming(name, desc);
if (mm != null) {
fill(start, name, mm);
}
});
}
示例4: visit
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的package包/类
@Override
public void visit(FieldDeclaration n, FieldInfos fieldInfos) {
for (final VariableDeclarator variable : n.getVariables()) {
Type type = n.getType();
if (ModifierSet.isPublic(n.getModifiers())) {
FieldInfo fieldInfo = new FieldInfo(type, variable, n.getComment(), fieldInfos.typeMap);
/*System.out.println("Type: " + type+ "Type1: " + type.getClass().getName());
System.out.println("Vars: "+ variable);
System.out.println("Jdoc: " +n.getComment());
System.out.println(fieldInfo);
System.out.println("");*/
fieldInfos.addField(fieldInfo);
}
}
//super.visit(n, arg);
}
示例5: visit
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的package包/类
@Override
public void visit(final FieldDeclaration n, final Object arg) {
printer.printLn("FieldDeclaration");
printOrphanCommentsBeforeThisChildNode(n);
printJavaComment(n.getComment(), arg);
printJavadoc(n.getJavaDoc(), arg);
printMemberAnnotations(n.getAnnotations(), arg);
printModifiers(n.getModifiers());
n.getType().accept(this, arg);
printer.print(" ");
for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext(); ) {
final VariableDeclarator var = i.next();
var.accept(this, arg);
if (i.hasNext()) {
printer.print(", ");
}
}
printer.print(";");
}
示例6: visit
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的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);
}
示例7: visit
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的package包/类
@Override
public void visit(ClassOrInterfaceDeclaration clazz, Object arg) {
for (BodyDeclaration member : clazz.getMembers()) {
if (member instanceof ClassOrInterfaceDeclaration)
visit((ClassOrInterfaceDeclaration)member, arg);
else if (member instanceof FieldDeclaration) {
FieldDeclaration field = (FieldDeclaration)member;
String type = null != field.getType() ? field.getType().toString() : "";
if (type.equals("int")) {
VariableDeclarator variable = field.getVariables().stream().findFirst().get();
String name = variable.getId().toString();
Integer value = null != variable.getInit() ? Integer.parseInt(variable.getInit().toString()) : 0;
// decimal value of 0x7f000000, which is what AAPT starts numbering at - http://stackoverflow.com/a/6646113/311304
if (value >= 2130706432) {
name = "R." + ((ClassOrInterfaceDeclaration)field.getParentNode()).getName() + "." + name;
transform.put(value, name);
}
}
}
}
}
示例8: visit
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的package包/类
@Override public void visit(final FieldDeclaration n, final Object arg) {
printOrphanCommentsBeforeThisChildNode(n);
printJavaComment(n.getComment(), arg);
printJavadoc(n.getJavaDoc(), arg);
printMemberAnnotations(n.getAnnotations(), arg);
printModifiers(n.getModifiers());
n.getType().accept(this, arg);
printer.print(" ");
for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext();) {
final VariableDeclarator var = i.next();
var.accept(this, arg);
if (i.hasNext()) {
printer.print(", ");
}
}
printer.print(";");
}
示例9: solveSymbol
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的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);
}
}
}
示例10: solveSymbol
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的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);
}
}
示例11: visit
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的package包/类
@Override public Node visit(final FieldDeclaration n, final A arg) {
if (n.getJavaDoc() != null) {
n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, 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> variables = n.getVariables();
for (int i = 0; i < variables.size(); i++) {
variables.set(i, (VariableDeclarator) variables.get(i).accept(this, arg));
}
removeNulls(variables);
return n;
}
示例12: visit
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的package包/类
@Override public void visit(final VariableDeclarationExpr n, final Object arg) {
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(", ");
}
}
}
示例13: solve
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的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;
}
}
}
}
示例14: solveSymbol
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的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: solveParameterOfLambdaInFieldDecl
import com.github.javaparser.ast.body.VariableDeclarator; //导入依赖的package包/类
@Test
public void solveParameterOfLambdaInFieldDecl() throws ParseException {
CompilationUnit cu = parseSample("Lambda");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
VariableDeclarator field = Navigator.demandField(clazz, "functional");
LambdaExpr lambdaExpr = (LambdaExpr) field.getInitializer().get();
File src = new File("src/test/resources");
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath(src)));
Context context = new LambdaExprContext(lambdaExpr, combinedTypeSolver);
Optional<Value> ref = context.solveSymbolAsValue("p", typeSolver);
assertTrue(ref.isPresent());
assertEquals("java.lang.String", ref.get().getType().describe());
}