Skip to content

Commit

Permalink
style fix-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Oct 12, 2020
1 parent 4fe2b4b commit fec194b
Show file tree
Hide file tree
Showing 31 changed files with 4,692 additions and 5,236 deletions.
14 changes: 7 additions & 7 deletions checkstyleConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -720,25 +720,25 @@
</module>
<module name="RegexpSingleline">
<property name="message" value="Superfluous ''()'' should be removed" />
<property name="format" value="(?&lt;!\.)@(?:\w+\.)*\w+\(\s*\)" />
<property name="format" value="(?&lt;!\|\s{0,99}|\.)@(?:\w+\.)*\w+\(\s*\)" />
<property name="fileExtensions" value="groovy" />
<property name="id" value="groovyAnnotationStyle:EmptyParens" />
</module>
<module name="RegexpSingleline">
<property name="message" value="Superfluous ''[]'' should be removed" />
<property name="format" value="(?&lt;!\.)@(?:\w+\.)*\w+\(\s*(?:\w+\s*=\s*)?\[\s*(?:[^,\]]*|([&apos;&quot;])[^&apos;&quot;]*\1)\]\s*\)" />
<property name="format" value="(?&lt;!\|\s{0,99}|\.)@(?:\w+\.)*\w+\(\s*(?:\w+\s*=\s*)?\[\s*(?:[^,\]]*|([&apos;&quot;])[^&apos;&quot;]*\1)\]\s*\)" />
<property name="fileExtensions" value="groovy" />
<property name="id" value="groovyAnnotationStyle:SingleValue" />
</module>
<module name="RegexpSingleline">
<property name="message" value="Superfluous ''value='' should be removed" />
<property name="format" value="(?&lt;!\.)@(?:\w+\.)*\w+\(\s*value\s*=\s*(?:(?:\w+\.)*\w+|\[[^\]]*\]|([&apos;&quot;])[^&apos;&quot;]*\1)\)" />
<property name="format" value="(?&lt;!\|\s{0,99}|\.)@(?:\w+\.)*\w+\(\s*value\s*=\s*(?:(?:\w+\.)*\w+|\[[^\]]*\]|([&apos;&quot;])[^&apos;&quot;]*\1)\)" />
<property name="fileExtensions" value="groovy" />
<property name="id" value="groovyAnnotationStyle:ValueLiteral" />
</module>
<module name="RegexpMultiline">
<module name="RegexpSingleline">
<property name="message" value="Groovy property notation should be used instead of accessors" />
<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}*\([^,]+\))" />
<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;](?:,|$))" />
<property name="fileExtensions" value="groovy" />
<property name="id" value="groovyPropertyAccess" />
</module>
Expand Down Expand Up @@ -787,13 +787,13 @@
</module>
<module name="RegexpSingleline">
<property name="message" value="Statement ''for (x in y)'' should be used instead of ''for (T x : y)''" />
<property name="format" value="\bfor\s*\(.+?\s+\w+\s*:" />
<property name="format" value="(?&lt;!\|\s{0,99})\bfor\s*\(.+?\s+\w+\s*:" />
<property name="fileExtensions" value="groovy" />
<property name="id" value="groovyForInStatement" />
</module>
<module name="RegexpSingleline">
<property name="message" value="Statement ''for (x in y)'' should be used instead of ''for (x in y.entrySet())''" />
<property name="format" value="\bfor\s*\(.+?\s+in\s+.+?\.entrySet\(\)\)" />
<property name="format" value="(?&lt;!\|\s{0,99})\bfor\s*\(.+?\s+in\s+.+?\.entrySet\(\)\)" />
<property name="fileExtensions" value="groovy" />
<property name="id" value="groovyForInStatement:MapEntrySet" />
</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ final class CodeSelectTypesTests extends BrowsingTestSuite {

@Test
void testSelectAnnotationClass5() {
String contents = 'import groovy.transform.*; @AnnotationCollector([EqualsAndHashCode]) public @interface Custom { }'
String contents = 'import groovy.transform.*; @AnnotationCollector(EqualsAndHashCode) @interface Custom { }'
assertCodeSelect([contents], 'EqualsAndHashCode')
}

@Test
void testSelectAnnotationClass5a() {
String contents = 'import groovy.transform.*; @EqualsAndHashCode @AnnotationCollector public @interface Custom { }'
String contents = 'import groovy.transform.*; @EqualsAndHashCode @AnnotationCollector @interface Custom { }'
assertCodeSelect([contents], 'EqualsAndHashCode')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.codehaus.groovy.eclipse.core.test

import groovy.transform.CompileStatic

import org.codehaus.groovy.eclipse.core.search.SyntheticAccessorSearchRequestor
import org.codehaus.groovy.eclipse.test.GroovyEclipseTestSuite
import org.eclipse.jdt.core.IJavaElement
Expand All @@ -26,6 +28,7 @@ import org.eclipse.jdt.core.search.SearchParticipant
import org.junit.Before
import org.junit.Test

@CompileStatic
final class SyntheticMemberSearchTests extends GroovyEclipseTestSuite {

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

gType = gUnit.getType('G')
assert gType?.exists()
}

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

/**
* asserts that the given match exists at least once in the list
* Ensures that the given match exists at least once in the list.
*/
private void assertMatch(String enclosingName, String matchName, String contents, List<SearchMatch> matches) {
int matchStart = 0
int matchIndex = 0
int matchStart = 0
boolean matchFound = false
for (match in matches) {
if ((match.element as IJavaElement).elementName == enclosingName &&
contents.indexOf(matchName, matchStart) == match.offset &&
matchName.length() == match.length) {
if (isMatchOf(enclosingName, matchName, matchStart, contents, match)) {
matchFound = true
break
}
matchIndex += 1
}
assert matchFound : "Match name $matchName not found in\n${matches.join('\n')}"
assert matchFound : "Match name $matchName not found in\n${ -> matches.join('\n')}"

SearchMatch match = matches.remove(matchIndex)
assert match.element.exists() : 'Match enclosing element does not exist'
assert (match.element as IJavaElement).exists()
}

private void assertNoMatch(String enclosingName, String matchName, String contents, List<SearchMatch> matches) {
boolean matchFound = matches.any { SearchMatch match ->
(match.element as IJavaElement).elementName == enclosingName &&
contents.indexOf(matchName) == match.offset &&
matchName.length() == match.length
}
assert !matchFound : "Match name $matchName was found, but should not have been.\n${matches.join('\n')}"
boolean matchFound = matches.any(this.&isMatchOf.curry(enclosingName, matchName, contents))
assert !matchFound : "Match name $matchName was found, but should not have been.\n${ -> matches.join('\n')}"
}

private static boolean isMatchOf(String enclosingName, String matchName, int matchStart = 0, String contents, SearchMatch match) {
(match.element as IJavaElement).elementName == enclosingName &&
contents.indexOf(matchName, matchStart) == match.offset &&
matchName.length() == match.length
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.codehaus.groovy.eclipse.refactoring.test

import org.codehaus.groovy.eclipse.refactoring.test.internal.JavaProjectHelper
import org.codehaus.groovy.eclipse.refactoring.test.internal.TestOptions
import org.codehaus.groovy.eclipse.refactoring.test.internal.TestRenameParticipantShared
import org.codehaus.groovy.eclipse.refactoring.test.internal.TestRenameParticipantSingle
import org.eclipse.core.resources.IResource
Expand All @@ -37,6 +36,8 @@ import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor
import org.eclipse.jdt.internal.corext.util.Strings
import org.eclipse.jdt.internal.ui.JavaPlugin
import org.eclipse.jdt.internal.ui.util.CoreUtility
import org.eclipse.jdt.ui.PreferenceConstants
import org.eclipse.jface.preference.IPreferenceStore
import org.eclipse.ltk.core.refactoring.Change
import org.eclipse.ltk.core.refactoring.ChangeDescriptor
import org.eclipse.ltk.core.refactoring.CheckConditionsOperation
Expand Down Expand Up @@ -70,16 +71,34 @@ abstract class RefactoringTestSuite {
static final void setUpTestSuite() {
fWasAutobuild = CoreUtility.setAutoBuilding(false)
fWasOptions = JavaCore.getOptions()
TestOptions.getDefaultOptions().with {
JavaCore.getDefaultOptions().with {
JavaCore.setComplianceOptions('1.8', it)
put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE)
put(JavaCore.COMPILER_PB_FIELD_HIDING, JavaCore.IGNORE)
put(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, JavaCore.IGNORE)
put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.IGNORE)
put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE)
put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.IGNORE)
put(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN, JavaCore.IGNORE)

put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, '4')
put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB)
put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, String.valueOf(9999))
put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, '0')

