Skip to content

Commit f0d0bde

Browse files
committed
minor fix-ups
1 parent af3c944 commit f0d0bde

File tree

49 files changed

+950
-1028
lines changed

Some content is hidden

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

49 files changed

+950
-1028
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -5150,16 +5150,16 @@ public void testCompileStatic9771() {
51505150
"Main.groovy",
51515151
"@groovy.transform.CompileStatic\n" +
51525152
"class Main {\n" +
5153-
" private final Map<String, Boolean> map = [:]\n" +
5154-
" void test() {\n" +
5155-
" { ->\n" +
5156-
" map['key'] = true\n" +
5157-
" }.call()\n" +
5158-
" print map\n" +
5159-
" }\n" +
5160-
" static main(args) {\n" +
5161-
" newInstance().test()\n" +
5162-
" }\n" +
5153+
" private final Map<String, Boolean> map = [:]\n" +
5154+
" void test() {\n" +
5155+
" { ->\n" +
5156+
" map['key'] = true\n" +
5157+
" }.call()\n" +
5158+
" print map\n" +
5159+
" }\n" +
5160+
" static main(args) {\n" +
5161+
" newInstance().test()\n" +
5162+
" }\n" +
51635163
"}\n",
51645164
};
51655165
//@formatter:on

base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/MultiplexingIndexingParser.java

+10-17
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
package org.codehaus.jdt.groovy.integration.internal;
1717

1818
import java.util.Collections;
19-
import java.util.Optional;
2019

2120
import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration;
2221
import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyParser;
2322
import org.eclipse.core.runtime.IProgressMonitor;
23+
import org.eclipse.core.runtime.OperationCanceledException;
2424
import org.eclipse.jdt.core.compiler.CharOperation;
2525
import org.eclipse.jdt.groovy.core.util.ReflectionUtils;
2626
import org.eclipse.jdt.internal.compiler.CompilationResult;
@@ -32,15 +32,16 @@
3232
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
3333
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
3434
import org.eclipse.jdt.internal.core.search.indexing.IndexingParser;
35-
import org.eclipse.jdt.internal.core.util.Util;
35+
import org.eclipse.jdt.internal.core.util.Messages;
3636

