Search in sources :

Example 6 with ASTRequestor

use of org.eclipse.jdt.core.dom.ASTRequestor 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;
}
Also used : HashMap(java.util.HashMap) IBinding(org.eclipse.jdt.core.dom.IBinding) ASTRequestor(org.eclipse.jdt.core.dom.ASTRequestor) ASTParser(org.eclipse.jdt.core.dom.ASTParser)

Aggregations

ASTRequestor (org.eclipse.jdt.core.dom.ASTRequestor)6 ASTParser (org.eclipse.jdt.core.dom.ASTParser)5 IBinding (org.eclipse.jdt.core.dom.IBinding)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)2 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 IFile (org.eclipse.core.resources.IFile)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IProblem (org.eclipse.jdt.core.compiler.IProblem)1 CheASTParser (org.eclipse.jdt.core.dom.CheASTParser)1