use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class VariableDeclarationFix method createAddFinalOperation.
private static ModifierChangeOperation createAddFinalOperation(SimpleName name, ASTNode decl) {
if (decl == null)
return null;
IBinding binding = name.resolveBinding();
if (!canAddFinal(binding, decl))
return null;
if (decl instanceof SingleVariableDeclaration) {
return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
} else if (decl instanceof VariableDeclarationExpression) {
return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
} else if (decl instanceof VariableDeclarationFragment) {
VariableDeclarationFragment frag = (VariableDeclarationFragment) decl;
decl = decl.getParent();
if (decl instanceof FieldDeclaration || decl instanceof VariableDeclarationStatement) {
List<VariableDeclarationFragment> list = new ArrayList<VariableDeclarationFragment>();
list.add(frag);
return new ModifierChangeOperation(decl, list, Modifier.FINAL, Modifier.NONE);
} else if (decl instanceof VariableDeclarationExpression) {
return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
}
}
return null;
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class UnusedCodeFix method createUnusedTypeParameterFix.
public static UnusedCodeFix createUnusedTypeParameterFix(CompilationUnit compilationUnit, IProblemLocation problemLoc) {
if (problemLoc.getProblemId() == IProblem.UnusedTypeParameter) {
SimpleName name = getUnusedName(compilationUnit, problemLoc);
if (name != null) {
IBinding binding = name.resolveBinding();
if (binding != null) {
String label = FixMessages.UnusedCodeFix_RemoveUnusedTypeParameter_description;
RemoveUnusedTypeParameterOperation operation = new RemoveUnusedTypeParameterOperation(name);
return new UnusedCodeFix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions(binding, false));
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class InlineConstantRefactoring method findConstantNameNode.
private Name findConstantNameNode() {
ASTNode node = NodeFinder.perform(fSelectionCuRewrite.getRoot(), fSelectionStart, fSelectionLength);
if (node == null)
return null;
if (node instanceof FieldAccess)
node = ((FieldAccess) node).getName();
if (!(node instanceof Name))
return null;
Name name = (Name) node;
IBinding binding = name.resolveBinding();
if (!(binding instanceof IVariableBinding))
return null;
IVariableBinding variableBinding = (IVariableBinding) binding;
if (!variableBinding.isField() || variableBinding.isEnumConstant())
return null;
int modifiers = binding.getModifiers();
if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)))
return null;
return name;
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class ConvertAnonymousToNestedRefactoring method getUsedLocalVariables.
private IVariableBinding[] getUsedLocalVariables() {
final Set<IBinding> result = new HashSet<IBinding>(0);
collectRefrencedVariables(fAnonymousInnerClassNode, result);
ArrayList<IVariableBinding> usedLocals = new ArrayList<IVariableBinding>();
for (Iterator<IBinding> iterator = result.iterator(); iterator.hasNext(); ) {
IVariableBinding next = (IVariableBinding) iterator.next();
if (isBindingToTemp(next)) {
usedLocals.add(next);
}
}
return usedLocals.toArray(new IVariableBinding[usedLocals.size()]);
}
use of org.eclipse.jdt.core.dom.IBinding in project flux by eclipse.
the class CompletionProposalReplacementProvider method getExpectedTypeForGenericParameters.
private ITypeBinding getExpectedTypeForGenericParameters() {
char[][] chKeys = context.getExpectedTypesKeys();
if (chKeys == null || chKeys.length == 0)
return null;
String[] keys = new String[chKeys.length];
for (int i = 0; i < keys.length; i++) {
keys[i] = String.valueOf(chKeys[0]);
}
final ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setProject(compilationUnit.getJavaProject());
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
final Map<String, IBinding> bindings = new HashMap<String, IBinding>();
ASTRequestor requestor = new ASTRequestor() {
@Override
public void acceptBinding(String bindingKey, IBinding binding) {
bindings.put(bindingKey, binding);
}
};
parser.createASTs(new ICompilationUnit[0], keys, requestor, null);
if (bindings.size() > 0)
return (ITypeBinding) bindings.get(keys[0]);
return null;
}
Aggregations