本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
}
示例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);
}
}
}