Skip to content

Commit fec194b

Browse files
committed
style fix-ups
1 parent 4fe2b4b commit fec194b

31 files changed

+4692
-5236
lines changed

checkstyleConfig.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -720,25 +720,25 @@
720720
</module>
721721
<module name="RegexpSingleline">
722722
<property name="message" value="Superfluous ''()'' should be removed" />
723-
<property name="format" value="(?&lt;!\.)@(?:\w+\.)*\w+\(\s*\)" />
723+
<property name="format" value="(?&lt;!\|\s{0,99}|\.)@(?:\w+\.)*\w+\(\s*\)" />
724724
<property name="fileExtensions" value="groovy" />
725725
<property name="id" value="groovyAnnotationStyle:EmptyParens" />
726726
</module>
727727
<module name="RegexpSingleline">
728728
<property name="message" value="Superfluous ''[]'' should be removed" />
729-
<property name="format" value="(?&lt;!\.)@(?:\w+\.)*\w+\(\s*(?:\w+\s*=\s*)?\[\s*(?:[^,\]]*|([&apos;&quot;])[^&apos;&quot;]*\1)\]\s*\)" />
729+
<property name="format" value="(?&lt;!\|\s{0,99}|\.)@(?:\w+\.)*\w+\(\s*(?:\w+\s*=\s*)?\[\s*(?:[^,\]]*|([&apos;&quot;])[^&apos;&quot;]*\1)\]\s*\)" />
730730
<property name="fileExtensions" value="groovy" />
731731
<property name="id" value="groovyAnnotationStyle:SingleValue" />
732732
</module>
733733
<module name="RegexpSingleline">
734734
<property name="message" value="Superfluous ''value='' should be removed" />
735-
<property name="format" value="(?&lt;!\.)@(?:\w+\.)*\w+\(\s*value\s*=\s*(?:(?:\w+\.)*\w+|\[[^\]]*\]|([&apos;&quot;])[^&apos;&quot;]*\1)\)" />
735+
<property name="format" value="(?&lt;!\|\s{0,99}|\.)@(?:\w+\.)*\w+\(\s*value\s*=\s*(?:(?:\w+\.)*\w+|\[[^\]]*\]|([&apos;&quot;])[^&apos;&quot;]*\1)\)" />
736736
<property name="fileExtensions" value="groovy" />
737737
<property name="id" value="groovyAnnotationStyle:ValueLiteral" />
738738
</module>
739-
<module name="RegexpMultiline">
739+
<module name="RegexpSingleline">
740740
<property name="message" value="Groovy property notation should be used instead of accessors" />
741-
<property name="format" value="(?&lt;!\b\p{Upper}\w{0,99}\s{0,99})\.(get\p{Upper}\p{Alnum}*\(\s*\)|set\p{Upper}\p{Alnum}*\([^,]+\))" />
741+
<property name="format" value="^(?!\s*\|(?!\|)).*(?&lt;!\b\p{Upper}\w{0,99}\s{0,99})\.(get\p{Upper}\p{Alnum}*\(\s*\)|set\p{Upper}\p{Alnum}*\([^,]+\))(?!;?[&apos;&quot;](?:,|$))" />
742742
<property name="fileExtensions" value="groovy" />
743743
<property name="id" value="groovyPropertyAccess" />
744744
</module>
@@ -787,13 +787,13 @@
787787
</module>
788788
<module name="RegexpSingleline">
789789
<property name="message" value="Statement ''for (x in y)'' should be used instead of ''for (T x : y)''" />
790-
<property name="format" value="\bfor\s*\(.+?\s+\w+\s*:" />
790+
<property name="format" value="(?&lt;!\|\s{0,99})\bfor\s*\(.+?\s+\w+\s*:" />
791791
<property name="fileExtensions" value="groovy" />
792792
<property name="id" value="groovyForInStatement" />
793793
</module>
794794
<module name="RegexpSingleline">
795795
<property name="message" value="Statement ''for (x in y)'' should be used instead of ''for (x in y.entrySet())''" />
796-
<property name="format" value="\bfor\s*\(.+?\s+in\s+.+?\.entrySet\(\)\)" />
796+
<property name="format" value="(?&lt;!\|\s{0,99})\bfor\s*\(.+?\s+in\s+.+?\.entrySet\(\)\)" />
797797
<property name="fileExtensions" value="groovy" />
798798
<property name="id" value="groovyForInStatement:MapEntrySet" />
799799
</module>

