com.sun.tools.javac.util.Abort Java Examples

The following examples show how to use com.sun.tools.javac.util.Abort. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavacProcessingEnvironment.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Processor next() {
    try {
        return iterator.next();
    } catch (ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (UnsupportedClassVersionError ucve) {
        log.error("proc.cant.load.class", ucve.getLocalizedMessage());
        throw new Abort(ucve);
    } catch (ClassFormatError cfe) {
        log.error("proc.cant.load.class", cfe.getLocalizedMessage());
        throw new Abort(cfe);
    } catch (Throwable t) {
        log.error("proc.bad.config.file", t.getLocalizedMessage());
        throw new Abort(t);
    }
}
 
Example #2
Source File: APTUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
@Messages("ERR_ProcessorException=Annotation processor {0} failed with an exception: {1}")
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!valid) {
        return false;
    }
    try {
        return delegate.process(annotations, roundEnv);
    } catch (ClientCodeException | ThreadDeath | Abort err) {
        valid = false;
        throw err;
    } catch (Throwable t) {
        valid = false;
        Element el = roundEnv.getRootElements().isEmpty() ? null : roundEnv.getRootElements().iterator().next();
        StringBuilder exception = new StringBuilder();
        exception.append(t.getMessage()).append("\n");
        for (StackTraceElement ste : t.getStackTrace()) {
            exception.append(ste).append("\n");
        }
        processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, Bundle.ERR_ProcessorException(delegate.getClass().getName(), exception.toString()), el);
        return false;
    }
}
 
