Skip to content

Commit

Permalink
Fix for #1317: title-case variable expression isn't missing type
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 4, 2021
1 parent 7be85a9 commit e17d6ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,17 @@ final class OrganizeImportsTests extends OrganizeImportsTestSuite {
doAddImportTest(contents, ['java.text.DateFormat'])
}

@Test
void testTitleCaseVariable() {
createGroovyType 'p', 'Q', 'class Q {}'

String contents = '''\
|def Q = null
|def q = Q
|'''
doContentsCompareTest(contents, contents)
}

@Test // GRECLISPE-823
void testThrownExceptions() {
String originalContents = '''\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.codehaus.groovy.eclipse.refactoring.actions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -319,7 +320,7 @@ private void pruneMissingTypes(Iterable<ImportNode> imports) throws JavaModelExc

private IType[] resolveMissingTypes(IProgressMonitor monitor) throws JavaModelException {
// fill in all the potential matches
new TypeSearch().searchForTypes(unit, missingTypes, monitor);
new TypeSearch().searchForTypes(unit, Collections.unmodifiableMap(missingTypes), monitor);

List<TypeNameMatch> missingTypesNoChoiceRequired = new ArrayList<>();
List<TypeNameMatch[]> missingTypesChoiceRequired = new ArrayList<>();
Expand Down Expand Up @@ -594,8 +595,8 @@ public void visitVariableExpression(VariableExpression expression) {
// Assume dynamic variables are a candidate for organize imports,
// but only if name begins with a capital letter and does not match
// the idiomatic static constant naming. This will hopefully filter
// out false positives, but misses types that start with lower case.
if (expression.getAccessedVariable() instanceof DynamicVariable || expression.isDynamicTyped()) {
// out false positives but misses types that start with lower case.
if (expression.getAccessedVariable() instanceof DynamicVariable) {
if (!checkRetainImport(expression.getName())) { // could it be static?
String name = expression.getName();
if (!missingTypes.containsKey(name) &&
Expand Down

0 comments on commit e17d6ea

Please sign in to comment.