src/jdk.compiler/share/classes/com/sun/tools/javac/code/DeferredCompletionFailureHandler.java
author jlahoda
Fri, 09 Mar 2018 09:42:10 +0100
changeset 49197 cc2673fa8c20
child 52489 1a6aeca4a8c9
permissions -rw-r--r--
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure. Summary: Catching CompletionFailures that would be thrown to API clients, and re-completing the symbols again when javac itself needs it. Reviewed-by: cushon, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
     1
/*
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
     4
 *
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    10
 *
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    16
 *
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    20
 *
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    23
 * questions.
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    24
 */
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    25
package com.sun.tools.javac.code;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    26
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    27
import java.util.Map;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    28
import java.util.WeakHashMap;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    29
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    30
import com.sun.tools.javac.code.Kinds.Kind;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    31
import com.sun.tools.javac.code.Scope.WriteableScope;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    32
import com.sun.tools.javac.code.Symbol;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    33
import com.sun.tools.javac.code.Symbol.ClassSymbol;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    34
import com.sun.tools.javac.code.Symbol.Completer;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    35
import com.sun.tools.javac.code.Symbol.CompletionFailure;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    36
import com.sun.tools.javac.util.Context;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    37
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    38
/** When a CompletionFailure is thrown when user code is running, it shouldn't be
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    39
 *  thrown out to the client code, but rather skipped, and then rethrown later if javac
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    40
 *  itself will complete the Symbol.
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    41
 *
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    42
 *  On all places where javac invokes client code (e.g. TaskListeners, annotation
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    43
 *  Processors), the {@code userCodeHandler} should be set using
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    44
 *  {@link DeferredCompletionFailureHandler#setHandler}, and the original handler
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    45
 *  should be restored when the control returns back to javac.
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    46
 *
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    47
 *  Implementations of API methods should use {@link Symbol#apiComplete()} instead of
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    48
 *  {@link Symbol#complete}, as the {@code apiComplete} method will invoke
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    49
 *  {@link DeferredCompletionFailureHandler#handleAPICompletionFailure }, which will
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    50
 *  catch the CompletionFailure and will either rethrow it or skip it, depending on
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    51
 *  the context.
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    52
 */
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    53
public class DeferredCompletionFailureHandler {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    54
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    55
    protected static final Context.Key<DeferredCompletionFailureHandler> deferredCompletionFailureHandlerKey = new Context.Key<>();
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    56
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    57
    public static DeferredCompletionFailureHandler instance(Context context) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    58
        DeferredCompletionFailureHandler instance = context.get(deferredCompletionFailureHandlerKey);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    59
        if (instance == null)
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    60
            instance = new DeferredCompletionFailureHandler(context);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    61
        return instance;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    62
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    63
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    64
    public final Handler userCodeHandler = new Handler() {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    65
        private final Map<ClassSymbol, FlipSymbolDescription> class2Flip = new WeakHashMap<>();
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    66
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    67
        public void install() {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    68
            class2Flip.values().forEach(f -> f.flip());
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    69
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    70
        public void handleAPICompletionFailure(CompletionFailure cf) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    71
            //ignore
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    72
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    73
        public void classSymbolCompleteFailed(ClassSymbol sym, Completer origCompleter) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    74
            class2Flip.put(sym, new FlipSymbolDescription(sym, new DeferredCompleter(origCompleter) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    75
                @Override public void complete(Symbol sym) throws CompletionFailure {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    76
                    class2Flip.remove(sym);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    77
                    super.complete(sym);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    78
                }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    79
            }));
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    80
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    81
        public void uninstall() {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    82
            class2Flip.values().forEach(f -> f.flip());
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    83
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    84
    };
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    85
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    86
    public final Handler javacCodeHandler = new Handler() {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    87
        public void install() {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    88
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    89
        public void handleAPICompletionFailure(CompletionFailure cf) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    90
            throw cf;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    91
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    92
        public void classSymbolCompleteFailed(ClassSymbol sym, Completer origCompleter) {}
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    93
        public void uninstall() {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    94
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    95
    };
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    96
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    97
    private Handler handler = javacCodeHandler;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    98
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
    99
    protected DeferredCompletionFailureHandler(Context context) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   100
        context.put(deferredCompletionFailureHandlerKey, this);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   101
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   102
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   103
    public Handler setHandler(Handler h) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   104
        if (h == handler) return handler;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   105
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   106
        handler.uninstall();
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   107
        Handler prev = handler;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   108
        handler = h;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   109
        handler.install();
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   110
        return prev;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   111
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   112
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   113
    public void handleAPICompletionFailure(CompletionFailure cf) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   114
        handler.handleAPICompletionFailure(cf);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   115
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   116
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   117
    public void classSymbolCompleteFailed(ClassSymbol sym, Completer origCompleter) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   118
        handler.classSymbolCompleteFailed(sym, origCompleter);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   119
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   120
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   121
    public boolean isDeferredCompleter(Completer c) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   122
        return c instanceof DeferredCompleter;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   123
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   124
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   125
    public interface Handler {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   126
        public void install();
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   127
        public void handleAPICompletionFailure(CompletionFailure cf);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   128
        public void classSymbolCompleteFailed(ClassSymbol sym, Completer origCompleter);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   129
        public void uninstall();
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   130
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   131
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   132
    private class DeferredCompleter implements Completer {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   133
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   134
        private final Completer origCompleter;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   135
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   136
        public DeferredCompleter(Completer origCompleter) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   137
            this.origCompleter = origCompleter;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   138
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   139
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   140
        @Override
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   141
        public void complete(Symbol sym) throws CompletionFailure {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   142
            origCompleter.complete(sym);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   143
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   144
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   145
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   146
    private static class FlipSymbolDescription {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   147
        public final ClassSymbol sym;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   148
        public Type type;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   149
        public Kind kind;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   150
        public WriteableScope members;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   151
        public Completer completer;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   152
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   153
        public FlipSymbolDescription(ClassSymbol sym, Completer completer) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   154
            this.sym = sym;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   155
            this.type = sym.type;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   156
            this.kind = sym.kind;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   157
            this.members = null;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   158
            this.completer = completer;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   159
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   160
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   161
        public void flip() {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   162
            Type prevType = sym.type;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   163
            sym.type = type;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   164
            this.type = prevType;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   165
            Kind prevKind = sym.kind;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   166
            sym.kind = kind;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   167
            this.kind = prevKind;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   168
            Completer prevCompleter = sym.completer;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   169
            sym.completer = completer;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   170
            this.completer = prevCompleter;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   171
            WriteableScope prevMembers = sym.members_field;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   172
            sym.members_field = members;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   173
            this.members = prevMembers;
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   174
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   175
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   176
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
diff changeset
   177
}