Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk21 Public archive

Commit

Permalink
8310061: Note if implicit annotation processing is being used
Browse files Browse the repository at this point in the history
Reviewed-by: vromero
Backport-of: 3df36c4f101e094d6f6beccadc004742b47d045a
  • Loading branch information
jddarcy committed Jun 29, 2023
1 parent 722794f commit e67393f
Show file tree
Hide file tree
Showing 10 changed files with 340 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public boolean validate() {

if (!emptyAllowed) {
if (!errors) {
if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
if (JavaCompiler.explicitAnnotationProcessingRequested(options, fileManager)) {
reportDiag(Errors.NoSourceFilesClasses);
} else {
reportDiag(Errors.NoSourceFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@

import static com.sun.tools.javac.code.Kinds.Kind.*;

import com.sun.tools.javac.code.Lint;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Symbol.ModuleSymbol;

import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
import com.sun.tools.javac.resources.CompilerProperties.Notes;
Expand All @@ -96,6 +99,7 @@
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;

import static javax.tools.StandardLocation.CLASS_OUTPUT;
import static javax.tools.StandardLocation.ANNOTATION_PROCESSOR_PATH;

import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
import com.sun.tools.javac.tree.JCTree.JCRecordPattern;
Expand Down Expand Up @@ -232,6 +236,10 @@ else if (option.equals("class"))
*/
public Log log;

/** Whether or not the options lint category was initially disabled
*/
boolean optionsCheckingInitiallyDisabled;

/** Factory for creating diagnostic objects
*/
JCDiagnostic.Factory diagFactory;
Expand Down Expand Up @@ -424,6 +432,12 @@ public JavaCompiler(Context context) {
moduleFinder.moduleNameFromSourceReader = this::readModuleName;

options = Options.instance(context);
// See if lint options checking was explicitly disabled by the
// user; this is distinct from the options check being
// enabled/disabled.
optionsCheckingInitiallyDisabled =
options.isSet(Option.XLINT_CUSTOM, "-options") ||
options.isSet(Option.XLINT_CUSTOM, "none");

verbose = options.isSet(VERBOSE);
sourceOutput = options.isSet(PRINTSOURCE); // used to be -s
Expand Down Expand Up @@ -1132,6 +1146,11 @@ public void initProcessAnnotations(Iterable<? extends Processor> processors,
processAnnotations = procEnvImpl.atLeastOneProcessor();

if (processAnnotations) {
if (!explicitAnnotationProcessingRequested() &&
!optionsCheckingInitiallyDisabled) {
log.note(Notes.ImplicitAnnotationProcessing);
}

options.put("parameters", "parameters");
reader.saveParameterNames = true;
keepComments = true;
Expand Down Expand Up @@ -1279,18 +1298,19 @@ private boolean unrecoverableError() {
boolean explicitAnnotationProcessingRequested() {
return
explicitAnnotationProcessingRequested ||
explicitAnnotationProcessingRequested(options);
explicitAnnotationProcessingRequested(options, fileManager);
}

static boolean explicitAnnotationProcessingRequested(Options options) {
static boolean explicitAnnotationProcessingRequested(Options options, JavaFileManager fileManager) {
return
options.isSet(PROCESSOR) ||
options.isSet(PROCESSOR_PATH) ||
options.isSet(PROCESSOR_MODULE_PATH) ||
options.isSet(PROC, "only") ||
options.isSet(PROC, "full") ||
options.isSet(A) ||
options.isSet(XPRINT);
options.isSet(XPRINT) ||
fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH);
// Skipping -XprintRounds and -XprintProcessorInfo
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ private void initProcessorIterator(Iterable<? extends Processor> processors) {
* If the "-processor" option is used, search the appropriate
* path for the named class. Otherwise, use a service
* provider mechanism to create the processor iterator.
*
* Note: if an explicit processor path is not set,
* only the class path and _not_ the module path are
* searched for processors.
*/
String processorNames = options.get(Option.PROCESSOR);
if (fileManager.hasLocation(ANNOTATION_PROCESSOR_MODULE_PATH)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,15 @@ compiler.note.proc.messager=\
compiler.note.multiple.elements=\
Multiple elements named ''{1}'' in modules ''{2}'' were found by javax.lang.model.util.Elements.{0}.

compiler.note.implicit.annotation.processing=\
Annotation processing is enabled because one or more processors were found\n\
on the class path. A future release of javac may disable annotation processing\n\
unless at least one processor is specified by name (-processor), or a search\n\
path is specified (--processor-path, --processor-module-path), or annotation\n\
processing is enabled explicitly (-proc:only, -proc:full).\n\
Use -Xlint:-options to suppress this message.\n\
Use -proc:none to disable annotation processing.

#####

# 0: number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -115,7 +115,8 @@ public void testMissingAnnotationProcessor(Path base) throws Exception {
.options("-XDrawDiagnostics",
"-classpath", "",
"-sourcepath", src.toString(),
"-processorpath", apDir.toString())
"-processorpath", apDir.toString(),
"-Xlint:-options")
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Expect.FAIL)
Expand Down
2 changes: 1 addition & 1 deletion test/langtools/tools/javac/diags/examples.not-yet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,4 @@ compiler.err.preview.without.source.or.release
compiler.misc.illegal.signature # the compiler can now detect more non-denotable types before class writing

# this one needs a forged class file to be reproduced
compiler.err.annotation.unrecognized.attribute.name
compiler.err.annotation.unrecognized.attribute.name
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,6 +22,7 @@
*/

// key: compiler.warn.proc.use.proc.or.implicit
// key: compiler.note.implicit.annotation.processing
// options: -Xprefer:source

import p.SomeClass;
Expand Down
4 changes: 2 additions & 2 deletions test/langtools/tools/javac/platform/PlatformProviderTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -239,7 +239,7 @@ public Plugin getPlugin() {

@Override
public List<String> getAdditionalOptions() {
return Arrays.asList("-Xlint:rawtypes", "-XDrawDiagnostics");
return Arrays.asList("-Xlint:rawtypes", "-XDrawDiagnostics", "-proc:full");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -71,7 +71,7 @@ public static void main(String[] args) throws Exception {
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, List.of(testOutputPath));

final StringWriter outputWriter = new StringWriter();
compiler.getTask(outputWriter, fileManager, null, List.of("-XDrawDiagnostics", "--module", "mod"), null, null).call();
compiler.getTask(outputWriter, fileManager, null, List.of("-XDrawDiagnostics", "--module", "mod", "-proc:full"), null, null).call();

String actualOutput = outputWriter.toString();
String expectedOutput = Files.readString(testBasePath.resolve("ReportOnImportedModuleAnnotation.out"));
Expand Down
Loading

3 comments on commit e67393f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JesperIRL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/tag jdk-21+29

@openjdk
Copy link

@openjdk openjdk bot commented on e67393f Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JesperIRL The tag jdk-21+29 was successfully created.

Please sign in to comment.