Skip to content

Commit

Permalink
spotlessApply
Browse files Browse the repository at this point in the history
  • Loading branch information
blacelle committed Mar 7, 2023
1 parent 53f3fcf commit 920c320
Show file tree
Hide file tree
Showing 216 changed files with 984 additions and 1,014 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public Bundle getBundle(String location) {
@Override
public ServiceReference<?>[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
//Filters are based on class names
String interfaceClassName = (null == clazz) ? filter : clazz;
var interfaceClassName = (null == clazz) ? filter : clazz;
return services.getReferences(interfaceClassName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ResourceAccessor {
/** Resources are located in the JAR of the given class
* @throws BundleException */
ResourceAccessor(Class<?> clazz) throws BundleException {
String bundleObjPath = clazz.getName();
var bundleObjPath = clazz.getName();
fatJarResourcePath = bundleObjPath.substring(0, bundleObjPath.lastIndexOf('.'));
try {
bundleFile = getBundlFile(clazz);
Expand All @@ -74,7 +74,7 @@ class ResourceAccessor {

private static BundleFile getBundlFile(Class<?> clazz) throws BundleException {
URI objUri = getBundleUri(clazz);
File jarOrDirectory = new File(objUri.getPath());
var jarOrDirectory = new File(objUri.getPath());
if (!(jarOrDirectory.exists() && jarOrDirectory.canRead())) {
throw new BundleException(String.format("Path '%s' for '%s' is not accessible exist on local file system.", objUri, clazz.getName()), BundleException.READ_ERROR);
}
Expand All @@ -87,7 +87,7 @@ private static BundleFile getBundlFile(Class<?> clazz) throws BundleException {

private static URI getBundleUri(Class<?> clazz) throws BundleException {
try {
URL objUrl = clazz.getProtectionDomain().getCodeSource().getLocation();
var objUrl = clazz.getProtectionDomain().getCodeSource().getLocation();
return objUrl.toURI();
} catch (NullPointerException e) {
//No bunlde should be used for RT classes lookup. See also org.eclipse.core.runtime.PerformanceStats.
Expand All @@ -101,10 +101,10 @@ private static URI getBundleUri(Class<?> clazz) throws BundleException {

/** Get the manifest name from the resources. */
String getManifestName() throws BundleException {
URL manifestUrl = getEntry(JarFile.MANIFEST_NAME);
var manifestUrl = getEntry(JarFile.MANIFEST_NAME);
if (null != manifestUrl) {
try {
Manifest manifest = new Manifest(manifestUrl.openStream());
var manifest = new Manifest(manifestUrl.openStream());
String headerValue = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
if (null == headerValue) {
throw new BundleException(String.format("Symbolic values not found in '%s'.", manifestUrl), BundleException.MANIFEST_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void set(String key, String value) {

@Override
public <S> void add(Class<S> interfaceClass, S service) throws ServiceException {
String className = interfaceClass.getName();
var className = interfaceClass.getName();
if (null != className2Service.put(interfaceClass.getName(), new FrameworkServiceReference<S>(className, service))) {
throw new ServiceException(
String.format("Service '%s' is already registered.", interfaceClass.getName()), ServiceException.FACTORY_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class PluginRegistrar {
private static final String PLUGIN_PROPERTIES = "plugin.properties";

public static BundleException register(Bundle bundle) {
PluginRegistrar registrar = new PluginRegistrar(bundle);
var registrar = new PluginRegistrar(bundle);
try {
registrar.register();
} catch (BundleException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public long getTime() {

@Override
public String toString() {
StringWriter result = new StringWriter();
var result = new StringWriter();
result.write(message);
if (execption.isPresent()) {
result.write('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private TemporaryLocation(Location parent, URL defaultValue) {

private static URL createTemporaryDirectory() {
try {
Path location = Files.createTempDirectory(TEMP_PREFIX);
var location = Files.createTempDirectory(TEMP_PREFIX);
return location.toUri().toURL();
} catch (IOException e) {
throw new IOError(e);
Expand Down Expand Up @@ -120,7 +120,7 @@ public Location createLocation(Location parent, URL defaultValue, boolean readon
@Override
public URL getDataArea(String path) throws IOException {
try {
Path locationPath = Paths.get(location.toURI());
var locationPath = Paths.get(location.toURI());
return locationPath.resolve(path).toUri().toURL();
} catch (URISyntaxException e) {
throw new IOException("Location not correctly formatted.", e);
Expand All @@ -130,7 +130,7 @@ public URL getDataArea(String path) throws IOException {
@Override
public void close() throws Exception {
try {
Path path = Path.of(location.toURI());
var path = Path.of(location.toURI());
Files.walk(path)
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void println(String x) {
@Override
public void println(Object x) {
if (x instanceof Exception) {
Exception e = (Exception) x;
var e = (Exception) x;
if (TEST_EXCEPTION_MESSAGE == e.getMessage()) {
messages.add(TEST_EXCEPTION_MESSAGE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void testAddGet() throws BundleException {

@Test
void testSameSymbolicName() throws BundleException {
final String symbolicName = "sym.a";
final var symbolicName = "sym.a";
final long id1 = 12345;
final long id2 = 23456;
Bundle testBundle1 = new TestBundle(id1, symbolicName);
Expand All @@ -63,8 +63,8 @@ void testSameSymbolicName() throws BundleException {

@Test
void testSameID() throws BundleException {
final String symbolicName1 = "sym.a";
final String symbolicName2 = "sym.b";
final var symbolicName1 = "sym.a";
final var symbolicName2 = "sym.b";
final long id = 12345;
Bundle testBundle1 = new TestBundle(id, symbolicName1);
Bundle testBundle2 = new TestBundle(id, symbolicName2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void initialize() {

@Test
void testAddGet() {
Service1 service1 = new Service1();
Service2 service2 = new Service2();
var service1 = new Service1();
var service2 = new Service2();
instance.add(Interf1.class, service1);
instance.add(Interf2a.class, service2);
instance.add(Interf2b.class, service2);
Expand All @@ -51,8 +51,8 @@ void testAddGet() {

@Test
void testMultipleServicesPerInterface() {
Service1 serviceX = new Service1();
Service1 serviceY = new Service1();
var serviceX = new Service1();
var serviceY = new Service1();
instance.add(Interf1.class, serviceX);
ServiceException e = assertThrows(ServiceException.class, () -> instance.add(Interf1.class, serviceY));
assertThat(e.getMessage()).as("ServiceException does not contain interface class name.").contains(Interf1.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ class EclipseCdtFormatterStepImplTest {

@Test
void defaultFormat() throws Throwable {
String output = format(CPP_UNFORMATTED, config -> {});
var output = format(CPP_UNFORMATTED, config -> {});
assertEquals(CPP_FORMATTED,
output, "Unexpected formatting with default preferences.");
}

@Test
void invalidFormat() throws Throwable {
String output = format(CPP_FORMATTED.replace("int main() {", "int main() "), config -> {});
var output = format(CPP_FORMATTED.replace("int main() {", "int main() "), config -> {});
assertTrue(output.contains("int main()" + LINE_DELIMITER), "Incomplete CPP not formatted on best effort basis.");
}

@Test
void invalidCharater() throws Throwable {
String output = format(CPP_FORMATTED.replace("int main() {", "int main()" + ILLEGAL_CHAR + " {"), config -> {});
var output = format(CPP_FORMATTED.replace("int main() {", "int main()" + ILLEGAL_CHAR + " {"), config -> {});
assertTrue(output.contains("int main()" + LINE_DELIMITER), "Invalid charater not formatted on best effort basis.");
}

@Test
void invalidConfiguration() throws Throwable {
String output = format(CPP_FORMATTED, config -> {
var output = format(CPP_FORMATTED, config -> {
config.setProperty(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
config.setProperty(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "noInteger");
});
Expand All @@ -79,19 +79,19 @@ void invalidConfiguration() throws Throwable {

@Test
void htmlCommentFormat() throws Throwable {
String output = format(DOXYGEN_HTML + CPP_FORMATTED, config -> {});
var output = format(DOXYGEN_HTML + CPP_FORMATTED, config -> {});
assertEquals(DOXYGEN_HTML + CPP_FORMATTED,
output, "HTML comments not ignored by formatter.");
}

@Test
void regionWarning() throws Throwable {
String output = format(FUNCT_PTR_UNFORMATTED, config -> {});
var output = format(FUNCT_PTR_UNFORMATTED, config -> {});
assertEquals(FUNCT_PTR_FORMATTED, output, "Code not formatted at all due to regional error.");
}

private static String format(final String input, final Consumer<Properties> config) throws Exception {
Properties properties = new Properties();
var properties = new Properties();
config.accept(properties);
EclipseCdtFormatterStepImpl formatter = new EclipseCdtFormatterStepImpl(properties);
return formatter.format(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void activatePlugins(SpotlessEclipsePluginConfig config) {
/** Formatting Groovy string */
public String format(String raw) throws Exception {
IDocument doc = new Document(raw);
GroovyErrorListener errorListener = new GroovyErrorListener();
var errorListener = new GroovyErrorListener();
TextSelection selectAll = new TextSelection(doc, 0, doc.getLength());
GroovyFormatter codeFormatter = new DefaultGroovyFormatter(selectAll, doc, preferencesStore, false);
TextEdit edit = codeFormatter.format();
Expand Down Expand Up @@ -127,7 +127,7 @@ public boolean errorsDetected() {

@Override
public String toString() {
StringBuilder string = new StringBuilder();
var string = new StringBuilder();
if (1 < errors.size()) {
string.append("Multiple problems detected during step execution:");
} else if (0 == errors.size()) {
Expand Down Expand Up @@ -161,9 +161,9 @@ public void log(TraceCategory arg0, String arg1) {

private static PreferenceStore createPreferences(final Properties properties) throws IOException {
final PreferenceStore preferences = new PreferenceStore();
ByteArrayOutputStream output = new ByteArrayOutputStream();
var output = new ByteArrayOutputStream();
properties.store(output, null);
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
var input = new ByteArrayInputStream(output.toByteArray());
preferences.load(input);
return preferences;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void scannerException() throws Throwable {
*/
@Test
void boundedWildCards() throws Throwable {
String output = format(BOUNDED_WILDCARDS_UNFORMATTED, config -> {});
var output = format(BOUNDED_WILDCARDS_UNFORMATTED, config -> {});
assertEquals(BOUNDED_WILDCARDS_FORMATTED,
output, "Unexpected formatting after bounded wildcards.");
}
Expand All @@ -96,7 +96,7 @@ void ignoreCompilerProblems() throws Throwable {
}

private static String format(final String input, final Consumer<Properties> config) throws Exception {
Properties properties = new Properties();
var properties = new Properties();
config.accept(properties);
GrEclipseFormatterStepImpl formatter = new GrEclipseFormatterStepImpl(properties);
return formatter.format(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

public class TestData {
public static TestData getTestDataOnFileSystem() {
final String userDir = System.getProperty("user.dir", ".");
Path dataPath = Paths.get(userDir, "src", "test", "resources");
final var userDir = System.getProperty("user.dir", ".");
var dataPath = Paths.get(userDir, "src", "test", "resources");
if (Files.isDirectory(dataPath)) {
return new TestData(dataPath);
}
Expand All @@ -48,7 +48,7 @@ public String input(final String fileName) throws Exception {
}

public String expected(final String fileName) {
Path path = expectedPath.resolve(fileName);
var path = expectedPath.resolve(fileName);
return read(path);
}

Expand All @@ -57,7 +57,7 @@ private String read(final Path xmlPath) {
throw new IllegalArgumentException(String.format("'%1$s' is not a regular file.", xmlPath));
}
try {
String checkedOutFileContent = new String(java.nio.file.Files.readAllBytes(xmlPath), "UTF8");
var checkedOutFileContent = new String(java.nio.file.Files.readAllBytes(xmlPath), "UTF8");
return checkedOutFileContent.replace("\r", ""); //Align GIT end-of-line normalization
} catch (IOException e) {
throw new IllegalArgumentException(String.format("Failed to read '%1$s'.", xmlPath), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void nominal() throws Throwable {
@Test
public void invalidSyntax() throws Throwable {
try {
String invalidSyntax = FORMATTED.replace("{", "");
var invalidSyntax = FORMATTED.replace("{", "");
assertEquals(invalidSyntax, format(invalidSyntax));
} catch (IndexOutOfBoundsException e) {
/*
Expand All @@ -72,15 +72,15 @@ public void invalidSyntax() throws Throwable {

@Test
void invalidCharater() throws Throwable {
String invalidInput = UNFORMATTED + ILLEGAL_CHAR;
var invalidInput = UNFORMATTED + ILLEGAL_CHAR;
assertEquals(invalidInput, format(invalidInput));
}

@Test
void invalidConfiguration() throws Throwable {
config.setProperty(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
config.setProperty(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "noInteger");
String defaultTabReplacement = " ";
var defaultTabReplacement = " ";
assertEquals(FORMATTED.replace("\t", defaultTabReplacement), format(FORMATTED));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void activatePlugins(SpotlessEclipsePluginConfig config) {
* The HTML formatter only uses the DOCTYPE/SCHEMA for content model selection.
* Hence no external URIs are required.
*/
boolean allowExternalURI = false;
var allowExternalURI = false;
EclipseXmlFormatterStepImpl.FrameworkConfig.activateXmlPlugins(config, allowExternalURI);
config.add(new HTMLCorePlugin());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public StructuredDocumentProcessor(IStructuredDocument document, String type,

/** Applies processor on document, using a given formatter */
public void apply(T formatter) {
for (int currentRegionId = 0; currentRegionId < numberOfRegions; currentRegionId++) {
for (var currentRegionId = 0; currentRegionId < numberOfRegions; currentRegionId++) {
applyOnRegion(currentRegionId, formatter);
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public int getLastLine() {
}

private static int computeIndent(IStructuredDocument document, ITypedRegion region, String htmlIndent) {
int indent = 0;
var indent = 0;
try {
int lineNumber = document.getLineOfOffset(region.getOffset());
document.getNumberOfLines();
Expand Down Expand Up @@ -180,7 +180,7 @@ protected void fixTagIndent(MultiTextEdit modifications, int offset, String inde
int lineStart = document.getLineOffset(lineNumber);
int lineEnd = document.getLineOffset(lineNumber + 1);
String lineContent = document.get(lineStart, lineEnd - lineStart);
StringBuilder currentIndent = new StringBuilder();
var currentIndent = new StringBuilder();
lineContent.chars().filter(c -> {
if (c == ' ' || c == '\t') {
currentIndent.append(c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public static void configureCatalog(final Properties properties, final ICatalog
throw new IllegalArgumentException("Internal error: Catalog implementation '" + defaultCatalogInterface.getClass().getCanonicalName() + "' unsupported.");
}
Catalog defaultCatalog = (Catalog) defaultCatalogInterface;
String catalogProperty = properties.getProperty(USER_CATALOG, "");
var catalogProperty = properties.getProperty(USER_CATALOG, "");
if (!catalogProperty.isEmpty()) {
final File catalogFile = new File(catalogProperty);
final var catalogFile = new File(catalogProperty);
try {
InputStream inputStream = new FileInputStream(catalogFile);
String orgBase = defaultCatalog.getBase();
Expand All @@ -118,7 +118,7 @@ public static void configureCatalog(final Properties properties, final ICatalog
public static void assertNoChanges(Plugin plugin, Properties properties) {
Objects.requireNonNull(properties, "Property values are missing.");
final String preferenceId = plugin.getBundle().getSymbolicName();
Properties originalValues = CONFIG.get(preferenceId);
var originalValues = CONFIG.get(preferenceId);
if (null == originalValues) {
throw new IllegalArgumentException("No configuration found for " + preferenceId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void initialize() throws Exception {
* All formatter configuration is stored in
* org.eclipse.core.runtime/.settings/org.eclipse.wst.css.core.prefs.
*/
Properties properties = new Properties();
var properties = new Properties();
properties.put(INDENTATION_SIZE, "3");
properties.put(INDENTATION_CHAR, SPACE); //Default is TAB
properties.put(CLEANUP_CASE_SELECTOR, Integer.toString(UPPER)); //Done by cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void initialize() throws Exception {
* org.eclipse.core.runtime/.settings/org.eclipse.wst.xml.core.prefs.
* So a simple test of one configuration item change is considered sufficient.
*/
Properties properties = new Properties();
var properties = new Properties();
properties.put(CLEANUP_TAG_NAME_CASE, Integer.toString(HTMLCorePreferenceNames.UPPER)); //HTML config
properties.put(FORMATTER_INSERT_SPACE_BEFORE_SEMICOLON, JavaScriptCore.INSERT); //JS config
properties.put(QUOTE_ATTR_VALUES, "TRUE"); //CSS config
Expand Down Expand Up @@ -89,7 +89,7 @@ void formatCSS() throws Exception {

@Test
void checkCleanupForNonUtf8() throws Exception {
String osEncoding = System.getProperty("file.encoding");
var osEncoding = System.getProperty("file.encoding");
System.setProperty("file.encoding", "ISO-8859-1"); //Simulate a non UTF-8 OS
String[] input = testData.input("utf-8.html");
String output = formatter.format(input[0]);
Expand Down

0 comments on commit 920c320

Please sign in to comment.