Skip to content

Commit

Permalink
minor fix-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Oct 20, 2020
1 parent bc797c2 commit a74edbe
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package org.codehaus.jdt.groovy.integration.internal;

import java.util.Collections;
import java.util.Optional;

import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration;
import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyParser;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.groovy.core.util.ReflectionUtils;
import org.eclipse.jdt.internal.compiler.CompilationResult;
Expand All @@ -32,15 +32,16 @@
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.core.search.indexing.IndexingParser;
import org.eclipse.jdt.internal.core.util.Util;
import org.eclipse.jdt.internal.core.util.Messages;

class MultiplexingIndexingParser extends IndexingParser {

private final SourceElementNotifier notifier;
private final boolean reportReferenceInfo;
private ISourceElementRequestor requestor;

MultiplexingIndexingParser(final ISourceElementRequestor requestor, final IProblemFactory problemFactory, final CompilerOptions options, final boolean reportLocalDeclarations, final boolean optimizeStringLiterals, final boolean useSourceJavadocParser) {
MultiplexingIndexingParser(final ISourceElementRequestor requestor, final IProblemFactory problemFactory, final CompilerOptions options,
final boolean reportLocalDeclarations, final boolean optimizeStringLiterals, final boolean useSourceJavadocParser) {
super(requestor, problemFactory, options, reportLocalDeclarations, optimizeStringLiterals, useSourceJavadocParser);
this.notifier = ReflectionUtils.getPrivateField(SourceElementParser.class, "notifier", this);
this.reportReferenceInfo = reportLocalDeclarations;
Expand All @@ -56,25 +57,17 @@ public void setRequestor(final ISourceElementRequestor requestor) {
@Override
public CompilationUnitDeclaration parseCompilationUnit(final ICompilationUnit compilationUnit, final boolean fullParse, final IProgressMonitor pm) {
if (GroovyParser.isGroovyParserEligible(compilationUnit, readManager)) {
// ASSUMPTIONS:
// 1) parsing is for the entire CU (ie- from character 0 to compilationUnit.getContents().length)
// 2) nodesToCategories map is not necessary. I think it has something to do with JavaDoc, but not sure
// 3) there is no difference between a diet and full parse in the groovy works, so can ignore the fullParse parameter

char[] contents = GroovyParser.getContents(compilationUnit, readManager);
String fileName = CharOperation.charToString(compilationUnit.getFileName());
CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 0, options.maxProblemsPerUnit);
CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, options.maxProblemsPerUnit);
GroovyCompilationUnitDeclaration gcud = new GroovyParser(options, problemReporter, false, true).dietParse(contents, fileName, compilationResult);

Optional.ofNullable(gcud.getModuleNode()).ifPresent(module -> {
try {
new GroovyIndexingVisitor(requestor).visitModule(module);
} catch (RuntimeException e) {
Util.log(e);
}
});
if (pm != null && pm.isCanceled())
throw new OperationCanceledException(Messages.operation_cancelled);

new GroovyIndexingVisitor(requestor).visitModule(gcud.getModuleNode());

notifier.notifySourceElementRequestor(gcud, 0, contents.length, reportReferenceInfo, gcud.sourceEnds, Collections.EMPTY_MAP);
notifier.notifySourceElementRequestor(gcud, 0, contents.length, reportReferenceInfo, gcud.sourceEnds, Collections.emptyMap());

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

scanner.setSource(contents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
*/
package org.codehaus.groovy.eclipse.refactoring.test.rename

import static org.eclipse.jdt.core.refactoring.IJavaRefactorings.RENAME_PACKAGE
import static org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor

import groovy.transform.AutoFinal
import groovy.transform.CompileStatic

import org.codehaus.groovy.eclipse.refactoring.test.rename.RenameRefactoringTestSuite.TestSource
import org.eclipse.jdt.core.ICompilationUnit
import org.eclipse.jdt.core.refactoring.IJavaRefactorings
import org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor
import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory
import org.eclipse.ltk.core.refactoring.Refactoring
import org.eclipse.ltk.core.refactoring.RefactoringCore
import org.eclipse.ltk.core.refactoring.RefactoringStatus
import org.junit.Test

@CompileStatic
@AutoFinal @CompileStatic
final class RenamePackageTests extends RenameRefactoringTestSuite {

/**
Expand All @@ -35,16 +36,14 @@ final class RenamePackageTests extends RenameRefactoringTestSuite {
private RefactoringStatus renamePackage(TestSource... sources) {
ICompilationUnit[] units = createUnits(sources)

RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.
createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE)
descriptor.updateTextualOccurrences = true
descriptor.updateReferences = true
descriptor.javaElement = packageFragmentRoot.getPackageFragment('p')
descriptor.newName = 'q'
Refactoring refactoring = createRefactoring(createRenameJavaElementDescriptor(RENAME_PACKAGE).tap {
javaElement = packageFragmentRoot.getPackageFragment('p'); newName = 'q'
updateReferences = true
})

RefactoringStatus result = performRefactoring(createRefactoring(descriptor))
result = ignoreKnownErrors(result)
assert result.isOK()
RefactoringStatus status = performRefactoring(refactoring)
status = ignoreKnownErrors(status)
assert status.isOK()

for (i in 0..<sources.length) {
if (sources[i].pack == 'p') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,20 @@ abstract class RenameRefactoringTestSuite extends GroovyEclipseTestSuite {
}.toArray(new ICompilationUnit[0])
}

@CompileDynamic
protected Refactoring createRefactoring(RefactoringDescriptor descriptor) {
RefactoringStatus status = new RefactoringStatus()
Refactoring refactoring = descriptor.createRefactoring(status)
assert refactoring != null

assert status.isOK()
assert refactoring.processor.isApplicable()
assert refactoring.processor.updateReferences

return refactoring
}

protected RefactoringStatus performRefactoring(Refactoring refactor, boolean providesUndo = true) {
def create = new CreateChangeOperation(new CheckConditionsOperation(refactor,
CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL)
def create = new CreateChangeOperation(new CheckConditionsOperation(refactor, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL)
def change = new PerformChangeOperation(create)
def undoer = RefactoringCore.getUndoManager()
change.setUndoManager(undoer, refactor.name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,6 @@ package org.codehaus.groovy.eclipse.refactoring.test.rename
import groovy.transform.CompileStatic
import groovy.transform.NotYetImplemented

import org.codehaus.groovy.eclipse.refactoring.test.rename.RenameRefactoringTestSuite.TestSource
import org.eclipse.jdt.core.IField
import org.eclipse.jdt.core.refactoring.IJavaRefactorings
import org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor
Expand Down

0 comments on commit a74edbe

Please sign in to comment.