Example #3
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Processor next() {
    try {
        return iterator.next();
    } catch (ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (UnsupportedClassVersionError ucve) {
        log.error("proc.cant.load.class", ucve.getLocalizedMessage());
        throw new Abort(ucve);
    } catch (ClassFormatError cfe) {
        log.error("proc.cant.load.class", cfe.getLocalizedMessage());
        throw new Abort(cfe);
    } catch (Throwable t) {
        log.error("proc.bad.config.file", t.getLocalizedMessage());
        throw new Abort(t);
    }
}
 
Example #4
Source File: TypeHarness.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public final Type getType(String type) {
    JavaSource source = new JavaSource(type);
    MyAttr.theType = null;
    MyAttr.typeParameters = List.nil();
    tool.clear();
    List<JavaFileObject> inputs = of(source);
    try {
        tool.compile(inputs);
    } catch (Throwable ex) {
        throw new Abort(ex);
    }
    if (typeVariables != null) {
        return types.subst(MyAttr.theType, MyAttr.typeParameters, typeVariables);
    }
    return MyAttr.theType;
}
 
Example #5
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Processor next() {
    try {
        return iterator.next();
    } catch (ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #6
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean hasNext() {
    try {
        return iterator.hasNext();
    } catch(ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #7
Source File: JavacProcessingEnvironment.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle a security exception thrown during initializing the
 * Processor iterator.
 */
private void handleException(String key, Exception e) {
    if (e != null) {
        log.error(key, e.getLocalizedMessage());
        throw new Abort(e);
    } else {
        log.error(key);
        throw new Abort();
    }
}
 
Example #8
Source File: JavacProcessingEnvironment.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public boolean hasNext() {
    try {
        return iterator.hasNext();
    } catch (Throwable t) {
        if ("ServiceConfigurationError".
            equals(t.getClass().getSimpleName())) {
            log.error("proc.bad.config.file", t.getLocalizedMessage());
        }
        throw new Abort(t);
    }
}
 
Example #9
Source File: JavacProcessingEnvironment.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public Processor next() {
    try {
        return (Processor)(iterator.next());
    } catch (Throwable t) {
        if ("ServiceConfigurationError".
            equals(t.getClass().getSimpleName())) {
            log.error("proc.bad.config.file", t.getLocalizedMessage());
        } else {
            log.error("proc.processor.constructor.error", t.getLocalizedMessage());
        }
        throw new Abort(t);
    }
}
 
Example #10
Source File: JavaCompiler.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Main method: compile a list of files, return all compiled classes
 *
 * @param sourceFileObjects file objects to be compiled
 * @param classnames        class names to process for annotations
 * @param processors        user provided annotation processors to bypass
 *                          discovery, {@code null} means that no processors were provided
 */
public void compile(List<JavaFileObject> sourceFileObjects,
                    List<String> classnames,
                    Iterable<? extends Processor> processors) {
    if (processors != null && processors.iterator().hasNext())
        explicitAnnotationProcessingRequested = true;
    // as a JavaCompiler can only be used once, throw an exception if
    // it has been used before.
    if (hasBeenUsed)
        throw new AssertionError("attempt to reuse JavaCompiler");
    hasBeenUsed = true;

    // forcibly set the equivalent of -Xlint:-options, so that no further
    // warnings about command line options are generated from this point on
    options.put(XLINT_CUSTOM + "-" + LintCategory.OPTIONS.option, "true");
    options.remove(XLINT_CUSTOM + LintCategory.OPTIONS.option);

    start_msec = now();

    try {
        initProcessAnnotations(processors);

        // These method calls must be chained to avoid memory leaks
        delegateCompiler =
                processAnnotations(
                        enterTrees(stopIfError(CompileState.PARSE, parseFiles(sourceFileObjects))),
                        classnames);

        delegateCompiler.compile2();
        delegateCompiler.close();
        elapsed_msec = delegateCompiler.elapsed_msec;
    } catch (Abort ex) {
        if (devVerbose)
            ex.printStackTrace(System.err);
    } finally {
        if (procEnvImpl != null)
            procEnvImpl.close();
    }
}
 
Example #11
Source File: JavaCompiler.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public void close(boolean disposeNames) {
    rootClasses = null;
    reader = null;
    make = null;
    writer = null;
    enter = null;
    if (todo != null)
        todo.clear();
    todo = null;
    parserFactory = null;
    syms = null;
    source = null;
    attr = null;
    chk = null;
    gen = null;
    flow = null;
    transTypes = null;
    lower = null;
    annotate = null;
    types = null;

    log.flush();
    try {
        fileManager.flush();
    } catch (IOException e) {
        throw new Abort(e);
    } finally {
        if (names != null && disposeNames)
            names.dispose();
        names = null;
    }
}
 
Example #12
Source File: JavacProcessingEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public <S> ServiceLoader<S> getServiceLoader(Class<S> service) {
    if (fileManager.hasLocation(ANNOTATION_PROCESSOR_MODULE_PATH)) {
        try {
            return fileManager.getServiceLoader(ANNOTATION_PROCESSOR_MODULE_PATH, service);
        } catch (IOException e) {
            throw new Abort(e);
        }
    } else {
        return ServiceLoader.load(service, getProcessorClassLoader());
    }
}
 
Example #13
Source File: JavacProcessingEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle a security exception thrown during initializing the
 * Processor iterator.
 */
private void handleException(String key, Exception e) {
    if (e != null) {
        log.error(key, e.getLocalizedMessage());
        throw new Abort(e);
    } else {
        log.error(key);
        throw new Abort();
    }
}
 
Example #14
Source File: JavacProcessingEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ServiceIterator(ClassLoader classLoader, Log log) {
    this.log = log;
    try {
        try {
            loader = ServiceLoader.load(Processor.class, classLoader);
            this.iterator = loader.iterator();
        } catch (Exception e) {
            // Fail softly if a loader is not actually needed.
            this.iterator = handleServiceLoaderUnavailability("proc.no.service", null);
        }
    } catch (Throwable t) {
        log.error("proc.service.problem");
        throw new Abort(t);
    }
}
 
Example #15
Source File: JavacProcessingEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean hasNext() {
    try {
        return internalHasNext();
    } catch(ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #16
Source File: JavacProcessingEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Processor next() {
    try {
        return internalNext();
    } catch (ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #17
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean enter(List<JCCompilationUnit> trees, Consumer<Set<ModuleSymbol>> init, ClassSymbol c) {
    if (!allowModules) {
        for (JCCompilationUnit tree: trees) {
            tree.modle = syms.noModule;
        }
        defaultModule = syms.noModule;
        return true;
    }

    int startErrors = log.nerrors;

    depth++;
    try {
        // scan trees for module defs
        Set<ModuleSymbol> roots = enterModules(trees, c);

        setCompilationUnitModules(trees, roots, c);

        init.accept(roots);

        for (ModuleSymbol msym: roots) {
            msym.complete();
        }
    } catch (CompletionFailure ex) {
        log.error(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE, Position.NOPOS, "cant.access", ex.sym, ex.getDetailValue());
        if (ex instanceof ClassFinder.BadClassFile) throw new Abort();
    } finally {
        depth--;
    }

    return (log.nerrors == startErrors);
}
 
Example #18
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle a security exception thrown during initializing the
 * Processor iterator.
 */
private void handleException(String key, Exception e) {
    if (e != null) {
        log.error(key, e.getLocalizedMessage());
        throw new Abort(e);
    } else {
        log.error(key);
        throw new Abort();
    }
}
 
Example #19
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
ServiceIterator(ClassLoader classLoader, Log log) {
    this.log = log;
    try {
        try {
            loader = ServiceLoader.load(Processor.class, classLoader);
            this.iterator = loader.iterator();
        } catch (Exception e) {
            // Fail softly if a loader is not actually needed.
            this.iterator = handleServiceLoaderUnavailability("proc.no.service", null);
        }
    } catch (Throwable t) {
        log.error("proc.service.problem");
        throw new Abort(t);
    }
}
 
Example #20
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean hasNext() {
    try {
        return iterator.hasNext();
    } catch(ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #21
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Processor next() {
    try {
        return iterator.next();
    } catch (ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #22
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle a security exception thrown during initializing the
 * Processor iterator.
 */
private void handleException(String key, Exception e) {
    if (e != null) {
        log.error(key, e.getLocalizedMessage());
        throw new Abort(e);
    } else {
        log.error(key);
        throw new Abort();
    }
}
 
Example #23
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
ServiceIterator(ClassLoader classLoader, Log log) {
    this.log = log;
    try {
        try {
            loader = ServiceLoader.load(Processor.class, classLoader);
            this.iterator = loader.iterator();
        } catch (Exception e) {
            // Fail softly if a loader is not actually needed.
            this.iterator = handleServiceLoaderUnavailability("proc.no.service", null);
        }
    } catch (Throwable t) {
        log.error("proc.service.problem");
        throw new Abort(t);
    }
}
 
Example #24
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public boolean hasNext() {
    try {
        return iterator.hasNext();
    } catch(ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #25
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Processor next() {
    try {
        return iterator.next();
    } catch (ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #26
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle a security exception thrown during initializing the
 * Processor iterator.
 */
private void handleException(String key, Exception e) {
    if (e != null) {
        log.error(key, e.getLocalizedMessage());
        throw new Abort(e);
    } else {
        log.error(key);
        throw new Abort();
    }
}
 
Example #27
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
ServiceIterator(ClassLoader classLoader, Log log) {
    this.log = log;
    try {
        try {
            loader = ServiceLoader.load(Processor.class, classLoader);
            this.iterator = loader.iterator();
        } catch (Exception e) {
            // Fail softly if a loader is not actually needed.
            this.iterator = handleServiceLoaderUnavailability("proc.no.service", null);
        }
    } catch (Throwable t) {
        log.error("proc.service.problem");
        throw new Abort(t);
    }
}
 
Example #28
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean hasNext() {
    try {
        return iterator.hasNext();
    } catch(ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #29
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Processor next() {
    try {
        return iterator.next();
    } catch (ServiceConfigurationError sce) {
        log.error("proc.bad.config.file", sce.getLocalizedMessage());
        throw new Abort(sce);
    } catch (Throwable t) {
        throw new Abort(t);
    }
}
 
Example #30
Source File: JavaCompiler.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void close(boolean disposeNames) {
    rootClasses = null;
    reader = null;
    make = null;
    writer = null;
    enter = null;
    if (todo != null)
        todo.clear();
    todo = null;
    parserFactory = null;
    syms = null;
    source = null;
    attr = null;
    chk = null;
    gen = null;
    flow = null;
    transTypes = null;
    lower = null;
    annotate = null;
    types = null;

    log.flush();
    try {
        fileManager.flush();
    } catch (IOException e) {
        throw new Abort(e);
    } finally {
        if (names != null && disposeNames)
            names.dispose();
        names = null;
    }
}