当前位置: 首页>>代码示例>>Java>>正文


Java VariableDeclarator.getInit方法代码示例

本文整理汇总了Java中com.github.javaparser.ast.body.VariableDeclarator.getInit方法的典型用法代码示例。如果您正苦于以下问题:Java VariableDeclarator.getInit方法的具体用法?Java VariableDeclarator.getInit怎么用?Java VariableDeclarator.getInit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.javaparser.ast.body.VariableDeclarator的用法示例。


在下文中一共展示了VariableDeclarator.getInit方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
                }
            }
        }
    }
}
 
开发者ID:justingarrick,项目名称:android-reverse-r,代码行数:22,代码来源:Reverser.java

示例2: visit

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
@Override
public void visit(final VariableDeclarator n, final Object arg) {
    printer.printLn("VariableDeclarator");
    printJavaComment(n.getComment(), arg);
    n.getId().accept(this, arg);
    if (n.getInit() != null) {
        printer.print(" = ");
        n.getInit().accept(this, arg);
    }
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:11,代码来源:ASTDumpVisitor.java

示例3: visit

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的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));
  }
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:37,代码来源:JavaParser2JCTree.java

示例4: visit

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
@Override public void visit(final VariableDeclarator n, final Object arg) {
printJavaComment(n.getComment(), arg);
n.getId().accept(this, arg);
if (n.getInit() != null) {
    printer.print(" = ");
    n.getInit().accept(this, arg);
}
   }
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:9,代码来源:DumpVisitor.java

