Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import org.eclipse.jdt.internal.compiler.lookup.*;

@SuppressWarnings({"rawtypes", "unchecked"})
public abstract class ASTNode implements TypeConstants, TypeIds {
public abstract class ASTNode implements Location, TypeConstants, TypeIds {

public int sourceStart, sourceEnd;

Expand Down Expand Up @@ -1382,11 +1382,12 @@ public boolean checkingPotentialCompatibility() {
public void acceptPotentiallyCompatibleMethods(MethodBinding [] methods) {
// Discard. Interested subclasses should override and grab these goodies.
}
// --- "default methods" for InvocationSite

@Override
public int sourceStart() {
return this.sourceStart;
}
@Override
public int sourceEnd() {
return this.sourceEnd;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2025 Groq Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Martin Bazley - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;

public interface Location {
int sourceEnd();
int sourceStart();
default int nameSourceStart() { return sourceStart(); }
default int nameSourceEnd() { return sourceEnd(); }
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see much benefit in declaring nameSourceStart()/End() here. Those don't seem to be useful for ASTNode and many of its subclasses. Nor do I see this called via the Location interface. Am I missing anything?

}
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ ImportBinding[] getDefaultImports() {
problemReporter().isClassPathCorrect(
TypeConstants.JAVA_LANG_OBJECT,
this.referenceContext,
this.environment.missingClassFileLocation, false, null/*resolving j.l.O is not specific to any referencing type*/);
this.environment, false, null/*resolving j.l.O is not specific to any referencing type*/);
Copy link
Contributor

Choose a reason for hiding this comment

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

this change looks unmotivated to me. Wouldn't just changing the signature of isClassPathCorrect() simplify things already?
I don't think that method has use for the LookupEnvironment itself.

BinaryTypeBinding missingObject = this.environment.createMissingType(null, TypeConstants.JAVA_LANG_OBJECT);
importBinding = missingObject.fPackage;
implicitImports[0] = new ImportBinding(TypeConstants.JAVA_LANG, true, importBinding, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ private boolean siSubI(TypeBinding si, TypeBinding funcI) {
* @throws InferenceFailureException a compile error has been detected during inference
*/
public /*@Nullable*/ BoundSet solve(boolean inferringApplicability) throws InferenceFailureException {
return solve(inferringApplicability, (ASTNode) this.currentInvocation);
return solve(inferringApplicability, this.currentInvocation);
}
/**
* Try to solve the inference problem defined by constraints and bounds previously registered.
Expand All @@ -1023,8 +1023,7 @@ private boolean siSubI(TypeBinding si, TypeBinding funcI) {
* @return a bound set representing the solution, or null if inference failed
* @throws InferenceFailureException a compile error has been detected during inference
*/
private /*@Nullable*/ BoundSet solve(boolean inferringApplicability, ASTNode location)
throws InferenceFailureException
private /*@Nullable*/ BoundSet solve(boolean inferringApplicability, Location location) throws InferenceFailureException
{
CapturingContext.enter(location.sourceStart(), location.sourceEnd(), this.scope);
boolean isRecordPatternTypeInference = location instanceof RecordPattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.ExpressionContext;
import org.eclipse.jdt.internal.compiler.ast.Location;

public interface InvocationSite {
public interface InvocationSite extends Location {

TypeBinding[] genericTypeArguments();
boolean isSuperAccess();
Expand All @@ -32,10 +33,6 @@ public interface InvocationSite {
void setActualReceiverType(ReferenceBinding receiverType);
void setDepth(int depth);
void setFieldIndex(int depth);
int sourceEnd();
int sourceStart();
default int nameSourceStart() { return sourceStart(); }
default int nameSourceEnd() { return sourceEnd(); }
TypeBinding invocationTargetType();
boolean receiverIsImplicitThis();
boolean checkingPotentialCompatibility();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.eclipse.jdt.internal.compiler.ClassFilePool;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Location;
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
Expand Down Expand Up @@ -117,7 +118,7 @@ public class LookupEnvironment implements ProblemReasons, TypeConstants {
public HashtableOfModule knownModules; // SHARED

public CompilationUnitDeclaration unitBeingCompleted = null; // only set while completing units -- ROOT_ONLY
public Object missingClassFileLocation = null; // only set when resolving certain references, to help locating problems
public Location missingClassFileLocation = null; // only set when resolving certain references, to help locating problems
private CompilationUnitDeclaration[] units = new CompilationUnitDeclaration[4]; // ROOT_ONLY
private MethodVerifier verifier;

Expand Down Expand Up @@ -1877,7 +1878,7 @@ public ReferenceBinding getResolvedType(char[][] compoundName, ModuleBinding mod
this.problemReporter.isClassPathCorrect(
compoundName,
scope == null ? this.root.unitBeingCompleted : scope.referenceCompilationUnit(),
this.missingClassFileLocation, implicitAnnotationUse, this.requestingType);
this, implicitAnnotationUse, this.requestingType);
return createMissingType(null, compoundName);
}
public ReferenceBinding getResolvedJavaBaseType(char[][] compoundName, Scope scope) {
Expand Down Expand Up @@ -1996,7 +1997,7 @@ private ReferenceBinding getTypeFromCompoundName(char[][] compoundName, boolean
* misconfiguration now that did not also exist in some equivalent form while producing the class files which encode
* these missing types. So no need to bark again. Note that wasMissingType == true signals a type referenced in a .class
* file which could not be found when the binary was produced. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=364450 */
this.problemReporter.isClassPathCorrect(compoundName, this.root.unitBeingCompleted, this.missingClassFileLocation, false, this.requestingType);
this.problemReporter.isClassPathCorrect(compoundName, this.root.unitBeingCompleted, this, false, this.requestingType);
}
// create a proxy for the missing BinaryType
binding = createMissingType(null, compoundName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ else if (targetType == this) //$IDENTITY-COMPARISON$
environment.problemReporter.isClassPathCorrect(
this.compoundName,
environment.root.unitBeingCompleted,
environment.missingClassFileLocation,
environment,
false,
this.requestingType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4973,7 +4973,7 @@ public void discouragedValueBasedTypeToSynchronize(Expression expression, TypeBi
expression.sourceEnd);
}
public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl,
Object location, boolean implicitAnnotationUse, ReferenceBinding referencingType)
LookupEnvironment environment, boolean implicitAnnotationUse, ReferenceBinding referencingType)
{
// ProblemReporter is not designed to be reentrant. Just in case, we discovered a build path problem while we are already
// in the midst of reporting some other problem, save and restore reference context thereby mimicking a stack.
Expand All @@ -4982,16 +4982,9 @@ public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclar
this.referenceContext = compUnitDecl;
String[] arguments = new String[] {CharOperation.toString(wellKnownTypeName)};
int start = 0, end = 0;
if (location != null) {
if (location instanceof InvocationSite) {
InvocationSite site = (InvocationSite) location;
start = site.sourceStart();
end = site.sourceEnd();
} else if (location instanceof ASTNode) {
ASTNode node = (ASTNode) location;
start = node.sourceStart();
end = node.sourceEnd();
}
if (environment.missingClassFileLocation != null) {
start = environment.missingClassFileLocation.sourceStart();
end = environment.missingClassFileLocation.sourceEnd();
}
try {
int pId = IProblem.IsClassPathCorrect;
Expand Down