Search in sources :

Example 1 with FatalError

use of com.sun.tools.javac.util.FatalError in project error-prone by google.

the class FragmentInjection method matchClass.

@Override
public Description matchClass(ClassTree tree, VisitorState state) {
    // Only examine classes that extend PreferenceActivity.
    Type preferenceActivityType = state.getTypeFromString("android.preference.PreferenceActivity");
    if (!isSubtype(getType(tree), preferenceActivityType, state)) {
        return NO_MATCH;
    }
    // Examine each method in the class. Complain if isValidFragment not implemented.
    TypeSymbol preferenceActivityTypeSymbol = preferenceActivityType.tsym;
    boolean methodNotImplemented = true;
    try {
        MethodSymbol isValidFragmentMethodSymbol = resolveExistingMethod(state, getSymbol(tree), state.getName("isValidFragment"), ImmutableList.<Type>of(state.getTypeFromString("java.lang.String")), ImmutableList.<Type>of());
        methodNotImplemented = isValidFragmentMethodSymbol.owner.equals(preferenceActivityTypeSymbol);
    } catch (FatalError e) {
    // If isValidFragment method symbol is not found, then we must be compiling against an old SDK
    // version (< 19) in which isValidFragment is not yet implemented, and neither this class nor
    // any of its super classes have implemented it.
    }
    // isValidFragment, and this is not an abstract class, emit warning.
    if (methodNotImplemented && not(hasModifier(Modifier.ABSTRACT)).matches(tree, state)) {
        return buildDescription(tree).setMessage("Class extending PreferenceActivity does not implement isValidFragment.").build();
    }
    // Check the implementation of isValidFragment. Complain if it always returns true.
    MethodTree isValidFragmentMethodTree = getMethod(OVERRIDES_IS_VALID_FRAGMENT, tree, state);
    if (isValidFragmentMethodTree != null) {
        if (isValidFragmentMethodTree.accept(ALWAYS_RETURNS_TRUE, null)) {
            return buildDescription(isValidFragmentMethodTree).setMessage("isValidFragment unconditionally returns true.").build();
        }
    }
    return NO_MATCH;
}
Also used : FatalError(com.sun.tools.javac.util.FatalError) ASTHelpers.getType(com.google.errorprone.util.ASTHelpers.getType) Matchers.isSameType(com.google.errorprone.matchers.Matchers.isSameType) Type(com.sun.tools.javac.code.Type) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) MethodTree(com.sun.source.tree.MethodTree) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol)

Example 2 with FatalError

use of com.sun.tools.javac.util.FatalError in project ceylon-compiler by ceylon.

the class Main method compile.

/**
     * Programmatic interface for main function.
     * @param args The command line parameters.
     */
