Search in sources :

Example 11 with Selection

use of org.eclipse.jdt.internal.corext.dom.Selection in project che by eclipse.

the class ExtractMethodAnalyzer method computeTypeVariables.

private ITypeBinding[] computeTypeVariables(ITypeBinding[] bindings) {
    Selection selection = getSelection();
    Set<ITypeBinding> result = new HashSet<ITypeBinding>();
    // first remove all type variables that come from outside of the method
    // or are covered by the selection
    CompilationUnit compilationUnit = (CompilationUnit) fEnclosingBodyDeclaration.getRoot();
    for (int i = 0; i < bindings.length; i++) {
        ASTNode decl = compilationUnit.findDeclaringNode(bindings[i]);
        if (decl == null || (!selection.covers(decl) && decl.getParent() instanceof MethodDeclaration))
            result.add(bindings[i]);
    }
    // all all type variables which are needed since a local variable uses it
    for (int i = 0; i < fArguments.length; i++) {
        IVariableBinding arg = fArguments[i];
        ITypeBinding type = arg.getType();
        if (type != null && type.isTypeVariable()) {
            ASTNode decl = compilationUnit.findDeclaringNode(type);
            if (decl == null || (!selection.covers(decl) && decl.getParent() instanceof MethodDeclaration))
                result.add(type);
        }
    }
    return result.toArray(new ITypeBinding[result.size()]);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) Selection(org.eclipse.jdt.internal.corext.dom.Selection) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) HashSet(java.util.HashSet)

Aggregations

Selection (org.eclipse.jdt.internal.corext.dom.Selection)11 ASTNode (org.eclipse.jdt.core.dom.ASTNode)7 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)5 SelectionAnalyzer (org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer)4 ASTParser (org.eclipse.jdt.core.dom.ASTParser)3 Expression (org.eclipse.jdt.core.dom.Expression)3 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)3 LambdaExpression (org.eclipse.jdt.core.dom.LambdaExpression)3 RefactoringASTParser (org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser)3 ArrayList (java.util.ArrayList)2 Block (org.eclipse.jdt.core.dom.Block)2 FlowContext (org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowContext)2 InputFlowAnalyzer (org.eclipse.jdt.internal.corext.refactoring.code.flow.InputFlowAnalyzer)2 HashSet (java.util.HashSet)1 TextSelection (org.eclipse.che.jface.text.TextSelection)1 CoreException (org.eclipse.core.runtime.CoreException)1 IType (org.eclipse.jdt.core.IType)1 IProblem (org.eclipse.jdt.core.compiler.IProblem)1 ArrayType (org.eclipse.jdt.core.dom.ArrayType)1