Skip to content

Commit e67393f

Browse files
committed
8310061: Note if implicit annotation processing is being used
Reviewed-by: vromero Backport-of: 3df36c4
1 parent 722794f commit e67393f

File tree

10 files changed

+340
-12
lines changed

10 files changed

+340
-12
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public boolean validate() {
458458

459459
if (!emptyAllowed) {
460460
if (!errors) {
461-
if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
461+
if (JavaCompiler.explicitAnnotationProcessingRequested(options, fileManager)) {
462462
reportDiag(Errors.NoSourceFilesClasses);
463463
} else {
464464
reportDiag(Errors.NoSourceFiles);

src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@
8484

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

87+
import com.sun.tools.javac.code.Lint;
88+
import com.sun.tools.javac.code.Lint.LintCategory;
8789
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
90+
8891
import com.sun.tools.javac.resources.CompilerProperties.Errors;
8992
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
9093
import com.sun.tools.javac.resources.CompilerProperties.Notes;
@@ -96,6 +99,7 @@
9699
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
97100

98101
import static javax.tools.StandardLocation.CLASS_OUTPUT;
102+
import static javax.tools.StandardLocation.ANNOTATION_PROCESSOR_PATH;
99103

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

239+
/** Whether or not the options lint category was initially disabled
240+
*/
241+
boolean optionsCheckingInitiallyDisabled;
242+
235243
/** Factory for creating diagnostic objects
236244
*/
237245
JCDiagnostic.Factory diagFactory;
@@ -424,6 +432,12 @@ public JavaCompiler(Context context) {
424432
moduleFinder.moduleNameFromSourceReader = this::readModuleName;
425433

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

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

11341148
if (processAnnotations) {
1149+
if (!explicitAnnotationProcessingRequested() &&
1150+
!optionsCheckingInitiallyDisabled) {
1151+
log.note(Notes.ImplicitAnnotationProcessing);
1152+
}
1153+
11351154
options.put("parameters", "parameters");
11361155
reader.saveParameterNames = true;
11371156
keepComments = true;
@@ -1279,18 +1298,19 @@ private boolean unrecoverableError() {
12791298
boolean explicitAnnotationProcessingRequested() {
12801299
return
12811300
explicitAnnotationProcessingRequested ||
1282-
explicitAnnotationProcessingRequested(options);
1301+
explicitAnnotationProcessingRequested(options, fileManager);
12831302
}
12841303

1285-
static boolean explicitAnnotationProcessingRequested(Options options) {
1304+
static boolean explicitAnnotationProcessingRequested(Options options, JavaFileManager fileManager) {
12861305
return
12871306
options.isSet(PROCESSOR) ||
12881307
options.isSet(PROCESSOR_PATH) ||
12891308
options.isSet(PROCESSOR_MODULE_PATH) ||
12901309
options.isSet(PROC, "only") ||
12911310
options.isSet(PROC, "full") ||
12921311
options.isSet(A) ||
1293-
options.isSet(XPRINT);
1312+
options.isSet(XPRINT) ||
1313+
fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH);
12941314
// Skipping -XprintRounds and -XprintProcessorInfo
12951315
}
12961316

src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ private void initProcessorIterator(Iterable<? extends Processor> processors) {
310310
* If the "-processor" option is used, search the appropriate
311311
* path for the named class. Otherwise, use a service
312312
* provider mechanism to create the processor iterator.
313+
*
314+
* Note: if an explicit processor path is not set,
315+
* only the class path and _not_ the module path are
316+
* searched for processors.
313317
*/
314318
String processorNames = options.get(Option.PROCESSOR);
315319
if (fileManager.hasLocation(ANNOTATION_PROCESSOR_MODULE_PATH)) {

src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,15 @@ compiler.note.proc.messager=\
17691769
compiler.note.multiple.elements=\
17701770
Multiple elements named ''{1}'' in modules ''{2}'' were found by javax.lang.model.util.Elements.{0}.
17711771

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

17741783
# 0: number

test/langtools/tools/javac/annotations/8218152/MalformedAnnotationProcessorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -115,7 +115,8 @@ public void testMissingAnnotationProcessor(Path base) throws Exception {
115115
.options("-XDrawDiagnostics",
116116
"-classpath", "",
117117
"-sourcepath", src.toString(),
118-
"-processorpath", apDir.toString())
118+
"-processorpath", apDir.toString(),
119+
"-Xlint:-options")
119120
.outdir(classes)
120121
.files(tb.findJavaFiles(src))
121122
.run(Expect.FAIL)

test/langtools/tools/javac/diags/examples.not-yet.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,4 @@ compiler.err.preview.without.source.or.release
214214
compiler.misc.illegal.signature # the compiler can now detect more non-denotable types before class writing
215215

216216
# this one needs a forged class file to be reproduced
217-
compiler.err.annotation.unrecognized.attribute.name
217+
compiler.err.annotation.unrecognized.attribute.name

test/langtools/tools/javac/diags/examples/ProcUseProcOrImplicit/ProcUseProcOrImplicit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,6 +22,7 @@
2222
*/
2323

2424
// key: compiler.warn.proc.use.proc.or.implicit
25+
// key: compiler.note.implicit.annotation.processing
2526
// options: -Xprefer:source
2627

2728
import p.SomeClass;

test/langtools/tools/javac/platform/PlatformProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -239,7 +239,7 @@ public Plugin getPlugin() {
239239

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

245245
@Override

test/langtools/tools/javac/processing/ReportOnImportedModuleAnnotation/ReportOnImportedModuleAnnotation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -71,7 +71,7 @@ public static void main(String[] args) throws Exception {
7171
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, List.of(testOutputPath));
7272

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

7676
String actualOutput = outputWriter.toString();
7777
String expectedOutput = Files.readString(testBasePath.resolve("ReportOnImportedModuleAnnotation.out"));

0 commit comments

Comments
 (0)