ide-test/org.codehaus.groovy.eclipse.codebrowsing.test/src/org/codehaus/groovy/eclipse/codebrowsing/tests/CodeSelectTypesTests.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ final class CodeSelectTypesTests extends BrowsingTestSuite {
141141

142142
@Test
143143
void testSelectAnnotationClass5() {
144-
String contents = 'import groovy.transform.*; @AnnotationCollector([EqualsAndHashCode]) public @interface Custom { }'
144+
String contents = 'import groovy.transform.*; @AnnotationCollector(EqualsAndHashCode) @interface Custom { }'
145145
assertCodeSelect([contents], 'EqualsAndHashCode')
146146
}
147147

148148
@Test
149149
void testSelectAnnotationClass5a() {
150-
String contents = 'import groovy.transform.*; @EqualsAndHashCode @AnnotationCollector public @interface Custom { }'
150+
String contents = 'import groovy.transform.*; @EqualsAndHashCode @AnnotationCollector @interface Custom { }'
151151
assertCodeSelect([contents], 'EqualsAndHashCode')
152152
}
153153

ide-test/org.codehaus.groovy.eclipse.core.test/src/org/codehaus/groovy/eclipse/core/test/SyntheticMemberSearchTests.groovy

+18-13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.codehaus.groovy.eclipse.core.test
1717

18+
import groovy.transform.CompileStatic
19+
1820
import org.codehaus.groovy.eclipse.core.search.SyntheticAccessorSearchRequestor
1921
import org.codehaus.groovy.eclipse.test.GroovyEclipseTestSuite
2022
import org.eclipse.jdt.core.IJavaElement
@@ -26,6 +28,7 @@ import org.eclipse.jdt.core.search.SearchParticipant
2628
import org.junit.Before
2729
import org.junit.Test
2830

31+
@CompileStatic
2932
final class SyntheticMemberSearchTests extends GroovyEclipseTestSuite {
3033

3134
private IType gType
@@ -43,6 +46,7 @@ final class SyntheticMemberSearchTests extends GroovyEclipseTestSuite {
4346
|'''.stripMargin(), 'G', 'p'
4447

4548
gType = gUnit.getType('G')
49+
assert gType?.exists()
4650
}
4751

4852
@Test // references to property itself and synthetic accessors
@@ -272,32 +276,33 @@ final class SyntheticMemberSearchTests extends GroovyEclipseTestSuite {
272276
}
273277

274278
/**
275-
* asserts that the given match exists at least once in the list
279+
* Ensures that the given match exists at least once in the list.
276280
*/
277281
private void assertMatch(String enclosingName, String matchName, String contents, List<SearchMatch> matches) {
278-
int matchStart = 0
279282
int matchIndex = 0
283+
int matchStart = 0
280284
boolean matchFound = false
281285
for (match in matches) {
282-
if ((match.element as IJavaElement).elementName == enclosingName &&
283-
contents.indexOf(matchName, matchStart) == match.offset &&
284-
matchName.length() == match.length) {
286+
if (isMatchOf(enclosingName, matchName, matchStart, contents, match)) {
285287
matchFound = true
286288
break
287289
}
288290
matchIndex += 1
289291
}
290-
assert matchFound : "Match name $matchName not found in\n${matches.join('\n')}"
292+
assert matchFound : "Match name $matchName not found in\n${ -> matches.join('\n')}"
293+
291294
SearchMatch match = matches.remove(matchIndex)
292-
assert match.element.exists() : 'Match enclosing element does not exist'
295+
assert (match.element as IJavaElement).exists()
293296
}
294297

295298
private void assertNoMatch(String enclosingName, String matchName, String contents, List<SearchMatch> matches) {
296-
boolean matchFound = matches.any { SearchMatch match ->
297-
(match.element as IJavaElement).elementName == enclosingName &&
298-
contents.indexOf(matchName) == match.offset &&
299-
matchName.length() == match.length
300-
}
301-
assert !matchFound : "Match name $matchName was found, but should not have been.\n${matches.join('\n')}"
299+
boolean matchFound = matches.any(this.&isMatchOf.curry(enclosingName, matchName, contents))
300+
assert !matchFound : "Match name $matchName was found, but should not have been.\n${ -> matches.join('\n')}"
301+
}
302+
303+
private static boolean isMatchOf(String enclosingName, String matchName, int matchStart = 0, String contents, SearchMatch match) {
304+
(match.element as IJavaElement).elementName == enclosingName &&
305+
contents.indexOf(matchName, matchStart) == match.offset &&
306+
matchName.length() == match.length
302307
}
303308
}

ide-test/org.codehaus.groovy.eclipse.refactoring.test/src/org/codehaus/groovy/eclipse/refactoring/test/RefactoringTestSuite.groovy

+24-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.codehaus.groovy.eclipse.refactoring.test
1717

1818
import org.codehaus.groovy.eclipse.refactoring.test.internal.JavaProjectHelper
19-
import org.codehaus.groovy.eclipse.refactoring.test.internal.TestOptions
2019
import org.codehaus.groovy.eclipse.refactoring.test.internal.TestRenameParticipantShared
2120
import org.codehaus.groovy.eclipse.refactoring.test.internal.TestRenameParticipantSingle
2221
import org.eclipse.core.resources.IResource
@@ -37,6 +36,8 @@ import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor
3736
import org.eclipse.jdt.internal.corext.util.Strings
3837
import org.eclipse.jdt.internal.ui.JavaPlugin
3938
import org.eclipse.jdt.internal.ui.util.CoreUtility
39+
import org.eclipse.jdt.ui.PreferenceConstants
40+
import org.eclipse.jface.preference.IPreferenceStore
4041
import org.eclipse.ltk.core.refactoring.Change
4142
import org.eclipse.ltk.core.refactoring.ChangeDescriptor
4243
import org.eclipse.ltk.core.refactoring.CheckConditionsOperation
@@ -70,16 +71,34 @@ abstract class RefactoringTestSuite {
7071
static final void setUpTestSuite() {
7172
fWasAutobuild = CoreUtility.setAutoBuilding(false)
7273
fWasOptions = JavaCore.getOptions()
73-
TestOptions.getDefaultOptions().with {
74+
JavaCore.getDefaultOptions().with {
75+
JavaCore.setComplianceOptions('1.8', it)
76+
put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE)
77+
put(JavaCore.COMPILER_PB_FIELD_HIDING, JavaCore.IGNORE)
78+
put(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, JavaCore.IGNORE)
79+
put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.IGNORE)
80+
put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE)
81+
put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.IGNORE)
82+
put(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN, JavaCore.IGNORE)
83+
7484
put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, '4')
7585
put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB)
7686
put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, String.valueOf(9999))
7787
put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, '0')
88+
7889
JavaCore.setOptions(it)
7990
}
80-
TestOptions.initializeCodeGenerationOptions()
81-
JavaPlugin.getDefault().codeTemplateStore.load()
82-
91+
JavaPlugin.getDefault().with {
92+
getCodeTemplateStore().load()
93+
IPreferenceStore store = getPreferenceStore()
94+
store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, true)
95+
store.setValue(PreferenceConstants.CODEGEN_KEYWORD_THIS, false)
96+
store.setValue(PreferenceConstants.CODEGEN_IS_FOR_GETTERS, true)
97+
store.setValue(PreferenceConstants.CODEGEN_EXCEPTION_VAR_NAME, 'e')
98+
store.setValue(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, 99)
99+
store.setValue(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE, true)
100+
store.setValue(PreferenceConstants.ORGIMPORTS_IMPORTORDER, 'java;javax;org;com')
101+
}
83102
fgJavaTestProject = JavaProjectHelper.createGroovyProject('TestProject', 'bin')
84103
fgRoot = JavaProjectHelper.addSourceContainer(fgJavaTestProject, 'src')
85104
fgPackageP = fgRoot.createPackageFragment('p', true, null)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,24 +17,27 @@ package org.codehaus.groovy.eclipse.refactoring.test.extract
1717

1818
import static org.eclipse.jdt.core.compiler.CharOperation.indexOf
1919

20+
import groovy.transform.CompileStatic
21+
2022
import org.codehaus.groovy.eclipse.refactoring.core.convert.ConvertToMethodRefactoring
2123
import org.codehaus.groovy.eclipse.refactoring.test.RefactoringTestSuite
2224
import org.codehaus.jdt.groovy.model.GroovyCompilationUnit
2325
import org.eclipse.jdt.internal.core.util.SimpleDocument
2426
import org.junit.Assert
2527
import org.junit.Test
2628

29+
@CompileStatic
2730
final class ConvertFieldToMethodTests extends RefactoringTestSuite {
2831

2932
final String refactoringPath = null
3033

3134
private void doContentsCompareTest(CharSequence originalContents, CharSequence expectedContents = originalContents) {
32-
def unit = (GroovyCompilationUnit) createCU(packageP, 'C.groovy', originalContents.stripIndent())
35+
def unit = (GroovyCompilationUnit) createCU(packageP, 'C.groovy', originalContents.stripMargin())
3336
def todo = new ConvertToMethodRefactoring(unit, indexOf('x' as char, unit.contents))
3437
def document = new SimpleDocument(unit.contents as String)
3538
todo.applyRefactoring(document)
3639

37-
def expect = expectedContents.stripIndent()
40+
def expect = expectedContents.stripMargin()
3841
Assert.assertEquals(expect, document.get())
3942
}
4043

@@ -43,72 +46,72 @@ final class ConvertFieldToMethodTests extends RefactoringTestSuite {
4346
@Test
4447
void testPropertyToMethod0() {
4548
String originalContents = '''\
46-
class C {
47-
String x
48-
String y
49-
String z
50-
}
51-
'''
49+
|class C {
50+
| String x
51+
| String y
52+
| String z
53+
|}
54+
|'''
5255
doContentsCompareTest(originalContents)
5356
}
5457

5558
@Test
5659
void testPropertyToMethod1() {
5760
String originalContents = '''\
58-
class C {
59-
String x = { }
60-
}
61-
'''
61+
|class C {
62+
| String x = { }
63+
|}
64+
|'''
6265
String expectedContents = '''\
63-
class C {
64-
String x() { }
65-
}
66-
'''
66+
|class C {
67+
| String x() { }
68+
|}
69+
|'''
6770
doContentsCompareTest(originalContents, expectedContents)
6871
}
6972

7073
@Test
7174
void testPropertyToMethod2() {
7275
String originalContents = '''\
73-
class C {
74-
String x = { -> }
75-
}
76-
'''
76+
|class C {
77+
| String x = { -> }
78+
|}
79+
|'''
7780
String expectedContents = '''\
78-
class C {
79-
String x() { }
80-
}
81-
'''
81+
|class C {
82+
| String x() { }
83+
|}
84+
|'''
8285
doContentsCompareTest(originalContents, expectedContents)
8386
}
8487

8588
@Test
8689
void testPropertyToMethod3() {
8790
String originalContents = '''\
88-
class C {
89-
String x = { a -> print '' }
90-
}
91-
'''
91+
|class C {
92+
| String x = { a -> print '' }
93+
|}
94+
|'''
9295
String expectedContents = '''\
93-
class C {
94-
String x(a) { print '' }
95-
}
96-
'''
96+
|class C {
97+
| String x(a) { print '' }
98+
|}
99+
|'''
97100
doContentsCompareTest(originalContents, expectedContents)
98101
}
99102

100103
@Test
101104
void testPropertyToMethod4() {
102105
String originalContents = '''\
103-
class C {
104-
String x = { a, ... b -> print '' }
105-
}
106-
'''
106+
|class C {
107+
| String x = { a, ... b -> print '' }
108+
|}
109+
|'''
107110
String expectedContents = '''\
108-
class C {
109-
String x(a, ... b) { print '' }
110-
}
111-
'''
111+
|class C {
112+
| String x(a, ... b) { print '' }
113+
|}
114+
|'''
112115
doContentsCompareTest(originalContents, expectedContents)
113116
}
114117
}

0 commit comments

Comments
 (0)