Skip to content

Commit

Permalink
Fix for #1515: SourceTypeConverter in CompilationUnitResolver#accept
Browse files Browse the repository at this point in the history
like `CompilationUnitProblemFinder` and `HierarchyResolver`
  • Loading branch information
eric-milles committed Oct 6, 2023
1 parent 772143e commit ed954fa
Show file tree
Hide file tree
Showing 15 changed files with 332 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public void visitClass(ClassNode classNode) {
for (Map.Entry<Class<? extends ASTTransformation>, Set<ASTNode>> entry : baseTransforms.entrySet()) {
for (ASTNode node : entry.getValue()) {
List<ASTTransformation> list = transforms.computeIfAbsent(node, k -> new ArrayList<>());
list.add(transformInstances.get(entry.getKey()));
ASTTransformation aTransform = transformInstances.get(entry.getKey());
if (aTransform != null) list.add(aTransform); // GRECLIPSE null test
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public void visitClass(ClassNode classNode) {
for (Map.Entry<Class<? extends ASTTransformation>, Set<ASTNode>> entry : baseTransforms.entrySet()) {
for (ASTNode node : entry.getValue()) {
List<ASTTransformation> list = transforms.computeIfAbsent(node, k -> new ArrayList<>());
list.add(transformInstances.get(entry.getKey()));
ASTTransformation aTransform = transformInstances.get(entry.getKey());
if (aTransform != null) list.add(aTransform); // GRECLIPSE null test
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public void visitClass(ClassNode classNode) {
for (Map.Entry<Class<? extends ASTTransformation>, Set<ASTNode>> entry : baseTransforms.entrySet()) {
for (ASTNode node : entry.getValue()) {
List<ASTTransformation> list = transforms.computeIfAbsent(node, k -> new ArrayList<>());
list.add(transformInstances.get(entry.getKey()));
ASTTransformation aTransform = transformInstances.get(entry.getKey());
if (aTransform != null) list.add(aTransform); // GRECLIPSE null test
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GROOVY PATCHED
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -54,8 +54,10 @@
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
Expand Down Expand Up @@ -168,19 +170,39 @@ public CompilationUnitResolver(
boolean fromJavaProject) {

super(environment, policy, compilerOptions, requestor, problemFactory);
this.hasCompilationAborted = false;
this.monitor =monitor;
this.monitor = monitor;
this.fromJavaProject = fromJavaProject;
}

/*
* Add additional source types
*/
@Override
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
// Need to reparse the entire source of the compilation unit so as to get source positions
// (case of processing a source that was not known by beginToCompile (e.g. when asking to createBinding))
SourceTypeElementInfo sourceType = (SourceTypeElementInfo) sourceTypes[0];
// GROOVY add -- ASTParser#createAST <https://github.com/groovy/groovy-eclipse/issues/1515>
if (LanguageSupportFactory.isInterestingSourceFile(new String(sourceType.getFileName()))) {
while (sourceTypes[0].getEnclosingType() != null) sourceTypes[0] = sourceTypes[0].getEnclosingType();
CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, this.options.maxProblemsPerUnit);
LookupEnvironment environment = packageBinding.environment; if (environment == null) environment = this.lookupEnvironment;
CompilationUnitDeclaration unit =
SourceTypeConverter.buildCompilationUnit(
sourceTypes,
SourceTypeConverter.FIELD_AND_METHOD | SourceTypeConverter.MEMBER_TYPE,
environment.problemReporter,
result);
if (unit != null) {
environment.buildTypeBindings(unit, accessRestriction);
CompilationUnitDeclaration previousUnitBeingCompleted =
this.lookupEnvironment.unitBeingCompleted;
try {
environment.completeTypeBindings(unit);
} finally {
this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
}
}
}
else
// GROOVY end
accept((org.eclipse.jdt.internal.compiler.env.ICompilationUnit) sourceType.getHandle().getCompilationUnit(), accessRestriction);
}

Expand Down Expand Up @@ -375,8 +397,9 @@ public void acceptResult(CompilationResult compilationResult) {

@Override
public void initializeParser() {
// GROOVY edit
//this.parser = new CommentRecorderParser(this.problemReporter, false);
/* GROOVY edit
this.parser = new CommentRecorderParser(this.problemReporter, false);
*/
this.parser = LanguageSupportFactory.getParser(this, this.lookupEnvironment == null ? null : this.lookupEnvironment.globalOptions, this.problemReporter, false, LanguageSupportFactory.CommentRecorderParserVariant + 1);
// GROOVY end
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GROOVY PATCHED
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -54,8 +54,10 @@
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
Expand Down Expand Up @@ -168,19 +170,39 @@ public CompilationUnitResolver(
boolean fromJavaProject) {

super(environment, policy, compilerOptions, requestor, problemFactory);
this.hasCompilationAborted = false;
this.monitor =monitor;
this.monitor = monitor;
this.fromJavaProject = fromJavaProject;
}

/*
* Add additional source types
*/
@Override
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
// Need to reparse the entire source of the compilation unit so as to get source positions
// (case of processing a source that was not known by beginToCompile (e.g. when asking to createBinding))
SourceTypeElementInfo sourceType = (SourceTypeElementInfo) sourceTypes[0];
// GROOVY add -- ASTParser#createAST <https://github.com/groovy/groovy-eclipse/issues/1515>
if (LanguageSupportFactory.isInterestingSourceFile(new String(sourceType.getFileName()))) {
while (sourceTypes[0].getEnclosingType() != null) sourceTypes[0] = sourceTypes[0].getEnclosingType();
CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, this.options.maxProblemsPerUnit);
LookupEnvironment environment = packageBinding.environment; if (environment == null) environment = this.lookupEnvironment;
CompilationUnitDeclaration unit =
SourceTypeConverter.buildCompilationUnit(
sourceTypes,
SourceTypeConverter.FIELD_AND_METHOD | SourceTypeConverter.MEMBER_TYPE,
environment.problemReporter,
result);
if (unit != null) {
environment.buildTypeBindings(unit, accessRestriction);
CompilationUnitDeclaration previousUnitBeingCompleted =
this.lookupEnvironment.unitBeingCompleted;
try {
environment.completeTypeBindings(unit);
} finally {
this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
}
}
}
else
// GROOVY end
accept((org.eclipse.jdt.internal.compiler.env.ICompilationUnit) sourceType.getHandle().getCompilationUnit(), accessRestriction);
}

Expand Down Expand Up @@ -375,8 +397,9 @@ public void acceptResult(CompilationResult compilationResult) {

@Override
public void initializeParser() {
// GROOVY edit
//this.parser = new CommentRecorderParser(this.problemReporter, false);
/* GROOVY edit
this.parser = new CommentRecorderParser(this.problemReporter, false);
*/
this.parser = LanguageSupportFactory.getParser(this, this.lookupEnvironment == null ? null : this.lookupEnvironment.globalOptions, this.problemReporter, false, LanguageSupportFactory.CommentRecorderParserVariant + 1);
// GROOVY end
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GROOVY PATCHED
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -56,6 +56,7 @@
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
Expand Down Expand Up @@ -168,19 +169,38 @@ public CompilationUnitResolver(
boolean fromJavaProject) {

super(environment, policy, compilerOptions, requestor, problemFactory);
this.hasCompilationAborted = false;
this.monitor =monitor;
this.monitor = monitor;
this.fromJavaProject = fromJavaProject;
}

/*
* Add additional source types
*/
@Override
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
// Need to reparse the entire source of the compilation unit so as to get source positions
// (case of processing a source that was not known by beginToCompile (e.g. when asking to createBinding))
SourceTypeElementInfo sourceType = (SourceTypeElementInfo) sourceTypes[0];
// GROOVY add -- ASTParser#createAST <https://github.com/groovy/groovy-eclipse/issues/1515>
if (LanguageSupportFactory.isInterestingSourceFile(new String(sourceType.getFileName()))) {
while (sourceTypes[0].getEnclosingType() != null) sourceTypes[0] = sourceTypes[0].getEnclosingType();
var environment = packageBinding.environment; if (environment == null) environment = this.lookupEnvironment;
CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, this.options.maxProblemsPerUnit);
CompilationUnitDeclaration unit =
SourceTypeConverter.buildCompilationUnit(
sourceTypes,
SourceTypeConverter.FIELD_AND_METHOD | SourceTypeConverter.MEMBER_TYPE,
environment.problemReporter,
result);
if (unit != null) {
environment.buildTypeBindings(unit, accessRestriction);
var previousUnitBeingCompleted = this.lookupEnvironment.unitBeingCompleted;
try {
environment.completeTypeBindings(unit);
} finally {
this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
}
}
}
else
// GROOVY end
accept((org.eclipse.jdt.internal.compiler.env.ICompilationUnit) sourceType.getHandle().getCompilationUnit(), accessRestriction);
}

Expand Down Expand Up @@ -375,8 +395,9 @@ public void acceptResult(CompilationResult compilationResult) {

@Override
public void initializeParser() {
// GROOVY edit
//this.parser = new CommentRecorderParser(this.problemReporter, false);
/* GROOVY edit
this.parser = new CommentRecorderParser(this.problemReporter, false);
*/
this.parser = LanguageSupportFactory.getParser(this, this.lookupEnvironment == null ? null : this.lookupEnvironment.globalOptions, this.problemReporter, false, LanguageSupportFactory.CommentRecorderParserVariant + 1);
// GROOVY end
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GROOVY PATCHED
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -56,6 +56,7 @@
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
Expand Down Expand Up @@ -168,19 +169,38 @@ public CompilationUnitResolver(
boolean fromJavaProject) {

super(environment, policy, compilerOptions, requestor, problemFactory);
this.hasCompilationAborted = false;
this.monitor =monitor;
this.monitor = monitor;
this.fromJavaProject = fromJavaProject;
}

/*
* Add additional source types
*/
@Override
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
// Need to reparse the entire source of the compilation unit so as to get source positions
// (case of processing a source that was not known by beginToCompile (e.g. when asking to createBinding))
SourceTypeElementInfo sourceType = (SourceTypeElementInfo) sourceTypes[0];
// GROOVY add -- ASTParser#createAST <https://github.com/groovy/groovy-eclipse/issues/1515>
if (LanguageSupportFactory.isInterestingSourceFile(new String(sourceType.getFileName()))) {
while (sourceTypes[0].getEnclosingType() != null) sourceTypes[0] = sourceTypes[0].getEnclosingType();
var environment = packageBinding.environment; if (environment == null) environment = this.lookupEnvironment;
CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, this.options.maxProblemsPerUnit);
CompilationUnitDeclaration unit =
SourceTypeConverter.buildCompilationUnit(
sourceTypes,
SourceTypeConverter.FIELD_AND_METHOD | SourceTypeConverter.MEMBER_TYPE,
environment.problemReporter,
result);
if (unit != null) {
environment.buildTypeBindings(unit, accessRestriction);
var previousUnitBeingCompleted = this.lookupEnvironment.unitBeingCompleted;
try {
environment.completeTypeBindings(unit);
} finally {
this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
}
}
}
else
// GROOVY end
accept((org.eclipse.jdt.internal.compiler.env.ICompilationUnit) sourceType.getHandle().getCompilationUnit(), accessRestriction);
}

Expand Down Expand Up @@ -375,8 +395,9 @@ public void acceptResult(CompilationResult compilationResult) {

@Override
public void initializeParser() {
// GROOVY edit
//this.parser = new CommentRecorderParser(this.problemReporter, false);
/* GROOVY edit
this.parser = new CommentRecorderParser(this.problemReporter, false);
*/
this.parser = LanguageSupportFactory.getParser(this, this.lookupEnvironment == null ? null : this.lookupEnvironment.globalOptions, this.problemReporter, false, LanguageSupportFactory.CommentRecorderParserVariant + 1);
// GROOVY end
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GROOVY PATCHED
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -56,6 +56,7 @@
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
Expand Down Expand Up @@ -168,19 +169,38 @@ public CompilationUnitResolver(
boolean fromJavaProject) {

super(environment, policy, compilerOptions, requestor, problemFactory);
this.hasCompilationAborted = false;
this.monitor =monitor;
this.monitor = monitor;
this.fromJavaProject = fromJavaProject;
}

/*
* Add additional source types
*/
@Override
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
// Need to reparse the entire source of the compilation unit so as to get source positions
// (case of processing a source that was not known by beginToCompile (e.g. when asking to createBinding))
SourceTypeElementInfo sourceType = (SourceTypeElementInfo) sourceTypes[0];
// GROOVY add -- ASTParser#createAST <https://github.com/groovy/groovy-eclipse/issues/1515>
if (LanguageSupportFactory.isInterestingSourceFile(new String(sourceType.getFileName()))) {
while (sourceTypes[0].getEnclosingType() != null) sourceTypes[0] = sourceTypes[0].getEnclosingType();
var environment = packageBinding.environment; if (environment == null) environment = this.lookupEnvironment;
CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, this.options.maxProblemsPerUnit);
CompilationUnitDeclaration unit =
SourceTypeConverter.buildCompilationUnit(
sourceTypes,
SourceTypeConverter.FIELD_AND_METHOD | SourceTypeConverter.MEMBER_TYPE,
environment.problemReporter,
result);
if (unit != null) {
environment.buildTypeBindings(unit, accessRestriction);
var previousUnitBeingCompleted = this.lookupEnvironment.unitBeingCompleted;
try {
environment.completeTypeBindings(unit);
} finally {
this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
}
}
}
else
// GROOVY end
accept((org.eclipse.jdt.internal.compiler.env.ICompilationUnit) sourceType.getHandle().getCompilationUnit(), accessRestriction);
}

Expand Down
Loading

0 comments on commit ed954fa

Please sign in to comment.