Skip to content

Commit 58fed7e

Browse files
authored
Merge branch 'eclipse-jdt:master' into master
2 parents 42cf53c + 006800c commit 58fed7e

11 files changed

Lines changed: 328 additions & 40 deletions

File tree

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,11 +1455,10 @@ public ReferenceBinding[] superInterfaces() {
14551455
}
14561456
}
14571457
if (CapturingContext.isActive()) {
1458-
ReferenceBinding[] captured = new ReferenceBinding[this.superInterfaces.length];
1459-
for (int i = 0; i < captured.length; i++) {
1460-
captured[i] = CapturingContext.maybeCapture(this.superInterfaces[i]);
1461-
}
1462-
return captured;
1458+
ReferenceBinding capturedThis = CapturingContext.maybeCapture(this);
1459+
if (capturedThis != this) { //$IDENTITY-COMPARISON$
1460+
return capturedThis.superInterfaces();
1461+
}
14631462
}
14641463
return this.superInterfaces;
14651464
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ protected boolean commentParse() {
181181
boolean isDomParser = (this.kind & DOM_PARSER) != 0;
182182
boolean isFormatterParser = (this.kind & FORMATTER_COMMENT_PARSER) != 0;
183183
int lastStarPosition = -1;
184+
boolean annotationAtSymbolHandling = false;
184185

185186
// Init scanner position
186187
this.markdown = this.source[this.javadocStart + 1] == '/';
@@ -260,7 +261,7 @@ protected boolean commentParse() {
260261
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206345: ignore all tags when inside @literal or @code tags
261262
if (considerTagAsPlainText || this.markdownHelper.isInCode()) {
262263
// new tag found
263-
if (!this.lineStarted) {
264+
if (!this.lineStarted && !checkInlineTagForAnnotaion()) {
264265
// we may want to report invalid syntax when no closing brace found,
265266
// or when incoherent number of closing braces found
266267
if (openingBraces > 0 && this.reportProblems) {
@@ -341,9 +342,10 @@ protected boolean commentParse() {
341342
textEndPosition = previousPosition;
342343
}
343344
if (this.textStart != -1 && this.textStart < textEndPosition) {
344-
pushText(this.textStart, textEndPosition);
345+
pushText(annotationAtSymbolHandling ? this.textStart - 1 : this.textStart, textEndPosition);
345346
}
346347
}
348+
annotationAtSymbolHandling = false;
347349
this.lineStarted = false;
348350
lineHasStar = false;
349351
// Fix bug 51650
@@ -529,6 +531,9 @@ protected boolean commentParse() {
529531
if (!this.lineStarted || this.textStart == -1) {
530532
this.textStart = previousPosition;
531533
}
534+
if (previousChar == '@' && checkInlineTagForAnnotaion()) {
535+
annotationAtSymbolHandling = true;
536+
}
532537
this.lineStarted = true;
533538
textEndPosition = this.index;
534539
break;
@@ -590,6 +595,10 @@ protected boolean shouldAbortDueToJavadocTag(int currPos) {
590595
return false;
591596
}
592597

598+
protected boolean checkInlineTagForAnnotaion() {
599+
return (this.tagValue == TAG_SNIPPET_VALUE || this.tagValue == TAG_CODE_VALUE || this.tagValue == TAG_LITERAL_VALUE);
600+
}
601+
593602
protected void addFragmentToInlineReturn() {
594603
// do nothing
595604
}

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,9 @@ Excuse excuseFor(JavacCompiler compiler) {
11911191
JavacBug8348410 = // https://bugs.openjdk.org/browse/JDK-8348410
11921192
new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK25, 0000),
11931193
JavacBug8016196 = // https://bugs.openjdk.org/browse/JDK-8016196
1194-
new JavacHasABug(MismatchType.JavacErrorsEclipseNone);
1195-
1194+
new JavacHasABug(MismatchType.JavacErrorsEclipseNone),
1195+
JavacBug8016207 = // https://bugs.openjdk.org/browse/JDK-8016207 Widening of capture vars occurs at unspecified times
1196+
new JavacHasABug(MismatchType.EclipseErrorsJavacNone);
11961197

11971198
// bugs that have been fixed but that we've not identified
11981199
public static JavacHasABug

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_9.java

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Map;
1717
import junit.framework.Test;
1818
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.JavacHasABug;
19+
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.Excuse;
1920
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
2021
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
2122

@@ -380,9 +381,10 @@ public void testBug488663_012() {
380381
}
381382
// Redundant type argument specification - TODO - confirm that this is correct
382383
public void testBug488663_013() {
383-
Map<String, String> options = getCompilerOptions();
384-
options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
385-
this.runNegativeTest(
384+
Runner runner = new Runner();
385+
runner.customOptions = getCompilerOptions();
386+
runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
387+
runner.testFiles =
386388
new String[] {
387389
"X.java",
388390
"public class X {\n" +
@@ -406,14 +408,16 @@ public void testBug488663_013() {
406408
"interface I<T> {\n" +
407409
" String toString(T t);\n" +
408410
"}"
409-
},
411+
};
412+
runner.expectedCompilerLog =
410413
"----------\n" +
411414
"1. ERROR in X.java (at line 11)\n" +
412415
" I<X> i = new I<X>() {\n" +
413416
" ^\n" +
414417
"Redundant specification of type arguments <X>\n" +
415-
"----------\n",
416-
null, true, options);
418+
"----------\n";
419+
runner.javacTestOptions = Excuse.EclipseWarningConfiguredAsError;
420+
runner.runNegativeTest();
417421
}
418422
// All non-private methods of an anonymous class instantiated with '<>' must be treated as being annotated with @override
419423
public void testBug488663_014() {
@@ -602,7 +606,8 @@ public void testBug521815b() {
602606
if (this.complianceLevel <= ClassFileConstants.JDK1_8) {
603607
return;
604608
}
605-
runNegativeTest(
609+
Runner runner = new Runner();
610+
runner.testFiles =
606611
new String[] {
607612
"a/b/X.java",
608613
"package a.b;\n" +
@@ -618,13 +623,16 @@ public void testBug521815b() {
618623
"import static a.b.X.Inner;\n" +
619624
"public class Y {;\n" +
620625
"}\n"
621-
},
626+
};
627+
runner.expectedCompilerLog =
622628
"----------\n" +
623629
"1. WARNING in a\\Y.java (at line 2)\n" +
624630
" import static a.b.X.Inner;\n" +
625631
" ^^^^^^^^^^^\n" +
626632
"The import a.b.X.Inner is never used\n" +
627-
"----------\n");
633+
"----------\n";
634+
runner.javacTestOptions = Excuse.EclipseHasSomeMoreWarnings;
635+
runner.runWarningTest();
628636
}
629637
public void testBug533644() {
630638
runConformTest(
@@ -702,9 +710,10 @@ public void testBug551913_001() {
702710
// "Remove redundant type arguments" diagnostic should be reported ONLY if all the non-private methods defined in the anonymous class
703711
// are also present in the parent class.
704712
public void testBug551913_002() {
705-
Map<String, String> options = getCompilerOptions();
706-
options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
707-
this.runNegativeTest(
713+
Runner runner = new Runner();
714+
runner.customOptions = getCompilerOptions();
715+
runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
716+
runner.testFiles =
708717
new String[] {
709718
"X.java",
710719
"public class X {\n" +
@@ -716,22 +725,25 @@ public void testBug551913_002() {
716725
" };\n" +
717726
" }\n" +
718727
"}",
719-
},
728+
};
729+
runner.expectedCompilerLog =
720730
"----------\n" +
721731
"1. ERROR in X.java (at line 4)\n" +
722732
" java.util.HashSet<String> b = new java.util.HashSet<String>(a) {\n" +
723733
" ^^^^^^^\n" +
724734
"Redundant specification of type arguments <String>\n" +
725-
"----------\n",
726-
null, true, options);
735+
"----------\n";
736+
runner.javacTestOptions = Excuse.EclipseWarningConfiguredAsError;
737+
runner.runNegativeTest();
727738
}
728739

729740
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1506
730741
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=551913
731742
public void testBug551913_003() {
732-
Map<String, String> options = getCompilerOptions();
733-
options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
734-
this.runNegativeTest(
743+
Runner runner = new Runner();
744+
runner.customOptions = getCompilerOptions();
745+
runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
746+
runner.testFiles =
735747
new String[] {
736748
"X.java",
737749
"public class X {\n" +
@@ -744,14 +756,16 @@ public void testBug551913_003() {
744756
" };\n" +
745757
" }\n" +
746758
"}",
747-
},
759+
};
760+
runner.expectedCompilerLog =
748761
"----------\n" +
749762
"1. ERROR in X.java (at line 4)\n" +
750763
" java.util.HashSet<String> b = new java.util.HashSet<String>(a) {\n" +
751764
" ^^^^^^^\n" +
752765
"Redundant specification of type arguments <String>\n" +
753-
"----------\n",
754-
null, true, options);
766+
"----------\n";
767+
runner.javacTestOptions = Excuse.EclipseWarningConfiguredAsError;
768+
runner.runNegativeTest();
755769
}
756770
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1506
757771
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=551913
@@ -811,9 +825,10 @@ public void testGH1506() {
811825
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1506
812826
// Recommendation from compiler to drop type arguments leads to compile error
813827
public void testGH1506_2() {
814-
Map<String, String> options = getCompilerOptions();
815-
options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
816-
this.runNegativeTest(
828+
Runner runner = new Runner();
829+
runner.customOptions = getCompilerOptions();
830+
runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
831+
runner.testFiles =
817832
new String[] {
818833
"X.java",
819834
"import java.io.File;\n" +
@@ -837,14 +852,16 @@ public void testGH1506_2() {
837852
" };\n" +
838853
" }\n" +
839854
"}\n",
840-
},
855+
};
856+
runner.expectedCompilerLog =
841857
"----------\n"
842858
+ "1. ERROR in X.java (at line 8)\n"
843859
+ " return new Iterable<File>() {\n"
844860
+ " ^^^^^^^^\n"
845861
+ "Redundant specification of type arguments <File>\n"
846-
+ "----------\n",
847-
null, true, options);
862+
+ "----------\n";
863+
runner.javacTestOptions = Excuse.EclipseWarningConfiguredAsError;
864+
runner.runNegativeTest();
848865
}
849866
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1506
850867
// Recommendation from compiler to drop type arguments leads to compile error
@@ -2244,6 +2261,40 @@ The method consume(List<? extends Test.A<? super U>>) in the type Test is not ap
22442261
runner.javacTestOptions = JavacHasABug.JavacBug6573446;
22452262
runner.runNegativeTest();
22462263
}
2264+
public void testGH4731() {
2265+
Runner runner = new Runner();
2266+
runner.testFiles = new String[] {
2267+
"TestWildcard.java",
2268+
"""
2269+
import java.util.Collection;
2270+
import java.util.Iterator;
2271+
2272+
public class TestWildcard {
2273+
2274+
private Collection<? extends Collection<? extends Runnable>> _parts;
2275+
2276+
public Iterator<Runnable> iterator() {
2277+
return TestWildcard.concat(_parts).iterator();
2278+
}
2279+
2280+
public static <T> Iterable<T> concat(Iterable<? extends Iterable<? extends T>> entries) {
2281+
return null;
2282+
}
2283+
2284+
}
2285+
"""
2286+
};
2287+
runner.expectedCompilerLog = """
2288+
----------
2289+
1. ERROR in TestWildcard.java (at line 9)
2290+
return TestWildcard.concat(_parts).iterator();
2291+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2292+
Type mismatch: cannot convert from Iterator<capture#2-of ? extends Runnable> to Iterator<Runnable>
2293+
----------
2294+
""";
2295+
runner.javacTestOptions = JavacHasABug.JavacBug8016207;
2296+
runner.runNegativeTest();
2297+
}
22472298
public static Class<GenericsRegressionTest_9> testClass() {
22482299
return GenericsRegressionTest_9.class;
22492300
}

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,4 +3690,86 @@ public class Markdown {}
36903690
assumeEquals("Invalid eighth TextElement content","}" , textFrags.get(7).getText());
36913691
assumeEquals("Invalid nineth TextElement content","return -1;" , textFrags.get(8).getText());
36923692
}
3693+
3694+
public void testJavadocIncorrectlyParsingAnnotationInlineTag5055_01() throws JavaModelException {
3695+
this.workingCopies = new ICompilationUnit[1];
3696+
this.astLevel = AST.JLS25;
3697+
this.workingCopies[0] = getWorkingCopy("/Converter25/src/javadoc/Javadoc.java",
3698+
"""
3699+
/**
3700+
* Example showing formatter bug with {@code @} in pre blocks.
3701+
*
3702+
* <pre>
3703+
* {@code
3704+
* @MyAnnotation
3705+
* public class Example {
3706+
* @AnotherAnnotation
3707+
* private String field;
3708+
* }
3709+
* }
3710+
* </pre>
3711+
*/
3712+
public class Javadoc{}
3713+
"""
3714+
);
3715+
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
3716+
List unitComments = compilUnit.getCommentList();
3717+
assertEquals("Wrong number of comments", 1, unitComments.size());
3718+
Comment comment = (Comment) unitComments.get(0);
3719+
assertEquals("Comment should be javadoc", comment.getNodeType(), ASTNode.JAVADOC);
3720+
Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0);
3721+
assumeEquals("wrong number of tags", 1, docComment.tags().size());
3722+
TagElement parentTag = (TagElement) docComment.tags().get(0);
3723+
List<?> frags = parentTag.fragments();
3724+
assumeEquals("wrong number of Parent elements", 1, docComment.tags().size());
3725+
TagElement firstInnerTag = (TagElement) frags.get(1);
3726+
TagElement secondInnerTag = (TagElement) frags.get(4);
3727+
assertTrue(firstInnerTag.getNodeType() == ASTNode.TAG_ELEMENT && firstInnerTag.toString().contains("{@code @}"));
3728+
assertTrue(secondInnerTag.getNodeType() == ASTNode.TAG_ELEMENT);
3729+
List<TextElement> innerFrags = secondInnerTag.fragments();
3730+
assumeEquals("wrong number of Child elements", 5, innerFrags.size());
3731+
assumeEquals("Incorrect child content", "@MyAnnotation", innerFrags.get(0).getText());
3732+
assumeEquals("Incorrect child content", "@AnotherAnnotation", innerFrags.get(2).getText());
3733+
}
3734+
3735+
public void testJavadocIncorrectlyParsingAnnotationInlineTag5055_02() throws JavaModelException {
3736+
this.workingCopies = new ICompilationUnit[1];
3737+
this.astLevel = AST.JLS25;
3738+
this.workingCopies[0] = getWorkingCopy("/Converter25/src/javadoc/Javadoc.java",
3739+
"""
3740+
/**
3741+
* Example showing formatter bug with {@code @} in pre blocks.
3742+
*
3743+
* <pre>
3744+
* {@literal
3745+
* @MyAnnotation
3746+
* public class Example {
3747+
* @AnotherAnnotation
3748+
* private String field;
3749+
* }
3750+
* }
3751+
* </pre>
3752+
*/
3753+
public class Javadoc{}
3754+
"""
3755+
);
3756+
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
3757+
List unitComments = compilUnit.getCommentList();
3758+
assertEquals("Wrong number of comments", 1, unitComments.size());
3759+
Comment comment = (Comment) unitComments.get(0);
3760+
assertEquals("Comment should be javadoc", comment.getNodeType(), ASTNode.JAVADOC);
3761+
Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0);
3762+
assumeEquals("wrong number of tags", 1, docComment.tags().size());
3763+
TagElement parentTag = (TagElement) docComment.tags().get(0);
3764+
List<?> frags = parentTag.fragments();
3765+
assumeEquals("wrong number of Parent elements", 1, docComment.tags().size());
3766+
TagElement firstInnerTag = (TagElement) frags.get(1);
3767+
TagElement secondInnerTag = (TagElement) frags.get(4);
3768+
assertTrue(firstInnerTag.getNodeType() == ASTNode.TAG_ELEMENT && firstInnerTag.toString().contains("{@code @}"));
3769+
assertTrue(secondInnerTag.getNodeType() == ASTNode.TAG_ELEMENT);
3770+
List<TextElement> innerFrags = secondInnerTag.fragments();
3771+
assumeEquals("wrong number of Child elements", 5, innerFrags.size());
3772+
assumeEquals("Incorrect child content", "@MyAnnotation", innerFrags.get(0).getText());
3773+
assumeEquals("Incorrect child content", "@AnotherAnnotation", innerFrags.get(2).getText());
3774+
}
36933775
}

0 commit comments

Comments
 (0)