Skip to content

Commit 4b182ee

Browse files
authored
Merge pull request #24 from salesforce/guw/ecj431
Update to ECJ 4.31 RC1
2 parents 968fb8f + e2757bf commit 4b182ee

File tree

272 files changed

+5978
-5179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

272 files changed

+5978
-5179
lines changed

compiler/src/main/ecj/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Eclipse Java Compiler
22

3-
We are using a patched version of ECJ 4.30 to incorporate fixes for:
3+
We are using a patched version of ECJ 4.31 RC1 to incorporate fixes for:
44

55
* None at this time
66

compiler/src/main/ecj/about.html

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml">
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
6+
<title>About</title>
7+
</head>
8+
<body lang="EN-US">
9+
<h2>About This Content</h2>
10+
11+
<p>November 30, 2017</p>
12+
<h3>License</h3>
13+
14+
<p>
15+
The Eclipse Foundation makes available all content in this plug-in
16+
(&quot;Content&quot;). Unless otherwise indicated below, the Content
17+
is provided to you under the terms and conditions of the Eclipse
18+
Public License Version 2.0 (&quot;EPL&quot;). A copy of the EPL is
19+
available at <a href="http://www.eclipse.org/legal/epl-2.0">http://www.eclipse.org/legal/epl-2.0</a>.
20+
For purposes of the EPL, &quot;Program&quot; will mean the Content.
21+
</p>
22+
23+
<p>
24+
If you did not receive this Content directly from the Eclipse
25+
Foundation, the Content is being redistributed by another party
26+
(&quot;Redistributor&quot;) and different terms and conditions may
27+
apply to your use of any object code in the Content. Check the
28+
Redistributor's license that was provided with the Content. If no such
29+
license exists, contact the Redistributor. Unless otherwise indicated
30+
below, the terms and conditions of the EPL still apply to any source
31+
code in the Content and such source code may be obtained at <a
32+
href="http://www.eclipse.org/">http://www.eclipse.org</a>.
33+
</p>
34+
35+
</body>
36+
</html>

compiler/src/main/ecj/org/eclipse/jdt/core/compiler/CharOperation.java

