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


Java VariableDeclarationStatement.fragments方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: findClassInstanceCreationInDeclaration

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private ClassInstanceCreation findClassInstanceCreationInDeclaration(SimpleName collectionName,
        VariableDeclarationStatement statement) throws EnumParsingException {
    List<VariableDeclarationFragment> fragments = statement.fragments();
    for (VariableDeclarationFragment fragment : fragments) {
        if (areNamesEqual(collectionName, fragment.getName())) {
            Expression initializer = fragment.getInitializer();
            if (initializer instanceof ClassInstanceCreation) {
                return (ClassInstanceCreation) initializer;
            } else {
                throw new EnumParsingException();
            }
        }
    }
    throw new EnumParsingException();
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:17,代码来源:UseEnumCollectionsResolution.java

示例5: 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

示例6: visit

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
@Override
public boolean visit(VariableDeclarationStatement node) {
	List fragments = node.fragments();
	VariableDeclarationFragment varDec = (VariableDeclarationFragment) fragments.get(0);
	System.out.println(varDec.getName().getIdentifier() + "  " + node.getParent());
	return super.visit(node);
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:8,代码来源:ArrayParser.java

示例7: splitUpDeclarations

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
private void splitUpDeclarations(ASTRewrite rewrite, TextEditGroup group, VariableDeclarationFragment frag, VariableDeclarationStatement originalStatement, List<Expression> sideEffects) {
	if (sideEffects.size() > 0) {
		ListRewrite statementRewrite= rewrite.getListRewrite(originalStatement.getParent(), (ChildListPropertyDescriptor) originalStatement.getLocationInParent());

		Statement previousStatement= originalStatement;
		for (int i= 0; i < sideEffects.size(); i++) {
			Expression sideEffect= sideEffects.get(i);
			Expression movedInit= (Expression) rewrite.createMoveTarget(sideEffect);
			ExpressionStatement wrapped= rewrite.getAST().newExpressionStatement(movedInit);
			statementRewrite.insertAfter(wrapped, previousStatement, group);
			previousStatement= wrapped;
		}

		VariableDeclarationStatement newDeclaration= null;
		List<VariableDeclarationFragment> fragments= originalStatement.fragments();
		int fragIndex= fragments.indexOf(frag);
		ListIterator<VariableDeclarationFragment> fragmentIterator= fragments.listIterator(fragIndex+1);
		while (fragmentIterator.hasNext()) {
			VariableDeclarationFragment currentFragment= fragmentIterator.next();
			VariableDeclarationFragment movedFragment= (VariableDeclarationFragment) rewrite.createMoveTarget(currentFragment);
			if (newDeclaration == null) {
				newDeclaration= rewrite.getAST().newVariableDeclarationStatement(movedFragment);
				Type copiedType= (Type) rewrite.createCopyTarget(originalStatement.getType());
				newDeclaration.setType(copiedType);
			} else {
				newDeclaration.fragments().add(movedFragment);
			}
		}
		if (newDeclaration != null){
			statementRewrite.insertAfter(newDeclaration, previousStatement, group);
			if (originalStatement.fragments().size() == newDeclaration.fragments().size() + 1){
				rewrite.remove(originalStatement, group);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:37,代码来源:UnusedCodeFix.java

示例8: addLocalDeclarationRemoval

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
private void addLocalDeclarationRemoval(ASTRewrite rewrite) {
  VariableDeclarationStatement tempDeclarationStatement = getTempDeclarationStatement();
  List<VariableDeclarationFragment> fragments = tempDeclarationStatement.fragments();

  int fragmentIndex = fragments.indexOf(fTempDeclarationNode);
  Assert.isTrue(fragmentIndex != -1);
  VariableDeclarationFragment fragment = fragments.get(fragmentIndex);
  rewrite.remove(fragment, null);
  if (fragments.size() == 1) rewrite.remove(tempDeclarationStatement, null);
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:PromoteTempToFieldRefactoring.java

示例9: visit

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
@Override
public boolean visit(final VariableDeclarationStatement node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment vdf = (VariableDeclarationFragment) fragment;
		final IdentifierInformation vd = new IdentifierInformation(SHA,
				file, vdf.getName().getIdentifier(), node.getType()
						.toString(), getLineNumber(vdf),
				getAstParentString(vdf));
		identifiers.add(vd);
	}
	return super.visit(node);
}
 
开发者ID:mast-group,项目名称:naturalize,代码行数:13,代码来源:IdentifierInformationScanner.java

示例10: visit

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
@Override
public boolean visit(final VariableDeclarationStatement node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
开发者ID:mast-group,项目名称:tassal,代码行数:12,代码来源:VariableScopeExtractor.java

示例11: visit

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
/**
 * Looks for local variable declarations. For every declaration of a
 * variable, the parent {@link Block} denoting the variable's scope is
 * stored in {@link #variableScope} map.
 *
 * @param node
 *            the node to visit
 */
@Override
public boolean visit(final VariableDeclarationStatement node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		addBinding(node, frag.getName().getIdentifier());
	}
	return true;
}
 
开发者ID:mast-group,项目名称:tassal,代码行数:17,代码来源:JavaApproximateVariableBindingExtractor.java

示例12: addLocalDeclarationRemoval

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
private void addLocalDeclarationRemoval(ASTRewrite rewrite) {
VariableDeclarationStatement tempDeclarationStatement= getTempDeclarationStatement();
  	List<VariableDeclarationFragment> fragments= tempDeclarationStatement.fragments();

  	int fragmentIndex= fragments.indexOf(fTempDeclarationNode);
  	Assert.isTrue(fragmentIndex != -1);
      VariableDeclarationFragment fragment= fragments.get(fragmentIndex);
      rewrite.remove(fragment, null);
      if (fragments.size() == 1)
	rewrite.remove(tempDeclarationStatement, null);
  }
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:12,代码来源:PromoteTempToFieldRefactoring.java

示例13: splitUpDeclarations

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
private void splitUpDeclarations(ASTRewrite rewrite, TextEditGroup group, VariableDeclarationFragment frag, VariableDeclarationStatement originalStatement, List<Expression> sideEffects) {
	if (sideEffects.size() > 0) {
		ListRewrite statementRewrite= rewrite.getListRewrite(originalStatement.getParent(), (ChildListPropertyDescriptor) originalStatement.getLocationInParent());
		
		Statement previousStatement= originalStatement;
		for (int i= 0; i < sideEffects.size(); i++) {
			Expression sideEffect= sideEffects.get(i);
			Expression movedInit= (Expression) rewrite.createMoveTarget(sideEffect);
			ExpressionStatement wrapped= rewrite.getAST().newExpressionStatement(movedInit);
			statementRewrite.insertAfter(wrapped, previousStatement, group);
			previousStatement= wrapped;
		}

		VariableDeclarationStatement newDeclaration= null;
		List<VariableDeclarationFragment> fragments= originalStatement.fragments();
		int fragIndex= fragments.indexOf(frag);
		ListIterator<VariableDeclarationFragment> fragmentIterator= fragments.listIterator(fragIndex+1);
		while (fragmentIterator.hasNext()) {
			VariableDeclarationFragment currentFragment= fragmentIterator.next();
			VariableDeclarationFragment movedFragment= (VariableDeclarationFragment) rewrite.createMoveTarget(currentFragment);
			if (newDeclaration == null) {
				newDeclaration= rewrite.getAST().newVariableDeclarationStatement(movedFragment);
				Type copiedType= (Type) rewrite.createCopyTarget(originalStatement.getType());
				newDeclaration.setType(copiedType);
			} else {
				newDeclaration.fragments().add(movedFragment);
			}
		}
		if (newDeclaration != null){
			statementRewrite.insertAfter(newDeclaration, previousStatement, group);
			if (originalStatement.fragments().size() == newDeclaration.fragments().size() + 1){
				rewrite.remove(originalStatement, group);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:37,代码来源:UnusedCodeFix.java

示例14: splitVariableDeclarationStatement

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
/**
 * Split the fragments in <code>statement</code> to multiple VariableDeclarationStatements whenever
 * <code>splitOperator.needsSplit</code> returns <code>true</code>.
 * i.e.:
 * int i, j; ---> int i; int j; (if splitOperator.needsSplit(i, j) == true)
 *
 * @param statement The VariableDeclarationStatement to split
 * @param splitOperator The operator to use to split
 * @param rewrite The rewriter to use to generate new VariableDeclarationStatements.
 */
private void splitVariableDeclarationStatement(VariableDeclarationStatement statement, ISplitOperation splitOperator, ASTRewrite rewrite) {

	List<VariableDeclarationFragment> fragments= statement.fragments();
	Iterator<VariableDeclarationFragment> iter= fragments.iterator();
	VariableDeclarationFragment lastFragment= iter.next();
	VariableDeclarationStatement lastStatement= statement;

	splitOperator.initializeStatement(lastStatement, lastFragment);

	ListRewrite fragmentsRewrite= null;
	while (iter.hasNext()) {
		VariableDeclarationFragment currentFragment= iter.next();

		if (splitOperator.needsSplit(lastFragment, currentFragment)) {

			VariableDeclarationStatement newStatement= getAst().newVariableDeclarationStatement((VariableDeclarationFragment)rewrite.createMoveTarget(currentFragment));

			ListRewrite modifierRewrite= rewrite.getListRewrite(newStatement, VariableDeclarationStatement.MODIFIERS2_PROPERTY);
			for (Iterator<IExtendedModifier> iterator= statement.modifiers().iterator(); iterator.hasNext();) {
				modifierRewrite.insertLast(rewrite.createCopyTarget((ASTNode)iterator.next()), null);
			}

			newStatement.setType((Type)rewrite.createCopyTarget(statement.getType()));

			splitOperator.initializeStatement(newStatement, currentFragment);

			fragmentsRewrite= rewrite.getListRewrite(newStatement, VariableDeclarationStatement.FRAGMENTS_PROPERTY);

			lastStatement= newStatement;
		} else if (fragmentsRewrite != null) {
			ASTNode fragment0= rewrite.createMoveTarget(currentFragment);
			fragmentsRewrite.insertLast(fragment0, null);
		}
		lastFragment= currentFragment;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:47,代码来源:SurroundWith.java

示例15: splitUpDeclarations

import org.eclipse.jdt.core.dom.VariableDeclarationStatement; //导入方法依赖的package包/类
private void splitUpDeclarations(ASTRewrite rewrite, TextEditGroup group, VariableDeclarationFragment frag, ListRewrite statementRewrite, VariableDeclarationStatement originalStatement) {
	Expression initializer = frag.getInitializer();
	//keep constructors and method invocations
	if (initializer instanceof MethodInvocation || initializer instanceof ClassInstanceCreation){
		Expression movedInitializer= (Expression) rewrite.createMoveTarget(initializer);

		ExpressionStatement newInitializer= rewrite.getAST().newExpressionStatement( movedInitializer);
		statementRewrite.insertAfter(newInitializer, originalStatement, group);

		VariableDeclarationStatement newDeclaration= null;
		List<VariableDeclarationFragment> fragments= originalStatement.fragments();
		int fragIndex= fragments.indexOf(frag);
		ListIterator<VariableDeclarationFragment> fragmentIterator= fragments.listIterator(fragIndex+1);
		while (fragmentIterator.hasNext()) {
			VariableDeclarationFragment currentFragment= fragmentIterator.next();
			VariableDeclarationFragment movedFragment= (VariableDeclarationFragment) rewrite.createMoveTarget(currentFragment);
			if (newDeclaration == null) {
				newDeclaration= rewrite.getAST().newVariableDeclarationStatement(movedFragment);
				Type copiedType= (Type) rewrite.createCopyTarget(originalStatement.getType());
				newDeclaration.setType(copiedType);
			} else
				newDeclaration.fragments().add(movedFragment);
		}
		if (newDeclaration != null){
			statementRewrite.insertAfter(newDeclaration, newInitializer, group);
		}
		if (originalStatement.fragments().size() == newDeclaration.fragments().size() + 1){
			rewrite.remove(originalStatement, group);
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:32,代码来源:UnusedCodeFix.java


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