3737
class MultiplexingIndexingParser extends IndexingParser {
3838

3939
private final SourceElementNotifier notifier;
4040
private final boolean reportReferenceInfo;
4141
private ISourceElementRequestor requestor;
4242

43-
MultiplexingIndexingParser(final ISourceElementRequestor requestor, final IProblemFactory problemFactory, final CompilerOptions options, final boolean reportLocalDeclarations, final boolean optimizeStringLiterals, final boolean useSourceJavadocParser) {
43+
MultiplexingIndexingParser(final ISourceElementRequestor requestor, final IProblemFactory problemFactory, final CompilerOptions options,
44+
final boolean reportLocalDeclarations, final boolean optimizeStringLiterals, final boolean useSourceJavadocParser) {
4445
super(requestor, problemFactory, options, reportLocalDeclarations, optimizeStringLiterals, useSourceJavadocParser);
4546
this.notifier = ReflectionUtils.getPrivateField(SourceElementParser.class, "notifier", this);
4647
this.reportReferenceInfo = reportLocalDeclarations;
@@ -56,25 +57,17 @@ public void setRequestor(final ISourceElementRequestor requestor) {
5657
@Override
5758
public CompilationUnitDeclaration parseCompilationUnit(final ICompilationUnit compilationUnit, final boolean fullParse, final IProgressMonitor pm) {
5859
if (GroovyParser.isGroovyParserEligible(compilationUnit, readManager)) {
59-
// ASSUMPTIONS:
60-
// 1) parsing is for the entire CU (ie- from character 0 to compilationUnit.getContents().length)
61-
// 2) nodesToCategories map is not necessary. I think it has something to do with JavaDoc, but not sure
62-
// 3) there is no difference between a diet and full parse in the groovy works, so can ignore the fullParse parameter
63-
6460
char[] contents = GroovyParser.getContents(compilationUnit, readManager);
6561
String fileName = CharOperation.charToString(compilationUnit.getFileName());
66-
CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 0, options.maxProblemsPerUnit);
62+
CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, options.maxProblemsPerUnit);
6763
GroovyCompilationUnitDeclaration gcud = new GroovyParser(options, problemReporter, false, true).dietParse(contents, fileName, compilationResult);
6864

69-
Optional.ofNullable(gcud.getModuleNode()).ifPresent(module -> {
70-
try {
71-
new GroovyIndexingVisitor(requestor).visitModule(module);
72-
} catch (RuntimeException e) {
73-
Util.log(e);
74-
}
75-
});
65+
if (pm != null && pm.isCanceled())
66+
throw new OperationCanceledException(Messages.operation_cancelled);
67+
68+
new GroovyIndexingVisitor(requestor).visitModule(gcud.getModuleNode());
7669

77-
notifier.notifySourceElementRequestor(gcud, 0, contents.length, reportReferenceInfo, gcud.sourceEnds, Collections.EMPTY_MAP);
70+
notifier.notifySourceElementRequestor(gcud, 0, contents.length, reportReferenceInfo, gcud.sourceEnds, Collections.emptyMap());
7871

7972
return gcud;
8073
}

base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/MultiplexingSourceElementRequestorParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public CompilationUnitDeclaration parseCompilationUnit(final ICompilationUnit co
8888
// FIXASC Is it ok to use a new parser here everytime? If we don't we sometimes recurse back into the first one.
8989
// FIXASC ought to reuse to ensure types end up in same groovy CU
9090
GroovyParser groovyParser = new GroovyParser(this.groovyParser.requestor, options, problemReporter, !disableGlobalXforms, true);
91-
CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 0, options.maxProblemsPerUnit);
91+
CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, options.maxProblemsPerUnit);
9292
GroovyCompilationUnitDeclaration compUnitDecl = groovyParser.dietParse(contents, fileName, compilationResult);
9393

9494
scanner.setSource(contents);

base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import org.codehaus.jdt.groovy.core.dom.GroovyCompilationUnit;
9595
import org.eclipse.core.resources.IFile;
9696
import org.eclipse.core.runtime.IStatus;
97+
import org.eclipse.core.runtime.OperationCanceledException;
9798
import org.eclipse.core.runtime.Platform;
9899
import org.eclipse.core.runtime.Status;
99100
import org.eclipse.jdt.core.Flags;
@@ -251,7 +252,9 @@ public boolean processToPhase(int phase) {
251252
GroovyLogManager.manager.log(TraceCategory.COMPILER, e.getBugText());
252253
}
253254

254-
if (e.getCause() instanceof AbortCompilation) {
255+
if (e.getCause() instanceof OperationCanceledException) {
256+
throw (OperationCanceledException) e.getCause();
257+
} else if (e.getCause() instanceof AbortCompilation) {
255258
AbortCompilation abort = (AbortCompilation) e.getCause();
256259
if (!abort.isSilent) {
257260
if (abort.problem != null) {

base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/model/GroovyCompilationUnit.java

+90-81
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,6 @@
6868

6969
public class GroovyCompilationUnit extends CompilationUnit {
7070

71-
private class GroovyErrorHandlingPolicy implements IErrorHandlingPolicy {
72-
73-
final boolean stopOnFirst;
74-
75-
GroovyErrorHandlingPolicy(boolean stopOnFirst) {
76-
this.stopOnFirst = stopOnFirst;
77-
}
78-
79-
@Override
80-
public boolean proceedOnErrors() {
81-
return !stopOnFirst;
82-
}
83-
84-
@Override
85-
public boolean stopOnFirstError() {
86-
return stopOnFirst;
87-
}
88-
89-
@Override
90-
public boolean ignoreAllErrors() {
91-
// TODO is this the right decision here? New method with java8 support
92-
return false;
93-
}
94-
95-
}
96-
9771
public GroovyCompilationUnit(PackageFragment parent, String name, WorkingCopyOwner owner) {
9872
super(parent, name, owner);
9973
}
@@ -183,28 +157,13 @@ public void discardWorkingCopy() throws JavaModelException {
183157
* working copy info is about to be discared if useCount <= 1
184158
*/
185159
private boolean workingCopyInfoWillBeDiscarded(JavaModelManager.PerWorkingCopyInfo info) {
186-
return info != null && ((Integer) ReflectionUtils.getPrivateField(JavaModelManager.PerWorkingCopyInfo.class, "useCount", info)).intValue() <= 1;
160+
return (info != null && ((Integer) ReflectionUtils.getPrivateField(JavaModelManager.PerWorkingCopyInfo.class, "useCount", info)).intValue() <= 1);
187161
}
188162

189163
/**
190164
* Tracks how deep we are in recursive calls to {@link #buildStructure}.
191165
*/
192166
private static final ThreadLocalAtomicInteger depth = new ThreadLocalAtomicInteger();
193-
private static class ThreadLocalAtomicInteger extends ThreadLocal<AtomicInteger> {
194-
@Override
195-
protected AtomicInteger initialValue() {
196-
return new AtomicInteger();
197-
}
198-
int intValue() {
199-
return get().get();
200-
}
201-
void increment() {
202-
get().incrementAndGet();
203-
}
204-
void decrement() {
205-
get().decrementAndGet();
206-
}
207-
}
208167

209168
@Override
210169
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource)
@@ -405,26 +364,24 @@ protected void maybeCacheModuleNode(JavaModelManager.PerWorkingCopyInfo perWorki
405364
ModuleNodeMapper.getInstance().maybeCacheModuleNode(perWorkingCopyInfo, compilationUnitDeclaration);
406365
}
407366

408-
/*
409-
* Copied from super class, but changed so that a custom ReconcileWorkingCopyOperation can be run
410-
*/
411367
@Override
412368
public org.eclipse.jdt.core.dom.CompilationUnit reconcile(int astLevel, int reconcileFlags, WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor)
413369
throws JavaModelException {
414-
if (!isWorkingCopy())
370+
if (!isWorkingCopy() || isCanceled(monitor))
415371
return null; // reconciling is not supported on non-working copies
416-
if (workingCopyOwner == null)
417-
workingCopyOwner = DefaultWorkingCopyOwner.PRIMARY;
372+
418373
PerformanceStats stats = null;
419374
if (ReconcileWorkingCopyOperation.PERF) {
420375
stats = PerformanceStats.getStats(JavaModelManager.RECONCILE_PERF, this);
421376
stats.startRun(String.valueOf(getFileName()));
422377
}
423-
ReconcileWorkingCopyOperation op = new GroovyReconcileWorkingCopyOperation(this, astLevel, reconcileFlags, workingCopyOwner);
378+
ReconcileWorkingCopyOperation op = new GroovyReconcileWorkingCopyOperation(this, astLevel,
379+
reconcileFlags, workingCopyOwner != null ? workingCopyOwner : DefaultWorkingCopyOwner.PRIMARY);
424380
JavaModelManager manager = JavaModelManager.getJavaModelManager();
425381
try {
426382
manager.cacheZipFiles(this); // cache zip files for performance (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=134172)
427-
op.runOperation(monitor);
383+
if (!isCanceled(monitor))
384+
op.runOperation(monitor);
428385
} finally {
429386
manager.flushZipFiles(this);
430387
}
@@ -434,7 +391,12 @@ public org.eclipse.jdt.core.dom.CompilationUnit reconcile(int astLevel, int reco
434391
return op.ast;
435392
}
436393

437-
@Override @SuppressWarnings("unchecked")
394+
private boolean isCanceled(IProgressMonitor monitor) {
395+
return (monitor != null && monitor.isCanceled());
396+
}
397+
398+
@Override
399+
@SuppressWarnings("unchecked")
438400
public <T> T getAdapter(Class<T> adapter) {
439401
if (GroovyCompilationUnit.class.equals(adapter)) {
440402
return (T) this;
@@ -445,36 +407,6 @@ public <T> T getAdapter(Class<T> adapter) {
445407
return super.getAdapter(adapter);
446408
}
447409

448-
class CompilationUnitClone extends GroovyCompilationUnit {
449-
private char[] cachedContents;
450-
451-
CompilationUnitClone(char[] cachedContents) {
452-
this();
453-
this.cachedContents = cachedContents;
454-
}
455-
456-
CompilationUnitClone() {
457-
super((PackageFragment) GroovyCompilationUnit.this.parent, GroovyCompilationUnit.this.name, GroovyCompilationUnit.this.owner);
458-
}
459-
460-
@Override
461-
public char[] getContents() {
462-
if (this.cachedContents == null)
463-
this.cachedContents = GroovyCompilationUnit.this.getContents();
464-
return this.cachedContents;
465-
}
466-
467-
@Override
468-
public CompilationUnit originalFromClone() {
469-
return GroovyCompilationUnit.this;
470-
}
471-
472-
@Override
473-
public char[] getFileName() {
474-
return GroovyCompilationUnit.this.getFileName();
475-
}
476-
}
477-
478410
public GroovyCompilationUnit cloneCachingContents(char[] newContents) {
479411
return new CompilationUnitClone(newContents);
480412
}
@@ -593,4 +525,81 @@ protected void codeComplete(org.eclipse.jdt.internal.compiler.env.ICompilationUn
593525
super.codeComplete(cu, unitToSkip, position, requestor, owner, typeRoot, monitor);
594526
}
595527
}
528+
529+
//--------------------------------------------------------------------------
530+
531+
private class CompilationUnitClone extends GroovyCompilationUnit {
532+
533+
private char[] cachedContents;
534+
535+
CompilationUnitClone(char[] cachedContents) {
536+
this();
537+
this.cachedContents = cachedContents;
538+
}
539+
540+
CompilationUnitClone() {
541+
super((PackageFragment) GroovyCompilationUnit.this.parent, GroovyCompilationUnit.this.name, GroovyCompilationUnit.this.owner);
542+
}
543+
544+
@Override
545+
public char[] getContents() {
546+
if (this.cachedContents == null)
547+
this.cachedContents = GroovyCompilationUnit.this.getContents();
548+
return this.cachedContents;
549+
}
550+
551+
@Override
552+
public CompilationUnit originalFromClone() {
553+
return GroovyCompilationUnit.this;
554+
}
555+
556+
@Override
557+
public char[] getFileName() {
558+
return GroovyCompilationUnit.this.getFileName();
559+
}
560+
}
561+
562+
private static class GroovyErrorHandlingPolicy implements IErrorHandlingPolicy {
563+
564+
private final boolean stopOnFirst;
565+
566+
GroovyErrorHandlingPolicy(final boolean stopOnFirst) {
567+
this.stopOnFirst = stopOnFirst;
568+
}
569+
570+
@Override
571+
public boolean stopOnFirstError() {
572+
return stopOnFirst;
573+
}
574+
575+
@Override
576+
public boolean proceedOnErrors() {
577+
return !stopOnFirst;
578+
}
579+
580+
@Override
581+
public boolean ignoreAllErrors() {
582+
return false;
583+
}
584+
}
585+
586+
private static class ThreadLocalAtomicInteger extends ThreadLocal<AtomicInteger> {
587+
588+
@Override
589+
protected AtomicInteger initialValue() {
590+
return new AtomicInteger();
591+
}
592+
593+
int intValue() {
594+
return get().get();
595+
}
596+
597+
void increment() {
598+
get().incrementAndGet();
599+
}
600+
601+
void decrement() {
602+
get().decrementAndGet();
603+
}
604+
}
596605
}

0 commit comments

Comments
 (0)