+2
Original file line numberDiff line numberDiff line change
@@ -4047,11 +4047,13 @@ public static final char[][] splitOn(
40474047
* For example:
40484048
* <ol>
40494049
* <li><pre>
4050+
* {@code
40504051
* divider = ','
40514052
* array = { 'A' , '<', 'B', ',', 'C', '>', ',', 'D' }
40524053
* start = 0
40534054
* end = 8
40544055
* result => { { 'A' , '<', 'B', ',', 'C', '>'}, { 'D' }}
4056+
* }
40554057
* </pre>
40564058
* </li>
40574059
* </ol>

compiler/src/main/ecj/org/eclipse/jdt/core/compiler/IProblem.java

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2023 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -353,7 +353,7 @@ public interface IProblem {
353353
/**
354354
* Problem Categories
355355
* The high bits of a problem ID contains information about the category of a problem.
356-
* For example, (problemID & TypeRelated) != 0, indicates that this problem is type related.
356+
* For example, (problemID &amp; TypeRelated) != 0, indicates that this problem is type related.
357357
*
358358
* A problem category can help to implement custom problem filters. Indeed, when numerous problems
359359
* are listed, focusing on import related problems first might be relevant.
@@ -2048,6 +2048,23 @@ public interface IProblem {
20482048
/** @since 3.14 */
20492049
int DuplicateResource = Internal + 1251;
20502050

2051+
/** @since 3.37 */
2052+
int ShouldMarkMethodAsOwning = Internal + 1260;
2053+
/** @since 3.37 */
2054+
int MandatoryCloseNotShown = Internal + 1261;
2055+
/** @since 3.37 */
2056+
int MandatoryCloseNotShownAtExit = Internal + 1262;
2057+
/** @since 3.37 */
2058+
int NotOwningResourceField = Internal + 1263;
2059+
/** @since 3.37 */
2060+
int OwningFieldInNonResourceClass = Internal + 1264;
2061+
/** @since 3.37 */
2062+
int OwningFieldShouldImplementClose = Internal + 1265;
2063+
/** @since 3.37 */
2064+
int OverrideReducingParamterOwning = Internal + 1266;
2065+
/** @since 3.37 */
2066+
int OverrideAddingReturnOwning = Internal + 1267;
2067+
20512068
// terminally
20522069
/** @since 3.14 */
20532070
int UsingTerminallyDeprecatedType = TypeRelated + 1400;
@@ -2564,4 +2581,15 @@ public interface IProblem {
25642581
* @since 3.35
25652582
*/
25662583
int SyntheticAccessorNotEnclosingMethod = MethodRelated + 1990;
2584+
2585+
/**
2586+
* @since 3.37
2587+
* @noreference preview feature
2588+
*/
2589+
int UnderscoreCannotBeUsedHere = PreviewRelated + 2000;
2590+
/**
2591+
* @since 3.37
2592+
* @noreference preview feature
2593+
*/
2594+
int UnnamedVariableMustHaveInitializer = PreviewRelated + 2001;
25672595
}

compiler/src/main/ecj/org/eclipse/jdt/internal/compiler/ClassFile.java

+70-13
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation;
8080
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
8181
import org.eclipse.jdt.internal.compiler.ast.StringLiteral;
82+
import org.eclipse.jdt.internal.compiler.ast.StringTemplate;
8283
import org.eclipse.jdt.internal.compiler.ast.SwitchStatement;
8384
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
8485
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
@@ -201,9 +202,10 @@ public class ClassFile implements TypeConstants, TypeIds {
201202
public static final String ENUMDESC_OF = "EnumDesc.of"; //$NON-NLS-1$
202203
public static final String CLASSDESC = "ClassDesc"; //$NON-NLS-1$
203204
public static final String CLASSDESC_OF = "ClassDesc.of"; //$NON-NLS-1$
205+
public static final String PROCESS_STRING = "process"; //$NON-NLS-1$
206+
public static final String NEW_STRING_TEMPLATE = "newStringTemplate"; //$NON-NLS-1$
204207
public static final String[] BOOTSTRAP_METHODS = { ALTMETAFACTORY_STRING, METAFACTORY_STRING, BOOTSTRAP_STRING,
205-
TYPESWITCH_STRING, ENUMSWITCH_STRING, CONCAT_CONSTANTS, INVOKE_STRING, ENUMDESC_OF, CLASSDESC, CLASSDESC_OF };
206-
208+
TYPESWITCH_STRING, ENUMSWITCH_STRING, CONCAT_CONSTANTS, INVOKE_STRING, ENUMDESC_OF, CLASSDESC, CLASSDESC_OF, PROCESS_STRING, NEW_STRING_TEMPLATE};
207209
/**
208210
* INTERNAL USE-ONLY
209211
* Request the creation of a ClassFile compatible representation of a problematic type
@@ -619,7 +621,7 @@ private int addFieldAttributes(FieldBinding fieldBinding, int fieldAttributeOffs
619621
int size = allTypeAnnotationContexts.size();
620622
attributesNumber = completeRuntimeTypeAnnotations(attributesNumber,
621623
null,
622-
(node) -> size > 0,
624+
node -> size > 0,
623625
() -> allTypeAnnotationContexts);
624626
}
625627
} finally {
@@ -672,7 +674,7 @@ private int addComponentAttributes(RecordComponentBinding recordComponentBinding
672674
int size = allTypeAnnotationContexts.size();
673675
attributesNumber = completeRuntimeTypeAnnotations(attributesNumber,
674676
null,
675-
(node) -> size > 0,
677+
node -> size > 0,
676678
() -> allTypeAnnotationContexts);
677679

678680
}
@@ -1761,7 +1763,7 @@ public int generateTypeAnnotationsOnCodeAttribute() {
17611763
int size = allTypeAnnotationContexts.size();
17621764
attributesNumber = completeRuntimeTypeAnnotations(attributesNumber,
17631765
null,
1764-
(node) -> size > 0,
1766+
node -> size > 0,
17651767
() -> allTypeAnnotationContexts);
17661768
return attributesNumber;
17671769
}
@@ -2473,7 +2475,7 @@ public void completeMethodInfo(
24732475
int size = allTypeAnnotationContexts.size();
24742476
attributesNumber = completeRuntimeTypeAnnotations(attributesNumber,
24752477
null,
2476-
(node) -> size > 0,
2478+
node -> size > 0,
24772479
() -> allTypeAnnotationContexts);
24782480
}
24792481
if ((this.produceAttributes & ClassFileConstants.ATTR_METHOD_PARAMETERS) != 0 ||
@@ -3667,6 +3669,8 @@ private int generateBootstrapMethods(List<Object> bootStrapMethodsList) {
36673669
localContentsOffset = addBootStrapTypeCaseConstantEntry(localContentsOffset, (ResolvedCase) o, fPtr);
36683670
} else if (o instanceof TypeBinding) {
36693671
localContentsOffset = addClassDescBootstrap(localContentsOffset, (TypeBinding) o, fPtr);
3672+
} else if (o instanceof StringTemplate template) {
3673+
localContentsOffset = addBootStrapTemplateRuntimeEntry(localContentsOffset, template, fPtr);
36703674
}
36713675
}
36723676

@@ -3836,7 +3840,7 @@ private int addBootStrapRecordEntry(int localContentsOffset, TypeDeclaration typ
38363840
String names =
38373841
Arrays.stream(recordComponents)
38383842
.map(f -> new String(f.name))
3839-
.reduce((s1, s2) -> { return s1 + ";" + s2;}) //$NON-NLS-1$
3843+
.reduce((s1, s2) -> (s1 + ";" + s2)) //$NON-NLS-1$
38403844
.orElse(Util.EMPTY_STRING);
38413845
int namesIndex = this.constantPool.literalIndex(names);
38423846
this.contents[localContentsOffset++] = (byte) (namesIndex >> 8);
@@ -4021,6 +4025,7 @@ private int addBootStrapEnumSwitchEntry(int localContentsOffset, SwitchStatement
40214025
int numArgsLocation = localContentsOffset;
40224026
CaseStatement.ResolvedCase[] constants = switchStatement.otherConstants;
40234027
int numArgs = constants.length;
4028+
if (switchStatement.containsNull) --numArgs;
40244029
this.contents[numArgsLocation++] = (byte) (numArgs >> 8);
40254030
this.contents[numArgsLocation] = (byte) numArgs;
40264031
localContentsOffset += 2;
@@ -4032,8 +4037,11 @@ private int addBootStrapEnumSwitchEntry(int localContentsOffset, SwitchStatement
40324037
this.contents[localContentsOffset++] = (byte) (typeIndex >> 8);
40334038
this.contents[localContentsOffset++] = (byte) typeIndex;
40344039
} else {
4040+
if (c.e instanceof NullLiteral) continue;
4041+
String s = c.e instanceof QualifiedNameReference qnr ? // handle superfluously qualified enumerator.
4042+
new String(qnr.tokens[qnr.tokens.length-1]) : c.e.toString();
40354043
int intValIdx =
4036-
this.constantPool.literalIndex(c.e.toString());
4044+
this.constantPool.literalIndex(s);
40374045
this.contents[localContentsOffset++] = (byte) (intValIdx >> 8);
40384046
this.contents[localContentsOffset++] = (byte) intValIdx;
40394047
}
@@ -4067,6 +4075,40 @@ private int addBootStrapStringConcatEntry(int localContentsOffset, String recipe
40674075

40684076
return localContentsOffset;
40694077
}
4078+
private int addBootStrapTemplateRuntimeEntry(int localContentsOffset, StringTemplate template, Map<String, Integer> fPtr) {
4079+
final int contentsEntries = 10;
4080+
int indexForProcess = fPtr.get(NEW_STRING_TEMPLATE);
4081+
if (contentsEntries + localContentsOffset >= this.contents.length) {
4082+
resizeContents(contentsEntries);
4083+
}
4084+
if (indexForProcess == 0) {
4085+
ReferenceBinding javaLangRuntimeTemplateBootstraps = this.referenceBinding.scope.getJavaLangRuntimeTemplateRuntimeBootstraps();
4086+
indexForProcess = this.constantPool.literalIndexForMethodHandle(ClassFileConstants.MethodHandleRefKindInvokeStatic, javaLangRuntimeTemplateBootstraps,
4087+
NEW_STRING_TEMPLATE.toCharArray(), ConstantPool.JAVA_LANG_RUNTIME_STRING_TEMPLATE_SIGNATURE, false);
4088+
fPtr.put(NEW_STRING_TEMPLATE, indexForProcess);
4089+
}
4090+
this.contents[localContentsOffset++] = (byte) (indexForProcess >> 8);
4091+
this.contents[localContentsOffset++] = (byte) indexForProcess;
4092+
4093+
// u2 num_bootstrap_arguments
4094+
int numArgsLocation = localContentsOffset;
4095+
StringLiteral[] fragments = template.fragments();
4096+
int numArgs = fragments.length;
4097+
this.contents[numArgsLocation++] = (byte) (numArgs >> 8);
4098+
this.contents[numArgsLocation] = (byte) numArgs;
4099+
localContentsOffset += 2;
4100+
4101+
if ((numArgs * 2) + localContentsOffset >= this.contents.length) {
4102+
resizeContents(numArgs * 2);
4103+
}
4104+
for (StringLiteral frag : fragments) {
4105+
int intValIdx =
4106+
this.constantPool.literalIndex(frag.constant.stringValue());
4107+
this.contents[localContentsOffset++] = (byte) (intValIdx >> 8);
4108+
this.contents[localContentsOffset++] = (byte) intValIdx;
4109+
}
4110+
return localContentsOffset;
4111+
}
40704112
private int generateLineNumberAttribute() {
40714113
int localContentsOffset = this.contentsOffset;
40724114
int attributesNumber = 0;
@@ -4399,7 +4441,7 @@ public int generateMethodInfoAttributes(MethodBinding methodBinding) {
43994441
int size = allTypeAnnotationContexts.size();
44004442
attributesNumber = completeRuntimeTypeAnnotations(attributesNumber,
44014443
null,
4402-
(node) -> size > 0,
4444+
node -> size > 0,
44034445
() -> allTypeAnnotationContexts);
44044446
}
44054447
}
@@ -4585,7 +4627,7 @@ public void addSyntheticDeserializeLambda(SyntheticMethodBinding methodBinding,
45854627
* That method generates the method info header of a clinit:
45864628
* The header consists in:
45874629
* - the access flags (always default access + static)
4588-
* - the name index of the method name (always <clinit>) inside the constant pool
4630+
* - the name index of the method name (always {@code <clinit>}) inside the constant pool
45894631
* - the descriptor index of the signature (always ()V) of the method inside the constant pool.
45904632
*/
45914633
public void generateMethodInfoHeaderForClinit() {
@@ -5137,7 +5179,10 @@ private int generateMethodParameters(final MethodBinding binding) {
51375179
for (int i = 0, max = targetParameters.length, argumentsLength = arguments != null ? arguments.length : 0; i < max; i++) {
51385180
if (argumentsLength > i && arguments[i] != null) {
51395181
Argument argument = arguments[i];
5140-
length = writeArgumentName(argument.name, argument.binding.modifiers, length);
5182+
int modifiers = argument.binding.modifiers;
5183+
if (binding.isCompactConstructor())
5184+
modifiers |= ClassFileConstants.AccMandated;
5185+
length = writeArgumentName(argument.name, modifiers, length);
51415186
} else {
51425187
length = writeArgumentName(null, ClassFileConstants.AccSynthetic, length);
51435188
}
@@ -5850,7 +5895,7 @@ private int generateTypeAnnotationAttributeForTypeDeclaration() {
58505895
int size = allTypeAnnotationContexts.size();
58515896
attributesNumber = completeRuntimeTypeAnnotations(attributesNumber,
58525897
null,
5853-
(node) -> size > 0,
5898+
node -> size > 0,
58545899
() -> allTypeAnnotationContexts);
58555900
return attributesNumber;
58565901
}
@@ -6394,6 +6439,13 @@ public int recordBootstrapMethod(String expression) {
63946439
this.bootstrapMethods.add(expression);
63956440
return this.bootstrapMethods.size() - 1;
63966441
}
6442+
public int recordBootstrapMethod(StringTemplate template) {
6443+
if (this.bootstrapMethods == null) {
6444+
this.bootstrapMethods = new ArrayList<>();
6445+
}
6446+
this.bootstrapMethods.add(template);
6447+
return this.bootstrapMethods.size() - 1;
6448+
}
63976449
public void reset(/*@Nullable*/SourceTypeBinding typeBinding, CompilerOptions options) {
63986450
// the code stream is reinitialized for each method
63996451
if (typeBinding != null) {
@@ -6530,7 +6582,7 @@ public int compare(StackMapFrame frame, StackMapFrame frame2) {
65306582
}
65316583

65326584
private TypeBinding getTypeBinding(char[] typeConstantPoolName, Scope scope, boolean checkcast) {
6533-
if (typeConstantPoolName.length == 1) {
6585+
if (typeConstantPoolName.length == 1 && !checkcast) {
65346586
// base type
65356587
switch(typeConstantPoolName[0]) {
65366588
case 'Z':
@@ -6828,6 +6880,7 @@ public List<StackMapFrame> traverse(
68286880
}
68296881
}
68306882
byte opcode = (byte) u1At(bytecodes, 0, pc);
6883+
inspectFrame(currentPC, frame);
68316884
switch (opcode) {
68326885
case Opcodes.OPC_nop:
68336886
pc++;
@@ -7811,6 +7864,10 @@ public List<StackMapFrame> traverse(
78117864
return filterFakeFrames(realJumpTarget, frames, codeLength);
78127865
}
78137866

7867+
private void inspectFrame(int currentPC, StackMapFrame frame) {
7868+
// Plant a breakpoint at the call site to conveniently hover.
7869+
}
7870+
78147871
private StackMapFrame createNewFrame(int currentPC, StackMapFrame frame, boolean isClinit, MethodBinding methodBinding) {
78157872
StackMapFrame newFrame = frame.duplicate();
78167873
newFrame.pc = currentPC;

compiler/src/main/ecj/org/eclipse/jdt/internal/compiler/apt/model/AnnotationValueImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,15 @@ public String toString() {
266266
return "null"; //$NON-NLS-1$
267267
} else if (this._value instanceof String) {
268268
String value = (String) this._value;
269-
StringBuffer sb = new StringBuffer();
269+
StringBuilder sb = new StringBuilder();
270270
sb.append('"');
271271
for (int i = 0; i < value.length(); i++) {
272272
Util.appendEscapedChar(sb, value.charAt(i), true);
273273
}
274274
sb.append('"');
275275
return sb.toString();
276276
} else if (this._value instanceof Character) {
277-
StringBuffer sb = new StringBuffer();
277+
StringBuilder sb = new StringBuilder();
278278
sb.append('\'');
279279
Util.appendEscapedChar(sb, ((Character) this._value).charValue(), false);
280280
sb.append('\'');

compiler/src/main/ecj/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java

+2
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ private JavaFileObject getFileObjectForType(TypeBinding binding) {
274274
}
275275
return null;
276276
}
277+
278+
@SuppressWarnings("resource") // fileManager is not created, must not be closed
277279
private JavaFileObject getSourceJavaFileObject(ReferenceContext referenceContext) {
278280
JavaFileManager fileManager = this._env.getFileManager();
279281
if (fileManager instanceof EclipseFileManager) {

compiler/src/main/ecj/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ public boolean isVarArgs() {
269269
* the inherited C.f() override A.f(). If B.f() were private, for instance, then in the context
270270
* of C it would still not override A.f().
271271
*
272+
* <p>see jls3 8.4.8 Inheritance, Overriding, and Hiding
273+
* <p>see jls3 9.4.1 Inheritance and Overriding
272274
* @see javax.lang.model.util.Elements#overrides(ExecutableElement, ExecutableElement, TypeElement)
273-
* @jls3 8.4.8 Inheritance, Overriding, and Hiding
274-
* @jls3 9.4.1 Inheritance and Overriding
275275
*/
276276
public boolean overrides(ExecutableElement overridden, TypeElement type)
277277
{

compiler/src/main/ecj/org/eclipse/jdt/internal/compiler/apt/model/Factory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public NoType getNoType(TypeKind kind)
443443

444444
/**
445445
* Get a type mirror object representing the specified primitive type kind.
446-
* @throw IllegalArgumentException if a non-primitive TypeKind is requested
446+
* @throws IllegalArgumentException if a non-primitive TypeKind is requested
447447
*/
448448
public PrimitiveTypeImpl getPrimitiveType(TypeKind kind)
449449
{

compiler/src/main/ecj/org/eclipse/jdt/internal/compiler/apt/model/TypeMirrorImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* Implementation of a TypeMirror. TypeMirror represents a type, including
3434
* types that have no declaration, such as primitives (int, boolean) and
35-
* types that are specializations of declarations (List<String>).
35+
* types that are specializations of declarations {@code (List<String>)}.
3636
*/
3737
public class TypeMirrorImpl implements TypeMirror {
3838

0 commit comments

Comments
 (0)