From ed954fa81a7dd22dc8d7d46d072e996ee1d9c876 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Thu, 5 Oct 2023 15:57:49 -0500 Subject: [PATCH] Fix for #1515: `SourceTypeConverter` in `CompilationUnitResolver#accept` like `CompilationUnitProblemFinder` and `HierarchyResolver` --- .../transform/ASTTransformationVisitor.java | 3 +- .../transform/ASTTransformationVisitor.java | 3 +- .../transform/ASTTransformationVisitor.java | 3 +- .../jdt/core/dom/CompilationUnitResolver.java | 39 +++++++++++++++---- .../jdt/core/dom/CompilationUnitResolver.java | 39 +++++++++++++++---- .../jdt/core/dom/CompilationUnitResolver.java | 37 ++++++++++++++---- .../jdt/core/dom/CompilationUnitResolver.java | 37 ++++++++++++++---- .../jdt/core/dom/CompilationUnitResolver.java | 32 ++++++++++++--- .../jdt/core/dom/CompilationUnitResolver.java | 32 ++++++++++++--- .../jdt/core/dom/CompilationUnitResolver.java | 32 ++++++++++++--- .../jdt/core/dom/CompilationUnitResolver.java | 32 ++++++++++++--- .../jdt/core/dom/CompilationUnitResolver.java | 32 ++++++++++++--- .../jdt/core/dom/CompilationUnitResolver.java | 32 ++++++++++++--- .../jdt/core/dom/CompilationUnitResolver.java | 30 +++++++++++--- .../jdt/core/dom/CompilationUnitResolver.java | 30 +++++++++++--- 15 files changed, 332 insertions(+), 81 deletions(-) diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java index 10a4c0339d..4e136cda74 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java @@ -161,7 +161,8 @@ public void visitClass(ClassNode classNode) { for (Map.Entry, Set> entry : baseTransforms.entrySet()) { for (ASTNode node : entry.getValue()) { List 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 } } diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java index 0c79325777..96e2982358 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java @@ -166,7 +166,8 @@ public void visitClass(ClassNode classNode) { for (Map.Entry, Set> entry : baseTransforms.entrySet()) { for (ASTNode node : entry.getValue()) { List 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 } } diff --git a/base/org.codehaus.groovy50/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java b/base/org.codehaus.groovy50/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java index 0c79325777..96e2982358 100644 --- a/base/org.codehaus.groovy50/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java +++ b/base/org.codehaus.groovy50/src/org/codehaus/groovy/transform/ASTTransformationVisitor.java @@ -166,7 +166,8 @@ public void visitClass(ClassNode classNode) { for (Map.Entry, Set> entry : baseTransforms.entrySet()) { for (ASTNode node : entry.getValue()) { List 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 } } diff --git a/jdt-patch/e419/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e419/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 69973cb8b4..33768d3b9c 100644 --- a/jdt-patch/e419/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e419/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -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 @@ -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; @@ -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 + 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); } @@ -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 } diff --git a/jdt-patch/e420/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e420/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 69973cb8b4..33768d3b9c 100644 --- a/jdt-patch/e420/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e420/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -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 @@ -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; @@ -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 + 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); } @@ -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 } diff --git a/jdt-patch/e421/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e421/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 69973cb8b4..c4a4dad595 100644 --- a/jdt-patch/e421/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e421/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -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 @@ -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; @@ -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 + 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); } @@ -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 } diff --git a/jdt-patch/e422/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e422/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 69973cb8b4..c4a4dad595 100644 --- a/jdt-patch/e422/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e422/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -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 @@ -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; @@ -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 + 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); } @@ -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 } diff --git a/jdt-patch/e423/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e423/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 2c543574bd..c4a4dad595 100644 --- a/jdt-patch/e423/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e423/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -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 @@ -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; @@ -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 + 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); } diff --git a/jdt-patch/e424/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e424/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 76112f177c..d822141fbc 100644 --- a/jdt-patch/e424/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e424/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -1,6 +1,6 @@ // GROOVY PATCHED /******************************************************************************* - * Copyright (c) 2000, 2022 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 @@ -59,6 +59,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; @@ -172,19 +173,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 + 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); } diff --git a/jdt-patch/e425/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e425/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 76112f177c..d822141fbc 100644 --- a/jdt-patch/e425/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e425/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -1,6 +1,6 @@ // GROOVY PATCHED /******************************************************************************* - * Copyright (c) 2000, 2022 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 @@ -59,6 +59,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; @@ -172,19 +173,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 + 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); } diff --git a/jdt-patch/e426/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e426/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 76112f177c..d822141fbc 100644 --- a/jdt-patch/e426/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e426/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -1,6 +1,6 @@ // GROOVY PATCHED /******************************************************************************* - * Copyright (c) 2000, 2022 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 @@ -59,6 +59,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; @@ -172,19 +173,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 + 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); } diff --git a/jdt-patch/e427/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e427/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 76112f177c..d822141fbc 100644 --- a/jdt-patch/e427/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e427/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -1,6 +1,6 @@ // GROOVY PATCHED /******************************************************************************* - * Copyright (c) 2000, 2022 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 @@ -59,6 +59,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; @@ -172,19 +173,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 + 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); } diff --git a/jdt-patch/e428/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e428/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 76112f177c..d822141fbc 100644 --- a/jdt-patch/e428/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e428/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -1,6 +1,6 @@ // GROOVY PATCHED /******************************************************************************* - * Copyright (c) 2000, 2022 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 @@ -59,6 +59,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; @@ -172,19 +173,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 + 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); } diff --git a/jdt-patch/e429/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e429/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 650a657578..d822141fbc 100644 --- a/jdt-patch/e429/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e429/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -59,6 +59,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; @@ -172,19 +173,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 + 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); } diff --git a/jdt-patch/e430/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/jdt-patch/e430/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 650a657578..d822141fbc 100644 --- a/jdt-patch/e430/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/jdt-patch/e430/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -59,6 +59,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; @@ -172,19 +173,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 + 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); }