public int compile(String[] args, Context context, List<JavaFileObject> fileObjects, Iterable<? extends Processor> processors) {
    if (options == null) {
        // creates a new one
        options = Options.instance(context);
    }
    filenames = new ListBuffer<File>();
    classnames = new ListBuffer<String>();
    exitState = null;
    JavaCompiler comp = null;
    /* TODO: Logic below about what is an acceptable command line should be
         * updated to take annotation processing semantics into account. */
    try {
        if (args.length == 0 && fileObjects.isEmpty()) {
            help();
            this.exitState = ExitState.cmderror();
            return EXIT_CMDERR;
        }
        List<File> filenames = processArgs(args);
        if (filenames == null) {
            // null signals an error in options, abort
            this.exitState = ExitState.cmderror();
            return EXIT_CMDERR;
        } else if (filenames.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) {
            // or version info
            if (options.get("-help") != null || options.get("-jhelp") != null || options.get("-X") != null || options.get("-version") != null || options.get("-fullversion") != null)
                return EXIT_OK;
            error("err.no.source.files");
            this.exitState = ExitState.cmderror();
            return EXIT_CMDERR;
        }
        // Set up the timer *after* we've processed to options
        // because it needs to know if we need logging or not
        timer = Timer.instance(context);
        timer.init();
        boolean forceStdOut = options.get("stdout") != null;
        if (forceStdOut) {
            out.flush();
            out = new PrintWriter(System.out, true);
        }
        context.put(Log.outKey, out);
        fileManager = context.get(JavaFileManager.class);
        comp = LanguageCompiler.instance(context);
        if (comp == null) {
            this.exitState = ExitState.systemError(null, null);
            return EXIT_SYSERR;
        }
        if (!classnames.isEmpty()) {
            filenames = addModuleFiles(filenames);
            classnames.clear();
        }
        if (!filenames.isEmpty()) {
            // add filenames to fileObjects
            List<JavaFileObject> otherFiles = List.nil();
            JavacFileManager dfm = (JavacFileManager) fileManager;
            for (JavaFileObject fo : dfm.getJavaFileObjectsFromFiles(filenames)) {
                otherFiles = otherFiles.append(fo);
            }
            fileObjects = fileObjects.prependList(otherFiles);
        }
        if (fileObjects.isEmpty()) {
            error("err.no.source.files");
            this.exitState = ExitState.cmderror();
            return EXIT_CMDERR;
        }
        comp.compile(fileObjects, classnames.toList(), processors);
        int errorCount = comp.errorCount();
        //ceylonBackendErrors = comp.log instanceof CeylonLog ? ((CeylonLog)comp.log).ceylonBackendErrors() : false;
        if (errorCount != 0) {
            this.exitState = ExitState.error(comp);
            return EXIT_ERROR;
        }
    } catch (IOException ex) {
        ioMessage(ex);
        this.exitState = ExitState.systemError(null, ex);
        return EXIT_SYSERR;
    } catch (OutOfMemoryError ex) {
        resourceMessage(ex);
        this.exitState = ExitState.systemError(null, ex);
        return EXIT_SYSERR;
    } catch (StackOverflowError ex) {
        resourceMessage(ex);
        this.exitState = ExitState.systemError(null, ex);
        return EXIT_SYSERR;
    } catch (FatalError ex) {
        this.exitState = ExitState.systemError(comp, ex);
        if (this.exitState.javacExitCode == EXIT_SYSERR) {
            feMessage(ex);
        }
        return this.exitState.javacExitCode;
    } catch (AnnotationProcessingError ex) {
        apMessage(ex);
        this.exitState = ExitState.systemError(null, ex);
        return EXIT_SYSERR;
    } catch (ClientCodeException ex) {
        // and javax.tools.JavaCompiler.CompilationTask#call
        throw new RuntimeException(ex.getCause());
    } catch (PropagatedException ex) {
        throw ex.getCause();
    } catch (RepositoryException ex) {
        throw new EnvironmentException(ex);
    } catch (Throwable ex) {
        // exceptions.
        if (comp == null || comp.errorCount() == 0 || options == null || options.get("dev") != null) {
            bugMessage(ex);
        }
        this.exitState = ExitState.abnormal(comp, ex, options);
        return EXIT_ABNORMAL;
    } finally {
        if (comp != null)
            comp.close();
        filenames = null;
        options = null;
        if (timer != null) {
            timer.end();
        }
        timer = null;
    }
    this.exitState = ExitState.ok();
    return EXIT_OK;
}
Also used : JavaFileManager(javax.tools.JavaFileManager) JavaCompiler(com.sun.tools.javac.main.JavaCompiler) PropagatedException(com.sun.tools.javac.util.PropagatedException) RepositoryException(com.redhat.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) EnvironmentException(com.redhat.ceylon.compiler.EnvironmentException) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) AnnotationProcessingError(com.sun.tools.javac.processing.AnnotationProcessingError) JavaFileObject(javax.tools.JavaFileObject) FatalError(com.sun.tools.javac.util.FatalError) ClientCodeException(com.sun.tools.javac.util.ClientCodeException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 3 with FatalError

use of com.sun.tools.javac.util.FatalError in project ceylon-compiler by ceylon.

the class JavacProcessingEnvironment method close.

/**
     * Free resources related to annotation processing.
     */
public void close() {
    filer.close();
    if (// Make calling close idempotent
    discoveredProcs != null)
        discoveredProcs.close();
    discoveredProcs = null;
    if (processorClassLoader != null && processorClassLoader instanceof Closeable) {
        try {
            ((Closeable) processorClassLoader).close();
        } catch (IOException e) {
            JCDiagnostic msg = diags.fragment("fatal.err.cant.close.loader");
            throw new FatalError(msg, e);
        }
    }
}
Also used : FatalError(com.sun.tools.javac.util.FatalError) JCDiagnostic(com.sun.tools.javac.util.JCDiagnostic) Closeable(java.io.Closeable) IOException(java.io.IOException)

Aggregations

FatalError (com.sun.tools.javac.util.FatalError)3 IOException (java.io.IOException)2 Matchers.isSameType (com.google.errorprone.matchers.Matchers.isSameType)1 ASTHelpers.getType (com.google.errorprone.util.ASTHelpers.getType)1 EnvironmentException (com.redhat.ceylon.compiler.EnvironmentException)1 RepositoryException (com.redhat.ceylon.model.cmr.RepositoryException)1 MethodTree (com.sun.source.tree.MethodTree)1 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)1 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)1 Type (com.sun.tools.javac.code.Type)1 JavacFileManager (com.sun.tools.javac.file.JavacFileManager)1 JavaCompiler (com.sun.tools.javac.main.JavaCompiler)1 AnnotationProcessingError (com.sun.tools.javac.processing.AnnotationProcessingError)1 ClientCodeException (com.sun.tools.javac.util.ClientCodeException)1 JCDiagnostic (com.sun.tools.javac.util.JCDiagnostic)1 PropagatedException (com.sun.tools.javac.util.PropagatedException)1 Closeable (java.io.Closeable)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 JavaFileManager (javax.tools.JavaFileManager)1