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


Java VariableDeclarationStatement类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.VariableDeclarationStatement的典型用法代码示例。如果您正苦于以下问题:Java VariableDeclarationStatement类的具体用法?Java VariableDeclarationStatement怎么用?Java VariableDeclarationStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


VariableDeclarationStatement类属于org.eclipse.jdt.core.dom包,在下文中一共展示了VariableDeclarationStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDeclaration

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
private VariableDeclarationStatement createDeclaration(
    IVariableBinding binding, Expression intilizer) {
  VariableDeclaration original =
      ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
  VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment();
  fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName()));
  fragment.setInitializer(intilizer);
  VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment);
  result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
  result.setType(
      ASTNodeFactory.newType(
          fAST,
          original,
          fImportRewriter,
          new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:ExtractMethodRefactoring.java

示例2: createUnobservedInitStmt

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
@SuppressWarnings("unchecked")
	@Override
	public void createUnobservedInitStmt(CaptureLog log, int logRecNo) 
	{
		PostProcessor.notifyRecentlyProcessedLogRecNo(logRecNo);
		
		// NOTE: PLAIN INIT: has always one non-null param
		// TODO: use primitives
		final int    oid     = log.objectIds.get(logRecNo);
//		final String type    = log.oidClassNames.get(log.oidRecMapping.get(oid));
		final Object value   = log.params.get(logRecNo)[0];
		this.isXStreamNeeded = true;
		
		final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
		// handling because there must always be a new instantiation statement for pseudo inits
		this.oidToVarMapping.remove(oid);
		vd.setName(ast.newSimpleName(this.createNewVarName(oid, log.oidClassNames.get(log.oidRecMapping.get(oid)), true)));
		
		final MethodInvocation methodInvocation = ast.newMethodInvocation();
		final Name name = ast.newSimpleName("XSTREAM");
		methodInvocation.setExpression(name);
		methodInvocation.setName(ast.newSimpleName("fromXML")); 
		
		final StringLiteral xmlParam = ast.newStringLiteral();
		xmlParam.setLiteralValue((String) value);
		methodInvocation.arguments().add(xmlParam);
		
//		final CastExpression castExpr = ast.newCastExpression();
//		castExpr.setType(this.createAstType(type, ast));
//		castExpr.setExpression(methodInvocation);
		
//		vd.setInitializer(castExpr);
		vd.setInitializer(methodInvocation);
		
		final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
		vs.setType(this.createAstType("Object", ast));
				
		methodBlock.statements().add(vs);
	}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:40,代码来源:JUnitCodeGenerator.java

示例3: createUnobservedInitStmt

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void createUnobservedInitStmt(final int logRecNo, final Block methodBlock, final AST ast)
{
	// NOTE: PLAIN INIT: has always one non-null param
	// TODO: use primitives
	final int    oid     = this.log.objectIds.get(logRecNo);
	final String type    = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
	final Object value   = this.log.params.get(logRecNo)[0];
	this.isXStreamNeeded = true;
	
	final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
	// handling because there must always be a new instantiation statement for pseudo inits
	this.oidToVarMapping.remove(oid);
	vd.setName(ast.newSimpleName(this.createNewVarName(oid, type)));
	
	final MethodInvocation methodInvocation = ast.newMethodInvocation();
	final Name name = ast.newSimpleName("XSTREAM");
	methodInvocation.setExpression(name);
	methodInvocation.setName(ast.newSimpleName("fromXML")); 
	
	final StringLiteral xmlParam = ast.newStringLiteral();
	xmlParam.setLiteralValue((String) value);
	methodInvocation.arguments().add(xmlParam);
	
	final CastExpression castExpr = ast.newCastExpression();
	castExpr.setType(this.createAstType(type, ast));
	castExpr.setExpression(methodInvocation);
	
	vd.setInitializer(castExpr);
	
	final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
	vs.setType(this.createAstType(type, ast));
			
	methodBlock.statements().add(vs);
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:36,代码来源:CodeGenerator.java

示例4: variableDeclarationStatement

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
public VariableDeclarationStatement variableDeclarationStatement(String name, Type type, Expression initializer) {
    VariableDeclarationFragment variableDeclarationFragment = variableDeclarationFragment(name);
    variableDeclarationFragment.setInitializer(initializer);
    VariableDeclarationStatement statement = ast.get().newVariableDeclarationStatement(variableDeclarationFragment);
    statement.setType(type);
    return statement;
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:8,代码来源:ASTNodeFactory.java

示例5: visit

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
public boolean visit(VariableDeclarationStatement vds) {
	if (mtbStack.isEmpty()) // not part of a method
		return true;

	// make local variable declaration
	for (Object ovdf : vds.fragments()) {
		VariableDeclarationFragment vdf = (VariableDeclarationFragment) ovdf;
		try {
			facts.add(Fact.makeLocalVarFact(getQualifiedName(mtbStack
					.peek()), getQualifiedName(vds.getType()
					.resolveBinding()), vdf.getName().getIdentifier(), vdf
					.getInitializer().toString()));
		} catch (Exception e) {
			System.err.println("Cannot resolve variable declaration \""
					+ vdf.getName().toString() + "\"");
		}
	}
	return true;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:20,代码来源:ASTVisitorAtomicChange.java

示例6: createDeclaration

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
private VariableDeclarationStatement createDeclaration(IVariableBinding binding, Expression intilizer) {
	VariableDeclaration original = ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
	VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment();
	fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName()));
	fragment.setInitializer(intilizer);
	VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment);
	result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
	result.setType(ASTNodeFactory.newType(fAST, original, fImportRewriter, new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
	return result;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:ExtractMethodRefactoring.java

示例7: visit

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
@Override
      public boolean visit(VariableDeclarationFragment param) {

	ASTNode parent = param.getParent();
	if (parent instanceof VariableDeclarationStatement) {
		VariableDeclarationStatement statement = (VariableDeclarationStatement) parent;

		ASTNode annotation = getAnnotation(statement.modifiers(), "Domain");
		if (annotation != null) {
			ListRewrite paramRewrite = rewrite.getListRewrite(statement,
			        VariableDeclarationStatement.MODIFIERS2_PROPERTY);
			paramRewrite.remove(annotation, null);
		}
	}
	return super.visit(param);
}
 
开发者ID:aroog,项目名称:code,代码行数:17,代码来源:RemoveAnnotations.java

示例8: visit

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
public boolean visit(VariableDeclarationStatement vds)
{
  if (this.mtbStack.isEmpty()) {
    return true;
  }
  for (Object ovdf : vds.fragments())
  {
    VariableDeclarationFragment vdf = (VariableDeclarationFragment)ovdf;
    try
    {
      this.facts.add(Fact.makeLocalVarFact(getQualifiedName(
        (IMethodBinding)this.mtbStack.peek()), getQualifiedName(vds.getType()
        .resolveBinding()), vdf.getName().getIdentifier(), vdf
        .getInitializer().toString()));
    }
    catch (Exception e)
    {
      System.err.println("Cannot resolve variable declaration \"" + 
        vdf.getName().toString() + "\"");
    }
  }
  return true;
}
 
开发者ID:SEAL-UCLA,项目名称:Ref-Finder,代码行数:24,代码来源:ASTVisitorAtomicChange.java

示例9: visit

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
public boolean visit(VariableDeclarationStatement vds)
{
  if (this.mtbStack.isEmpty()) {
    return true;
  }
  for (Object ovdf : vds.fragments())
  {
    VariableDeclarationFragment vdf = (VariableDeclarationFragment)ovdf;
    try
    {
      this.facts.add(Fact.makeLocalVarFact(getQualifiedName(
        (IMethodBinding)this.mtbStack.peek()), getQualifiedName(vds.getType()
        .resolveBinding()), vdf.getName().getIdentifier(), vdf
        .getInitializer().toString()));
    }
    catch (Exception localException)
    {
      System.err.println("Cannot resolve variable declaration \"" + 
        vdf.getName().toString() + "\"");
    }
  }
  return true;
}
 
开发者ID:SEAL-UCLA,项目名称:Ref-Finder,代码行数:24,代码来源:ASTVisitorAtomicChange.java

示例10: createNewFieldDeclaration

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
private FieldDeclaration createNewFieldDeclaration(ASTRewrite rewrite) {
  AST ast = getAST();
  VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
  SimpleName variableName = ast.newSimpleName(fFieldName);
  fragment.setName(variableName);
  addLinkedName(rewrite, variableName, false);
  List<Dimension> extraDimensions =
      DimensionRewrite.copyDimensions(fTempDeclarationNode.extraDimensions(), rewrite);
  fragment.extraDimensions().addAll(extraDimensions);
  if (fInitializeIn == INITIALIZE_IN_FIELD && tempHasInitializer()) {
    Expression initializer = (Expression) rewrite.createCopyTarget(getTempInitializer());
    fragment.setInitializer(initializer);
  }
  FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment);

  VariableDeclarationStatement vds = getTempDeclarationStatement();
  Type type = (Type) rewrite.createCopyTarget(vds.getType());
  fieldDeclaration.setType(type);
  fieldDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiers()));
  return fieldDeclaration;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:PromoteTempToFieldRefactoring.java

示例11: createTempDeclaration

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
private VariableDeclarationStatement createTempDeclaration(Expression initializer)
    throws CoreException {
  AST ast = fCURewrite.getAST();

  VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
  vdf.setName(ast.newSimpleName(fTempName));
  vdf.setInitializer(initializer);

  VariableDeclarationStatement vds = ast.newVariableDeclarationStatement(vdf);
  if (fDeclareFinal) {
    vds.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
  }
  vds.setType(createTempType());

  if (fLinkedProposalModel != null) {
    ASTRewrite rewrite = fCURewrite.getASTRewrite();
    LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
    nameGroup.addPosition(rewrite.track(vdf.getName()), true);

    String[] nameSuggestions = guessTempNames();
    if (nameSuggestions.length > 0 && !nameSuggestions[0].equals(fTempName)) {
      nameGroup.addProposal(fTempName, null, nameSuggestions.length + 1);
    }
    for (int i = 0; i < nameSuggestions.length; i++) {
      nameGroup.addProposal(nameSuggestions[i], null, nameSuggestions.length - i);
    }
  }
  return vds;
}
 
开发者ID:eclipse,项目名称:che,代码行数:30,代码来源:ExtractTempRefactoring.java

示例12: createCollectionInitStmt

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void createCollectionInitStmt(final CaptureLog log, final int logRecNo) 
{
	final int      oid          = log.objectIds.get(logRecNo);
	final Object[] params       = log.params.get(logRecNo);
	String         collTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
	final Class<?> collType     = getClassForName(collTypeName);

	final String varName;
	
	// -- determine if an alternative collection must be used for code generation
	final boolean isPrivate = java.lang.reflect.Modifier.isPrivate(collType.getModifiers());
	if(isPrivate || ! hasDefaultConstructor(collType))
	{
		if(Set.class.isAssignableFrom(collType))
		{
			collTypeName = HashSet.class.getName();
		}
		else if (List.class.isAssignableFrom(collType))
		{
			collTypeName = ArrayList.class.getName();
		}
		else if(Queue.class.isAssignableFrom(collType))
		{
			collTypeName = ArrayDeque.class.getName();
		}
		else
		{
			throw new RuntimeException("Collection " + collType + " is not supported");
		}
	}

	// -- create code for instantiating collection
	varName = this.createNewVarName(oid, collTypeName);
	
	final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
	final SimpleName varNameExpr = ast.newSimpleName(varName); 
	vd.setName(varNameExpr);	
	
	final ClassInstanceCreation ci = ast.newClassInstanceCreation();
	    ci.setType(this.createAstType(collTypeName, ast));
	    vd.setInitializer(ci);
	
	final VariableDeclarationStatement stmt = ast.newVariableDeclarationStatement(vd);
	stmt.setType(this.createAstType(collTypeName, ast));
	
	methodBlock.statements().add(stmt);	

	// --- create code for filling the collection
	Integer paramOID;
	MethodInvocation mi;
	for(int i = 0; i < params.length; i++)
	{
		mi = ast.newMethodInvocation();
		mi.setName(ast.newSimpleName("add"));
		
		paramOID = (Integer) params[i];
		if(paramOID == null)
		{
			mi.arguments().add(ast.newNullLiteral());
		}
		else
		{
			mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(paramOID)));
		}
		
		methodBlock.statements().add(mi);	
	}
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:71,代码来源:JUnitCodeGenerator.java

示例13: createMapInitStmt

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
@Override
public void createMapInitStmt(final CaptureLog log, final int logRecNo) {
	final int      oid          = log.objectIds.get(logRecNo);
	final Object[] params       = log.params.get(logRecNo);
	String         collTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
	final Class<?> collType     = getClassForName(collTypeName);


	final String varName;
	
	// -- determine if an alternative collection must be used for code generation
	final boolean isPrivate = java.lang.reflect.Modifier.isPrivate(collType.getModifiers());
	if(isPrivate || ! hasDefaultConstructor(collType))
	{
		collTypeName = HashMap.class.getName();
	}

	// -- create code for instantiating collection
	varName = this.createNewVarName(oid, collTypeName);
	
	final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
	final SimpleName varNameExpr = ast.newSimpleName(varName); 
	vd.setName(varNameExpr);	
	
	final ClassInstanceCreation ci = ast.newClassInstanceCreation();
	    ci.setType(this.createAstType(collTypeName, ast));
	    vd.setInitializer(ci);
	
	final VariableDeclarationStatement stmt = ast.newVariableDeclarationStatement(vd);
	stmt.setType(this.createAstType(collTypeName, ast));
	
	methodBlock.statements().add(stmt);	

	// --- create code for filling the collection
	Integer valueOID;
	Integer keyOID;
	
	MethodInvocation mi;
	for(int i = 0; i + 1< params.length; i+=2)
	{
		mi = ast.newMethodInvocation();
		mi.setName(ast.newSimpleName("put"));
		
		keyOID = (Integer) params[i];
	    mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(keyOID)));
		
		valueOID = (Integer) params[i + 1];
		if(valueOID == null)
		{
			mi.arguments().add(ast.newNullLiteral());
		}
		else
		{
			mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(valueOID)));
		}
		
		methodBlock.statements().add(mi);	
	}
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:60,代码来源:JUnitCodeGenerator.java

