Skip to content

Commit

Permalink
Merge branch 'master' into DOM-Support-for-implicitly-declared-classe…
Browse files Browse the repository at this point in the history
…s-2294-new
  • Loading branch information
mpalat authored Oct 11, 2024
2 parents 9f1d366 + 8253f4b commit a5940f3
Show file tree
Hide file tree
Showing 36 changed files with 1,310 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
uses: actions/upload-artifact@84480863f228bb9747b473957fcc9e309aa96097 # v4.4.2
with:
name: Event File
path: ${{ github.event_path }}
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
mvn -U clean verify --batch-mode --fail-at-end -Ptest-on-javase-21 -Pbree-libs -Papi-check -Djava.io.tmpdir=$WORKSPACE/tmp -Dproject.build.sourceEncoding=UTF-8 -Dtycho.surefire.argLine="--add-modules ALL-SYSTEM -Dcompliance=1.8,11,17,20 -Djdt.performance.asserts=disabled" -Dcbi-ecj-version=99.99
- name: Upload Test Results for Linux
if: always()
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
uses: actions/upload-artifact@84480863f228bb9747b473957fcc9e309aa96097 # v4.4.2
with:
name: test-results-linux
if-no-files-found: warn
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ For more information and important links, refer to the [JDT wiki page](https://g

[Contributions are always welcome!](https://github.com/eclipse-jdt/.github/blob/main/CONTRIBUTING.md)

Please bear in mind that this project is almost entirely developed by volunteers. If you do not provide the implementation yourself (or pay someone to do it for you), the bug might never get fixed. If it is a serious bug, other people than you might care enough to provide a fix.
Please bear in mind that this project is almost entirely developed by volunteers.
If you do not provide the implementation yourself (or pay someone to do it for you), the bug might never get fixed.
If it is a serious bug, other people than you might care enough to provide a fix.

## License

Expand All @@ -28,4 +30,4 @@ Please bear in mind that this project is almost entirely developed by volunteers

- https://github.com/eclipse-jdt/eclipse.jdt.core/wiki
- https://github.com/eclipse-jdt/.github/blob/main/CONTRIBUTING.md
- http://www.eclipse.org/projects/project.php?id=eclipse.jdt
- https://projects.eclipse.org/projects/eclipse.jdt
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,11 @@ public interface IProblem {
/** @since 3.1 */
int DiscouragedReference = TypeRelated + 280;

/**
* @since 3.40
*/
int LambdaParameterIsNeverUsed = Internal + 281;

int InterfaceCannotHaveInitializers = TypeRelated + 300;
int DuplicateModifierForType = TypeRelated + 301;
int IllegalModifierForClass = TypeRelated + 302;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler;

import java.lang.ref.SoftReference;
import java.util.*;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.parser.RecoveryScannerData;
import org.eclipse.jdt.internal.compiler.util.Util;

/**
* A compilation result consists of all information returned by the compiler for
* a single compiled compilation source unit. This includes:
Expand All @@ -34,19 +48,6 @@
* specific fields and methods which were referenced, but does contain their
* declaring types and any other types used to locate such fields or methods.
*/
import java.util.*;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.parser.RecoveryScannerData;
import org.eclipse.jdt.internal.compiler.util.Util;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class CompilationResult {

Expand Down Expand Up @@ -77,6 +78,8 @@ public class CompilationResult {
private boolean hasMandatoryErrors;
public List<AnnotationBinding[]> annotations = new ArrayList<>(1);
private List<Runnable> scheduledProblems;
private volatile boolean cacheSource;
private volatile SoftReference<char[]> contentRef;

private static final int[] EMPTY_LINE_ENDS = Util.EMPTY_INT_ARRAY;
private static final Comparator PROBLEM_COMPARATOR = new Comparator() {
Expand Down Expand Up @@ -481,4 +484,29 @@ public void materializeProblems() {
}
}
}

public void cacheSource() {
this.cacheSource = true;
}

public char[] getContents() {
SoftReference<char[]> cr = this.contentRef;
if (cr != null) {
char[] cachedContents = cr.get();
if (cachedContents != null) {
return cachedContents;
}
}
return this.compilationUnit.getContents();
}

public void cacheContents(char[] contents) {
if (this.cacheSource) {
this.contentRef = new SoftReference<>(contents);
}
}

public void releaseContent() {
this.contentRef = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ protected void internalBeginToCompile(ICompilationUnit[] sourceUnits, int maxUni
if (this.totalUnits < this.parseThreshold) {
parsedUnit = this.parser.parse(sourceUnits[i], unitResult);
} else {
unitResult.cacheSource();
parsedUnit = this.parser.dietParse(sourceUnits[i], unitResult);
}
long resolveStart = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,16 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
int nullPatternCount = 0;
for (int i = 0, length = this.constantExpressions.length; i < length; i++) {
Expression e = this.constantExpressions[i];
for (LocalVariableBinding local : e.bindingsWhenTrue()) {
local.useFlag = LocalVariableBinding.USED; // these are structurally required even if not touched
CompilerOptions compilerOptions = currentScope.compilerOptions();
long sourceLevel = compilerOptions.sourceLevel;
boolean enablePreviewFeatures = compilerOptions.enablePreviewFeatures;
if (!JavaFeature.UNNAMMED_PATTERNS_AND_VARS.isSupported(sourceLevel, enablePreviewFeatures)) {
for (LocalVariableBinding local : e.bindingsWhenTrue()) {
local.useFlag = LocalVariableBinding.USED; // these are structurally required even if not touched
}
}
nullPatternCount += e instanceof NullLiteral ? 1 : 0;
if (i > 0 && (e instanceof Pattern) && !JavaFeature.UNNAMMED_PATTERNS_AND_VARS.isSupported(currentScope.compilerOptions().sourceLevel, currentScope.compilerOptions().enablePreviewFeatures)) {
if (i > 0 && (e instanceof Pattern) && !JavaFeature.UNNAMMED_PATTERNS_AND_VARS.isSupported(sourceLevel, enablePreviewFeatures)) {
if (!(i == nullPatternCount && e instanceof TypePattern))
currentScope.problemReporter().IllegalFallThroughToPattern(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,24 +430,21 @@ public static boolean checkUnsafeCast(Expression expression, Scope scope, TypeBi
ParameterizedTypeBinding paramCastType = (ParameterizedTypeBinding) castType;
TypeBinding[] castArguments = paramCastType.arguments;
int length = castArguments == null ? 0 : castArguments.length;
if ((paramCastType.tagBits & (TagBits.HasDirectWildcard|TagBits.HasTypeVariable)) != 0) {
// verify alternate cast type, substituting different type arguments
for (int i = 0; i < length; i++) {
if (castArguments[i].isUnboundWildcard())
continue;
TypeBinding[] alternateArguments;
// need to clone for each iteration to avoid env paramtype cache interference
System.arraycopy(paramCastType.arguments, 0, alternateArguments = new TypeBinding[length], 0, length);
alternateArguments[i] = TypeBinding.equalsEquals(paramCastType.arguments[i], scope.getJavaLangObject()) ? scope.getJavaLangBoolean() : scope.getJavaLangObject();
LookupEnvironment environment = scope.environment();
ParameterizedTypeBinding alternateCastType = environment.createParameterizedType((ReferenceBinding)castType.erasure(), alternateArguments, castType.enclosingType());
if (TypeBinding.equalsEquals(alternateCastType.findSuperTypeOriginatingFrom(expressionType), match)) {
expression.bits |= ASTNode.UnsafeCast;
break;
}
// verify alternate cast type, substituting different type arguments
for (int i = 0; i < length; i++) {
if (castArguments[i].isUnboundWildcard())
continue;
TypeBinding[] alternateArguments;
// need to clone for each iteration to avoid env paramtype cache interference
System.arraycopy(paramCastType.arguments, 0, alternateArguments = new TypeBinding[length], 0, length);
alternateArguments[i] = TypeBinding.equalsEquals(paramCastType.arguments[i], scope.getJavaLangObject()) ? scope.getJavaLangBoolean() : scope.getJavaLangObject();
LookupEnvironment environment = scope.environment();
ParameterizedTypeBinding alternateCastType = environment.createParameterizedType((ReferenceBinding)castType.erasure(), alternateArguments, castType.enclosingType());
if (TypeBinding.equalsEquals(alternateCastType.findSuperTypeOriginatingFrom(expressionType), match)) {
expression.bits |= ASTNode.UnsafeCast;
break;
}
}

// Type arguments added by subtypes of S and removed by supertypes of T don't need to be checked since the type arguments aren't specified by either S or T
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public void cleanUp() {

if (this.scope != null)
this.scope.cleanUpInferenceContexts();
this.compilationResult.releaseContent();
}

private void cleanUp(TypeDeclaration type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.impl.JavaFeature;
import org.eclipse.jdt.internal.compiler.lookup.*;

public class TryStatement extends SubRoutineStatement {
Expand Down Expand Up @@ -181,7 +182,12 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
}
}
if (localVariableBinding != null) {
localVariableBinding.useFlag = LocalVariableBinding.USED; // Is implicitly used anyways.
CompilerOptions compilerOptions = currentScope.compilerOptions();
long sourceLevel = compilerOptions.sourceLevel;
boolean enablePreviewFeatures = compilerOptions.enablePreviewFeatures;
if (!JavaFeature.UNNAMMED_PATTERNS_AND_VARS.isSupported(sourceLevel, enablePreviewFeatures)) {
localVariableBinding.useFlag = LocalVariableBinding.USED; // Is implicitly used anyways.
}
}
MethodBinding closeMethod = findCloseMethod(resource, resolvedType);
if (closeMethod != null && closeMethod.isValidBinding() && closeMethod.returnType.id == TypeIds.T_void) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
import org.eclipse.jdt.internal.compiler.flow.FlowContext;
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.impl.JavaFeature;
import org.eclipse.jdt.internal.compiler.lookup.*;
Expand Down Expand Up @@ -233,8 +234,11 @@ public TypeBinding resolveType(BlockScope scope) {
this.local.resolve(scope, true);
if (this.local.binding != null) {
this.local.binding.modifiers |= ExtraCompilerModifiers.AccOutOfFlowScope; // start out this way, will be BlockScope.include'd when definitely assigned
if (enclosingPattern != null)
this.local.binding.useFlag = LocalVariableBinding.USED; // syntactically required even if untouched
CompilerOptions compilerOptions = scope.compilerOptions();
if (!JavaFeature.UNNAMMED_PATTERNS_AND_VARS.isSupported(compilerOptions.sourceLevel, compilerOptions.enablePreviewFeatures)) {
if (enclosingPattern != null)
this.local.binding.useFlag = LocalVariableBinding.USED; // syntactically required even if untouched
}
if (this.local.type != null)
this.resolvedType = this.local.binding.type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class CompilerOptions {
public static final String OPTION_ReportDeprecationWhenOverridingDeprecatedMethod = "org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod"; //$NON-NLS-1$
public static final String OPTION_ReportHiddenCatchBlock = "org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock"; //$NON-NLS-1$
public static final String OPTION_ReportUnusedLocal = "org.eclipse.jdt.core.compiler.problem.unusedLocal"; //$NON-NLS-1$
public static final String OPTION_ReportUnusedLambdaParameter = "org.eclipse.jdt.core.compiler.problem.unusedLambdaParameter"; //$NON-NLS-1$
public static final String OPTION_ReportUnusedParameter = "org.eclipse.jdt.core.compiler.problem.unusedParameter"; //$NON-NLS-1$
public static final String OPTION_ReportUnusedExceptionParameter = "org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter"; //$NON-NLS-1$
public static final String OPTION_ReportUnusedParameterWhenImplementingAbstract = "org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract"; //$NON-NLS-1$
Expand Down Expand Up @@ -398,6 +399,7 @@ public class CompilerOptions {
// group 3
public static final int InsufficientResourceManagement = IrritantSet.GROUP3 | ASTNode.Bit1;
public static final int IncompatibleOwningContract = IrritantSet.GROUP3 | ASTNode.Bit2;
public static final int UnusedLambdaParameter = IrritantSet.GROUP3 | ASTNode.Bit3;


// Severity level for handlers
Expand Down Expand Up @@ -694,6 +696,8 @@ public static String optionKeyFromIrritant(int irritant) {
return OPTION_ReportHiddenCatchBlock;
case UnusedLocalVariable :
return OPTION_ReportUnusedLocal;
case UnusedLambdaParameter:
return OPTION_ReportUnusedLambdaParameter;
case UnusedArgument :
return OPTION_ReportUnusedParameter;
case UnusedExceptionParameter :
Expand Down Expand Up @@ -1170,6 +1174,7 @@ public static String warningTokenFromIrritant(int irritant) {
case UnusedImport :
case UnusedLabel :
case UnusedLocalVariable :
case UnusedLambdaParameter :
case UnusedObjectAllocation :
case UnusedArgument : // OPTION_ReportUnusedParameter
case UnusedPrivateMember :
Expand Down Expand Up @@ -1339,6 +1344,7 @@ public Map<String, String> getMap() {
optionsMap.put(OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, this.reportDeprecationWhenOverridingDeprecatedMethod ? ENABLED : DISABLED);
optionsMap.put(OPTION_ReportHiddenCatchBlock, getSeverityString(MaskedCatchBlock));
optionsMap.put(OPTION_ReportUnusedLocal, getSeverityString(UnusedLocalVariable));
optionsMap.put(OPTION_ReportUnusedLambdaParameter, getSeverityString(UnusedLambdaParameter));
optionsMap.put(OPTION_ReportUnusedParameter, getSeverityString(UnusedArgument));
optionsMap.put(OPTION_ReportUnusedExceptionParameter, getSeverityString(UnusedExceptionParameter));
optionsMap.put(OPTION_ReportUnusedImport, getSeverityString(UnusedImport));
Expand Down Expand Up @@ -1924,6 +1930,7 @@ public void set(Map<String, String> optionsMap) {
if ((optionValue = optionsMap.get(OPTION_ReportTerminalDeprecation)) != null) updateSeverity(UsingTerminallyDeprecatedAPI, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportHiddenCatchBlock)) != null) updateSeverity(MaskedCatchBlock, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportUnusedLocal)) != null) updateSeverity(UnusedLocalVariable, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportUnusedLambdaParameter)) != null) updateSeverity(UnusedLambdaParameter, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportUnusedParameter)) != null) updateSeverity(UnusedArgument, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportUnusedExceptionParameter)) != null) updateSeverity(UnusedExceptionParameter, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportUnusedImport)) != null) updateSeverity(UnusedImport, optionValue);
Expand Down Expand Up @@ -2284,6 +2291,7 @@ public String toString() {
buf.append("\n\t- removal: ").append(getSeverityString(UsingTerminallyDeprecatedAPI)); //$NON-NLS-1$
buf.append("\n\t- masked catch block: ").append(getSeverityString(MaskedCatchBlock)); //$NON-NLS-1$
buf.append("\n\t- unused local variable: ").append(getSeverityString(UnusedLocalVariable)); //$NON-NLS-1$
buf.append("\n\t- unused lambda parameter: ").append(getSeverityString(UnusedLambdaParameter)); //$NON-NLS-1$
buf.append("\n\t- unused parameter: ").append(getSeverityString(UnusedArgument)); //$NON-NLS-1$
buf.append("\n\t- unused exception parameter: ").append(getSeverityString(UnusedExceptionParameter)); //$NON-NLS-1$
buf.append("\n\t- unused import: ").append(getSeverityString(UnusedImport)); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public class IrritantSet {
|CompilerOptions.UnstableAutoModuleName
|CompilerOptions.PreviewFeatureUsed)
.set(CompilerOptions.InsufficientResourceManagement
|CompilerOptions.IncompatibleOwningContract);
|CompilerOptions.IncompatibleOwningContract
|CompilerOptions.UnusedLambdaParameter);
// default errors IF AnnotationBasedNullAnalysis is enabled:
COMPILER_DEFAULT_ERRORS.set(
CompilerOptions.NullSpecViolation
Expand Down Expand Up @@ -178,7 +179,8 @@ public class IrritantSet {
.set(CompilerOptions.DeadCode)
.set(CompilerOptions.UnusedObjectAllocation)
.set(CompilerOptions.UnusedTypeParameter)
.set(CompilerOptions.RedundantSpecificationOfTypeArguments);
.set(CompilerOptions.RedundantSpecificationOfTypeArguments)
.set(CompilerOptions.UnusedLambdaParameter);
STATIC_METHOD
.set(CompilerOptions.MethodCanBePotentiallyStatic);
RESOURCE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ void computeLocalVariablePositions(int ilocal, int initOffset, CodeStream codeSt
// could be optimized out, but does need to preserve unread variables ?
if (!generateCurrentLocalVar) {
if ((local.declaration != null && compilerOptions().preserveAllLocalVariables) ||
local.isPatternVariable()) { // too much voodoo around pattern codegen. Having warned, just treat them as used.
local.isPatternVariable() || // too much voodoo around pattern codegen. Having warned, just treat them as used.
local.isResourceVariable()) {
generateCurrentLocalVar = true; // force it to be preserved in the generated code
if (local.useFlag == LocalVariableBinding.UNUSED)
local.useFlag = LocalVariableBinding.USED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ public boolean isParameter() {
public boolean isCatchParameter() {
return false;
}

public boolean isResourceVariable() {
return (this.tagBits & TagBits.IsResource) != 0;
}

@Override
public boolean isPatternVariable() {
return (this.tagBits & TagBits.IsPatternBinding) != 0;
Expand Down
Loading

0 comments on commit a5940f3

Please sign in to comment.