JavaCore.setOptions(it)
}
TestOptions.initializeCodeGenerationOptions()
JavaPlugin.getDefault().codeTemplateStore.load()

JavaPlugin.getDefault().with {
getCodeTemplateStore().load()
IPreferenceStore store = getPreferenceStore()
store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, true)
store.setValue(PreferenceConstants.CODEGEN_KEYWORD_THIS, false)
store.setValue(PreferenceConstants.CODEGEN_IS_FOR_GETTERS, true)
store.setValue(PreferenceConstants.CODEGEN_EXCEPTION_VAR_NAME, 'e')
store.setValue(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, 99)
store.setValue(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE, true)
store.setValue(PreferenceConstants.ORGIMPORTS_IMPORTORDER, 'java;javax;org;com')
}
fgJavaTestProject = JavaProjectHelper.createGroovyProject('TestProject', 'bin')
fgRoot = JavaProjectHelper.addSourceContainer(fgJavaTestProject, 'src')
fgPackageP = fgRoot.createPackageFragment('p', true, null)
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 @@ -17,24 +17,27 @@ package org.codehaus.groovy.eclipse.refactoring.test.extract

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

import groovy.transform.CompileStatic

import org.codehaus.groovy.eclipse.refactoring.core.convert.ConvertToMethodRefactoring
import org.codehaus.groovy.eclipse.refactoring.test.RefactoringTestSuite
import org.codehaus.jdt.groovy.model.GroovyCompilationUnit
import org.eclipse.jdt.internal.core.util.SimpleDocument
import org.junit.Assert
import org.junit.Test

