use of org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer in project che by eclipse.
the class MissingReturnTypeInLambdaCorrectionProposal method computeProposals.
@Override
protected Expression computeProposals(AST ast, ITypeBinding returnBinding, int returnOffset, CompilationUnit root, Expression result) {
ScopeAnalyzer analyzer = new ScopeAnalyzer(root);
IBinding[] bindings = analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);
org.eclipse.jdt.core.dom.NodeFinder finder = new org.eclipse.jdt.core.dom.NodeFinder(root, returnOffset, 0);
ASTNode varDeclFrag = ASTResolving.findAncestor(finder.getCoveringNode(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
IVariableBinding varDeclFragBinding = null;
if (varDeclFrag != null)
varDeclFragBinding = ((VariableDeclarationFragment) varDeclFrag).resolveBinding();
for (int i = 0; i < bindings.length; i++) {
IVariableBinding curr = (IVariableBinding) bindings[i];
ITypeBinding type = curr.getType();
// Bindings are compared to make sure that a lambda does not return a variable which is yet to be initialised.
if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr) && !Bindings.equals(curr, varDeclFragBinding)) {
if (result == null) {
result = ast.newSimpleName(curr.getName());
}
addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName(), null);
}
}
return result;
}
use of org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer in project che by eclipse.
the class ExtractToNullCheckedLocalProposal method proposeLocalName.
String proposeLocalName(SimpleName fieldName, CompilationUnit root, IJavaProject javaProject) {
// don't propose names that are already in use:
Collection<String> variableNames = new ScopeAnalyzer(root).getUsedVariableNames(this.enclosingMethod.getStartPosition(), this.enclosingMethod.getLength());
String[] names = new String[variableNames.size() + 1];
variableNames.toArray(names);
// don't propose the field name itself, either:
String identifier = fieldName.getIdentifier();
names[names.length - 1] = identifier;
return StubUtility.getLocalNameSuggestions(javaProject, identifier, 0, names)[0];
}
use of org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer in project che by eclipse.
the class ConvertLoopOperation method getUsedVariableNames.
protected String[] getUsedVariableNames() {
final List<String> results = new ArrayList<String>();
ForStatement forStatement = getForStatement();
CompilationUnit root = (CompilationUnit) forStatement.getRoot();
Collection<String> variableNames = new ScopeAnalyzer(root).getUsedVariableNames(forStatement.getStartPosition(), forStatement.getLength());
results.addAll(variableNames);
forStatement.accept(new GenericVisitor() {
@Override
public boolean visit(SingleVariableDeclaration node) {
results.add(node.getName().getIdentifier());
return super.visit(node);
}
@Override
public boolean visit(VariableDeclarationFragment fragment) {
results.add(fragment.getName().getIdentifier());
return super.visit(fragment);
}
});
results.addAll(Arrays.asList(fUsedNames));
return results.toArray(new String[results.size()]);
}
use of org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer in project che by eclipse.
the class ASTResolving method getUsedVariableNames.
public static String[] getUsedVariableNames(ASTNode node) {
CompilationUnit root = (CompilationUnit) node.getRoot();
Collection<String> res = (new ScopeAnalyzer(root)).getUsedVariableNames(node.getStartPosition(), node.getLength());
return res.toArray(new String[res.size()]);
}
use of org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer in project flux by eclipse.
the class ImportReferencesCollector method possibleStaticImportFound.
private void possibleStaticImportFound(Name name) {
if (fStaticImports == null || fASTRoot == null) {
return;
}
while (name.isQualifiedName()) {
name = ((QualifiedName) name).getQualifier();
}
if (!isAffected(name)) {
return;
}
IBinding binding = name.resolveBinding();
SimpleName simpleName = (SimpleName) name;
if (binding == null || binding instanceof ITypeBinding || !Modifier.isStatic(binding.getModifiers()) || simpleName.isDeclaration()) {
return;
}
if (binding instanceof IVariableBinding) {
IVariableBinding varBinding = (IVariableBinding) binding;
if (varBinding.isField()) {
varBinding = varBinding.getVariableDeclaration();
ITypeBinding declaringClass = varBinding.getDeclaringClass();
if (declaringClass != null && !declaringClass.isLocal()) {
if (new ScopeAnalyzer(fASTRoot).isDeclaredInScope(varBinding, simpleName, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY))
return;
fStaticImports.add(simpleName);
}
}
} else if (binding instanceof IMethodBinding) {
IMethodBinding methodBinding = ((IMethodBinding) binding).getMethodDeclaration();
ITypeBinding declaringClass = methodBinding.getDeclaringClass();
if (declaringClass != null && !declaringClass.isLocal()) {
if (new ScopeAnalyzer(fASTRoot).isDeclaredInScope(methodBinding, simpleName, ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY))
return;
fStaticImports.add(simpleName);
}
}
}
Aggregations