use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project processing by processing.
the class CompletionGenerator method checkForTypes.
public static CompletionCandidate[] checkForTypes(ASTNode node) {
List<VariableDeclarationFragment> vdfs = null;
switch(node.getNodeType()) {
case ASTNode.TYPE_DECLARATION:
return new CompletionCandidate[] { new CompletionCandidate((TypeDeclaration) node) };
case ASTNode.METHOD_DECLARATION:
MethodDeclaration md = (MethodDeclaration) node;
log(getNodeAsString(md));
List<ASTNode> params = (List<ASTNode>) md.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);
CompletionCandidate[] cand = new CompletionCandidate[params.size() + 1];
cand[0] = new CompletionCandidate(md);
for (int i = 0; i < params.size(); i++) {
// cand[i + 1] = new CompletionCandidate(params.get(i).toString(), "", "",
// CompletionCandidate.LOCAL_VAR);
cand[i + 1] = new CompletionCandidate((SingleVariableDeclaration) params.get(i));
}
return cand;
case ASTNode.SINGLE_VARIABLE_DECLARATION:
return new CompletionCandidate[] { new CompletionCandidate((SingleVariableDeclaration) node) };
case ASTNode.FIELD_DECLARATION:
vdfs = ((FieldDeclaration) node).fragments();
break;
case ASTNode.VARIABLE_DECLARATION_STATEMENT:
vdfs = ((VariableDeclarationStatement) node).fragments();
break;
case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
vdfs = ((VariableDeclarationExpression) node).fragments();
break;
default:
break;
}
if (vdfs != null) {
CompletionCandidate[] ret = new CompletionCandidate[vdfs.size()];
int i = 0;
for (VariableDeclarationFragment vdf : vdfs) {
// ret[i++] = new CompletionCandidate(getNodeAsString2(vdf), "", "",
// CompletionCandidate.LOCAL_VAR);
ret[i++] = new CompletionCandidate(vdf);
}
return ret;
}
return null;
}
use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project AutoRefactor by JnRouvignac.
the class MapEliminateKeySetCallsRefactoring method visit.
@Override
public boolean visit(EnhancedForStatement enhancedFor) {
final Expression foreachExpr = enhancedFor.getExpression();
if (isKeySetMethod(foreachExpr)) {
// From 'for (K key : map.keySet()) { }'
// -> mapExpression become 'map', parameter become 'K key'
final Expression mapExpression = ((MethodInvocation) foreachExpr).getExpression();
if (mapExpression == null) {
// not implemented
return VISIT_SUBTREE;
}
final SingleVariableDeclaration parameter = enhancedFor.getParameter();
final List<MethodInvocation> getValueMis = collectMapGetValueCalls(mapExpression, parameter, enhancedFor.getBody());
if (!getValueMis.isEmpty() && haveSameTypeBindings(getValueMis)) {
replaceEntryIterationByKeyIteration(enhancedFor, mapExpression, parameter, getValueMis);
return DO_NOT_VISIT_SUBTREE;
}
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project AutoRefactor by JnRouvignac.
the class ReplaceQualifiedNamesBySimpleNamesRefactoring method visit.
@Override
public boolean visit(MethodDeclaration node) {
// Method parameters
for (final SingleVariableDeclaration parameter : parameters(node)) {
if (maybeReplaceFqnsWithSimpleNames(parameter) == DO_NOT_VISIT_SUBTREE) {
return DO_NOT_VISIT_SUBTREE;
}
}
// Method return value
if (maybeReplaceFqnsWithSimpleNames(node.getReturnType2()) == DO_NOT_VISIT_SUBTREE) {
return DO_NOT_VISIT_SUBTREE;
}
// Method body
final Set<String> localIdentifiers = new HashSet<String>();
for (final SingleVariableDeclaration localParameter : parameters(node)) {
localIdentifiers.add(localParameter.getName().getIdentifier());
}
localIdentifiers.addAll(getLocalVariableIdentifiers(node.getBody(), true));
return maybeReplaceFqnsWithSimpleNames(node.getBody(), localIdentifiers);
}
use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project AutoRefactor by JnRouvignac.
the class ASTBuilder method catch0.
/**
* Builds a new {@link CatchClause} instance.
*
* @param exceptionTypeName the exception type name
* @param caughtExceptionName the local name for the caught exception
* @param stmts the statements to add to the catch clause
* @return a new catch clause
*/
public CatchClause catch0(String exceptionTypeName, String caughtExceptionName, Statement... stmts) {
final CatchClause cc = ast.newCatchClause();
final SingleVariableDeclaration svd = ast.newSingleVariableDeclaration();
svd.setType(simpleType(exceptionTypeName));
svd.setName(ast.newSimpleName(caughtExceptionName));
cc.setException(svd);
final Block block = ast.newBlock();
addAll(statements(block), stmts);
cc.setBody(block);
return cc;
}
use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project AutoRefactor by JnRouvignac.
the class ASTBuilder method declareSingleVariable.
/**
* Builds a new {@link SingleVariableDeclaration} instance.
*
* @param varName
* the name of the variable being declared
* @param type
* the type of the variable being declared
* @return a new single variable declaration
*/
public SingleVariableDeclaration declareSingleVariable(String varName, Type type) {
final SingleVariableDeclaration svd = ast.newSingleVariableDeclaration();
svd.setName(simpleName(varName));
svd.setType(type);
return svd;
}
Aggregations