@CompileStatic
final class ConvertFieldToMethodTests extends RefactoringTestSuite {

final String refactoringPath = null

private void doContentsCompareTest(CharSequence originalContents, CharSequence expectedContents = originalContents) {
def unit = (GroovyCompilationUnit) createCU(packageP, 'C.groovy', originalContents.stripIndent())
def unit = (GroovyCompilationUnit) createCU(packageP, 'C.groovy', originalContents.stripMargin())
def todo = new ConvertToMethodRefactoring(unit, indexOf('x' as char, unit.contents))
def document = new SimpleDocument(unit.contents as String)
todo.applyRefactoring(document)

def expect = expectedContents.stripIndent()
def expect = expectedContents.stripMargin()
Assert.assertEquals(expect, document.get())
}

Expand All @@ -43,72 +46,72 @@ final class ConvertFieldToMethodTests extends RefactoringTestSuite {
@Test
void testPropertyToMethod0() {
String originalContents = '''\
class C {
String x
String y
String z
}
'''
|class C {
| String x
| String y
| String z
|}
|'''
doContentsCompareTest(originalContents)
}

@Test
void testPropertyToMethod1() {
String originalContents = '''\
class C {
String x = { }
}
'''
|class C {
| String x = { }
|}
|'''
String expectedContents = '''\
class C {
String x() { }
}
'''
|class C {
| String x() { }
|}
|'''
doContentsCompareTest(originalContents, expectedContents)
}

@Test
void testPropertyToMethod2() {
String originalContents = '''\
class C {
String x = { -> }
}
'''
|class C {
| String x = { -> }
|}
|'''
String expectedContents = '''\
class C {
String x() { }
}
'''
|class C {
| String x() { }
|}
|'''
doContentsCompareTest(originalContents, expectedContents)
}

@Test
void testPropertyToMethod3() {
String originalContents = '''\
class C {
String x = { a -> print '' }
}
'''
|class C {
| String x = { a -> print '' }
|}
|'''
String expectedContents = '''\
class C {
String x(a) { print '' }
}
'''
|class C {
| String x(a) { print '' }
|}
|'''
doContentsCompareTest(originalContents, expectedContents)
}

@Test
void testPropertyToMethod4() {
String originalContents = '''\
class C {
String x = { a, ... b -> print '' }
}
'''
|class C {
| String x = { a, ... b -> print '' }
|}
|'''
String expectedContents = '''\
class C {
String x(a, ... b) { print '' }
}
'''
|class C {
| String x(a, ... b) { print '' }
|}
|'''
doContentsCompareTest(originalContents, expectedContents)
}
}
Loading

0 comments on commit fec194b

Please sign in to comment.