示例5: visit

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
@Override public void visit(final VariableDeclarator n, final A arg) {
	visitComment(n.getComment(), arg);
	n.getId().accept(this, arg);
	if (n.getInit() != null) {
		n.getInit().accept(this, arg);
	}
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:8,代码来源:VoidVisitorAdapter.java

示例6: visit

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
@Override public void visit(final VariableDeclarator n, final A arg) {
    jw.write(n); 
    visitComment(n.getComment(), arg);
    n.getId().accept(this, arg);
    if (n.getInit() != null) {
        n.getInit().accept(this, arg);
    }
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:9,代码来源:JsonVisitorAdapter.java

示例7: visit

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
@Override public Node visit(final VariableDeclarator n, final A arg) {
	n.setId((VariableDeclaratorId) n.getId().accept(this, arg));
	if (n.getInit() != null) {
		n.setInit((Expression) n.getInit().accept(this, arg));
	}
	return n;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:8,代码来源:ModifierVisitorAdapter.java

示例8: visit

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
@Override public Node visit(final VariableDeclarator n, final A arg) {
	visitComment(n, arg);
	final VariableDeclaratorId id = (VariableDeclaratorId)
		n.getId().accept(this, arg);
	if (id == null) {
		return null;
	}
	n.setId(id);
	if (n.getInit() != null) {
		n.setInit((Expression) n.getInit().accept(this, arg));
	}
	return n;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:14,代码来源:ModifierVisitorAdapter.java

示例9: visit

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
@Override public void visit(final VariableDeclarator n, final Object arg) {
	printJavaComment(n.getComment(), arg);
	n.getId().accept(this, arg);
	if (n.getInit() != null) {
		printer.print(" = ");
		n.getInit().accept(this, arg);
	}
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:9,代码来源:DumpVisitor.java

示例10: parseExpr

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
private void parseExpr(Expression expr){
    if(expr instanceof NameExpr){
        // Most likely a variable name
    	String name = ((NameExpr)expr).getName();
        if (name != null){
        	// null occurs often when it involves methodCalls
        	Node parent = expr.getParentNode();
        	if(!(parent instanceof MethodCallExpr) && !(parent instanceof FieldAccessExpr)){
        		// methodCall like getPerson().getName() would also have getName and getPerson as name expressions
        		// So do fieldAccess expressions like System.out.println
        		incrementDictCount(this.variables, ((NameExpr)expr).getName());
        	}          	
        }            	
    } else if(expr instanceof VariableDeclarationExpr){        	
        int modifiers = ((VariableDeclarationExpr) expr).getModifiers();
        if (modifiers == 16){
        	this.concepts.add("FinalVariables");
        }
    	VariableDeclarationExpr varDecExpr = (VariableDeclarationExpr) expr;
        String leftType = varDecExpr.getType().toString();
        for(Node child : varDecExpr.getChildrenNodes()){
        	if (child instanceof VariableDeclarator){
        		VariableDeclarator varDeclerator = (VariableDeclarator) child;
        		if (varDeclerator.getInit() instanceof ObjectCreationExpr){
        			ObjectCreationExpr creationExpr = (ObjectCreationExpr) varDeclerator.getInit();
            		if(!creationExpr.getType().toString().equals(leftType)){
            			// Left Type is not equal to right, Polymorphism in action
            			this.concepts.add("PolyMorphism");
            			incrementDictCount(this.types, creationExpr.getType().getName());
            		}
        		} else if (varDeclerator.getInit() instanceof CastExpr){
        			this.concepts.add("Casting");
        			this.concepts.add("PolyMorphism");
        		}
        	}
        }
        incrementDictCount(this.types, varDecExpr.getType().toString());
    } else if(expr instanceof LiteralExpr){
        // These are primarily integer and string constants
        String stringExpr = ((LiteralExpr) expr).toString().trim();
        if (!stringExpr.startsWith("//")){
        	incrementDictCount(this.constants, stringExpr);
    	}            
    }
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:46,代码来源:ASTEnhanced.java

示例11: getLambdaExprInStatementInMethodInClass

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
private LambdaExpr getLambdaExprInStatementInMethodInClass(int statementPosition, int methodPosition, int classPosition) {
    Statement statement = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
    VariableDeclarator variableDeclarator = (VariableDeclarator)statement.getChildrenNodes().get(0).getChildrenNodes().get(1);
    return (LambdaExpr) variableDeclarator.getInit();
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:6,代码来源:ParsingSteps.java

示例12: parseVariable

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
public static VariableInfo parseVariable(SourceInfo sourceInfo, FieldDeclaration variableDecl) {
        VariableInfo result = new VariableInfo();
        
        VariableDeclarator variableDeclarator = variableDecl.getVariables().get(0);
        
        String name = variableDeclarator.getId().getName();
        String type = variableDecl.getType().toString();
        
        result.setVariableName(name);
        
        if (variableDecl.getModifiers() != 0) {
            result.addAllModifiers(Modifier.parseModifiersFromFlags(variableDecl.getModifiers()));
        }
        
//        Log.d(TAG, "vartype class name: %s", variableDecl.getType().getClass().getSimpleName());
        
        Object value = null;
        if (result.isContainedModifier(Modifier.FINAL) && variableDeclarator.getInit() != null) {
//            Log.d(TAG, "varinit class name: %s", variableDeclarator.getInit().getClass().getSimpleName());
            value = VariableInitParser.parseVariableInit(sourceInfo, variableDeclarator.getInit());   
        }

        Type variableType = TypeParser.parseType(sourceInfo, variableDecl.getType(), type);
        Log.d(TAG, "variableType: %s", variableType);
        result.setType(variableType);
        
        if (value != null) {
            result.setVariableValue(value);
        }
        
        if (variableDecl.getAnnotations() != null && variableDecl.getAnnotations().size() > 0) {
            List<AnnotationExpr> annotationList = variableDecl.getAnnotations();
            for (AnnotationExpr annotation : annotationList) {
                AnnotationModifier annotationModifier = AnnotationModifierParser.parseAnnotation(sourceInfo, annotation);
                if (annotationModifier != null) {
                    result.putAnnotation(annotationModifier);
                }
            }
        }
        
        Log.d(TAG, "parseVariable, name: %s, type: %s, value: %s", name, type, value);
        
        return result;
    }
 
开发者ID:ragnraok,项目名称:JParserUtil,代码行数:45,代码来源:VariableParser.java

示例13: doMerge

import com.github.javaparser.ast.body.VariableDeclarator; //导入方法依赖的package包/类
@Override public VariableDeclarator doMerge(VariableDeclarator first, VariableDeclarator second) {

        if(first.getInit() == second.getInit()) return first;

        VariableDeclarator vd = new VariableDeclarator();

        vd.setId(first.getId());
        vd.setInit(mergeSingle(first.getInit(),second.getInit()));

        return vd;
    }
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:12,代码来源:VariableDeclaratorMerger.java


注:本文中的com.github.javaparser.ast.body.VariableDeclarator.getInit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。