示例14: findUnnecessaryStore

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
private void findUnnecessaryStore(ReturnStatement node) {
    Block block = TraversalUtil.findClosestAncestor(node, Block.class);
    @SuppressWarnings("unchecked")
    List<Statement> blockStatements = block.statements();
    for (int i = 1; i < blockStatements.size(); i++) {
        Statement statement = blockStatements.get(i);
        if (statement == this.originalReturn) {
            for (int j = i - 1; j >= 0; j--) {
                Statement storeStatement = blockStatements.get(j);
                if (storeStatement instanceof VariableDeclarationStatement) {
                    splitStatementAndInitializer((VariableDeclarationStatement) storeStatement);
                    return;
                } else if (storeStatement instanceof ExpressionStatement) {
                    if (splitStatementAndInitializer((ExpressionStatement) storeStatement)) {
                        // we found our extra storage statement
                        return;
                    }
                }
            }
        }
    }
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:23,代码来源:UnnecessaryStoreResolution.java

示例15: visit

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入依赖的package包/类
@Override
public boolean visit(VariableDeclarationStatement node) {
	List fragments = node.fragments();
	for(Object o : fragments) {
		VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
		String varName = frag.getName().getIdentifier();
		int line = cunit.getLineNumber(frag.getStartPosition());
		Scope scope = new Scope(line, getEndLine(node.getParent(), cunit));
		VariableTags tags = new VariableTags(varName, null, line, scope, false);
		variables.add(tags);
	}
	return super.visit(node);
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:14,代码来源:TagParser.java


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