Skip to content
Permalink
Browse files
Use for-each. Use final.
  • Loading branch information
garydgregory committed Nov 21, 2020
1 parent b8bb2be commit f7e1ae732f0c3e24ba3f023bba412e39582f1969
Showing 31 changed files with 164 additions and 166 deletions.
@@ -81,7 +81,7 @@ final class CompilationUnit implements ICompilationUnit {
reader = pReader;
clazzName = ConversionUtils.convertResourceToClassName(pSourceFile);
fileName = pSourceFile;
int dot = clazzName.lastIndexOf('.');
final int dot = clazzName.lastIndexOf('.');
if (dot > 0) {
typeName = clazzName.substring(dot + 1).toCharArray();
} else {
@@ -221,8 +221,8 @@ public NameEnvironmentAnswer findType( final char[][] pCompoundTypeName ) {

public NameEnvironmentAnswer findType( final char[] pTypeName, final char[][] pPackageName ) {
final StringBuilder result = new StringBuilder();
for (int i = 0; i < pPackageName.length; i++) {
result.append(pPackageName[i]);
for (final char[] element : pPackageName) {
result.append(element);
result.append('.');
}

@@ -330,7 +330,7 @@ private boolean isPackage( final String pClazzName ) {
return true;
}

public boolean isPackage( char[][] parentPackageName, char[] pPackageName ) {
public boolean isPackage( final char[][] parentPackageName, final char[] pPackageName ) {
final StringBuilder result = new StringBuilder();
if (parentPackageName != null) {
for (int i = 0; i < parentPackageName.length; i++) {
@@ -358,7 +358,7 @@ public void cleanup() {
final ICompilerRequestor compilerRequestor = new ICompilerRequestor() {
public void acceptResult( final CompilationResult pResult ) {
if (pResult.hasProblems()) {
for (IProblem iproblem : pResult.getProblems()) {
for (final IProblem iproblem : pResult.getProblems()) {
final CompilationProblem problem = new EclipseCompilationProblem(iproblem);
if (problemHandler != null) {
problemHandler.handle(problem);
@@ -368,7 +368,7 @@ public void acceptResult( final CompilationResult pResult ) {
}
if (!pResult.hasErrors()) {
final ClassFile[] clazzFiles = pResult.getClassFiles();
for (ClassFile clazzFile : clazzFiles) {
for (final ClassFile clazzFile : clazzFiles) {
final char[][] compoundName = clazzFile.getCompoundName();
final StringBuilder clazzName = new StringBuilder();
for (int j = 0; j < compoundName.length; j++) {
@@ -35,7 +35,7 @@ public JavaCompiler createJavaCompiler() {
public void testAdditionalTopLevelClassCompile() throws Exception {
try {
super.testAdditionalTopLevelClassCompile();
} catch (AssertionFailedError e) {
} catch (final AssertionFailedError e) {
if (e.getMessage().contains("The type AdditionalTopLevel collides")) {
System.err.println("WARNING: See JCI-59 - EclipseJavaCompile#isPackage() is not yet working correctly - ignoring the failure for now");
} else {
@@ -46,8 +46,8 @@ public GroovyCompilationProblem(final Message pMessage) {
error = true;
}
if (pMessage instanceof SyntaxErrorMessage) {
SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage)pMessage;
SyntaxException syntaxException = syntaxErrorMessage.getCause();
final SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage)pMessage;
final SyntaxException syntaxException = syntaxErrorMessage.getCause();
message = syntaxException.getMessage();
fileName = syntaxException.getSourceLocator();
// FIXME: getStartLine() vs. getLine()
@@ -87,7 +87,7 @@ public CompilationResult compile(

@SuppressWarnings("unchecked") // Groovy library is not yet generic
final List<GroovyClass> classes = unit.getClasses();
for (GroovyClass clazz : classes) {
for (final GroovyClass clazz : classes) {
final byte[] bytes = clazz.getBytes();
pStore.write(ConversionUtils.convertClassToResourcePath(clazz.getName()), bytes);
}
@@ -96,7 +96,7 @@ public CompilationResult compile(
@SuppressWarnings("unchecked") // Groovy library is not yet generic
final Collection<WarningMessage> warnings = col.getWarnings();
if (warnings != null) {
for (WarningMessage warning : warnings) {
for (final WarningMessage warning : warnings) {
final CompilationProblem problem = new GroovyCompilationProblem(warning);
if (problemHandler != null) {
problemHandler.handle(problem);
@@ -108,15 +108,15 @@ public CompilationResult compile(
@SuppressWarnings("unchecked") // Groovy library is not yet generic
final Collection<Message> errors = col.getErrors();
if (errors != null) {
for (Message message : errors) {
for (final Message message : errors) {
final CompilationProblem problem = new GroovyCompilationProblem(message);
if (problemHandler != null) {
problemHandler.handle(problem);
}
problems.add(problem);
}
}
} catch (CompilationFailedException e) {
} catch (final CompilationFailedException e) {
throw new RuntimeException("no expected");
}

@@ -190,9 +190,9 @@ public void handleError( final String pMessage, final Location pLocation ) throw

try {
compiler.compile(resources);
} catch ( LocatedException e ) {
} catch ( final LocatedException e ) {
problems.add(new JaninoCompilationProblem(e));
} catch ( IOException e ) {
} catch ( final IOException e ) {
// low level problems reading or writing bytes
log.error("this error should have been cought before", e);
}
@@ -66,9 +66,9 @@ public boolean delete() {
}

@Override
public CharSequence getCharContent(boolean encodingErrors) throws IOException {
public CharSequence getCharContent(final boolean encodingErrors) throws IOException {
log.debug("getCharContent of " + name);
byte[] content = reader.getBytes(name);
final byte[] content = reader.getBytes(name);
return new String(content);
}

@@ -85,7 +85,7 @@ public String getName() {
}

@Override
public boolean isNameCompatible(String simpleName, Kind kind) {
public boolean isNameCompatible(final String simpleName, final Kind kind) {
log.debug("isNameCompatible " + simpleName + " " + kind);
// return super.isNameCompatible(simpleName, kind);
return true;
@@ -104,7 +104,7 @@ public OutputStream openOutputStream() throws IOException {
}

@Override
public Reader openReader(boolean arg0) throws IOException {
public Reader openReader(final boolean arg0) throws IOException {
log.debug("openReader");
return super.openReader(arg0);
}
@@ -137,51 +137,51 @@ public void close() {
public void flush() {
log.debug("flush");
}
public ClassLoader getClassLoader(JavaFileManager.Location location) {
public ClassLoader getClassLoader(final JavaFileManager.Location location) {
log.debug("getClassLoader");
return null;
}
public FileObject getFileForInput(JavaFileManager.Location location, String packageName, String relativeName) {
public FileObject getFileForInput(final JavaFileManager.Location location, final String packageName, final String relativeName) {
log.debug("getFileForInput");
return null;
}
public FileObject getFileForOutput(JavaFileManager.Location location, String packageName, String relativeName, FileObject sibling) {
public FileObject getFileForOutput(final JavaFileManager.Location location, final String packageName, final String relativeName, final FileObject sibling) {
log.debug("getFileForOutput");
return null;
}
public JavaFileObject getJavaFileForInput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind) {
public JavaFileObject getJavaFileForInput(final JavaFileManager.Location location, final String className, final JavaFileObject.Kind kind) {
log.debug("getJavaFileForInput");
return null;
}
public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) {
public JavaFileObject getJavaFileForOutput(final JavaFileManager.Location location, final String className, final JavaFileObject.Kind kind, final FileObject sibling) {
log.debug("getJavaFileForOutput");
return null;
}
public int isSupportedOption(String option) {
public int isSupportedOption(final String option) {
log.debug("isSupportedOption " + option);
return 0;
}
public boolean handleOption(String current, Iterator<String> remaining) {
public boolean handleOption(final String current, final Iterator<String> remaining) {
log.debug("handleOption " + current);
return false;
}
public boolean hasLocation(JavaFileManager.Location location) {
public boolean hasLocation(final JavaFileManager.Location location) {
log.debug("hasLocation " + location);
return false;
}
public String inferBinaryName(JavaFileManager.Location location, JavaFileObject file) {
String s = file.getName().replaceFirst(".java", ".class");
public String inferBinaryName(final JavaFileManager.Location location, final JavaFileObject file) {
final String s = file.getName().replaceFirst(".java", ".class");
log.debug("inferBinaryName " + file.getName() + " -> " + s);
return s;
}
public Iterable<JavaFileObject> list(JavaFileManager.Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) {
public Iterable<JavaFileObject> list(final JavaFileManager.Location location, final String packageName, final Set<JavaFileObject.Kind> kinds, final boolean recurse) {
if (packageName.startsWith("java.")) {
return new ArrayList<JavaFileObject>();
}
log.debug("list " + location + packageName + kinds + recurse);
return units;
}
public boolean isSameFile(FileObject fileobject, FileObject fileobject1) {
public boolean isSameFile(final FileObject fileobject, final FileObject fileobject1) {
return false;
}
}
@@ -196,19 +196,18 @@ public Jsr199JavaCompiler( final Jsr199JavaCompilerSettings pSettings ) {
settings = pSettings;
}

public CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader classLoader, JavaCompilerSettings settings) {
public CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader classLoader, final JavaCompilerSettings settings) {

final Collection<JavaFileObject> units = new ArrayList<JavaFileObject>();
for (int i = 0; i < pResourcePaths.length; i++) {
final String sourcePath = pResourcePaths[i];
for (final String sourcePath : pResourcePaths) {
log.debug("compiling " + sourcePath);
units.add(new CompilationUnit(sourcePath, pReader));
}

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

if (compiler == null) {
ServiceLoader<javax.tools.JavaCompiler> loader = ServiceLoader.load(javax.tools.JavaCompiler.class);
final ServiceLoader<javax.tools.JavaCompiler> loader = ServiceLoader.load(javax.tools.JavaCompiler.class);
compiler = loader.iterator().next();
}

@@ -219,7 +218,7 @@ public CompilationResult compile( final String[] pResourcePaths, final ResourceR
final JavaFileManager fileManager = new JciJavaFileManager(units, pStore);
final DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();

CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null, null, units);
final CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null, null, units);

if (task.call().booleanValue()) {
log.debug("compiled");
@@ -72,7 +72,7 @@ private final class RhinoCompilingClassLoader extends ClassLoader {

private final class ProblemCollector implements ErrorReporter {

public void error(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {
public void error(final String pMessage, final String pFileName, final int pLine, final String pScript, final int pColumn) {

final CompilationProblem problem = new RhinoCompilationProblem(pMessage, pFileName, pLine, pScript, pColumn, true);

@@ -83,7 +83,7 @@ public void error(String pMessage, String pFileName, int pLine, String pScript,
problems.add(problem);
}

public void warning(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {
public void warning(final String pMessage, final String pFileName, final int pLine, final String pScript, final int pColumn) {

final CompilationProblem problem = new RhinoCompilationProblem(pMessage, pFileName, pLine, pScript, pColumn, false);

@@ -94,7 +94,7 @@ public void warning(String pMessage, String pFileName, int pLine, String pScript
problems.add(problem);
}

public EvaluatorException runtimeError(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {
public EvaluatorException runtimeError(final String pMessage, final String pFileName, final int pLine, final String pScript, final int pColumn) {
return new EvaluatorException(pMessage, pFileName, pLine, pScript, pColumn);
}
}
@@ -121,9 +121,9 @@ protected Class<?> findClass( final String pName ) throws ClassNotFoundException

try {
return compileClass(context, pName);
} catch( EvaluatorException e ) {
} catch( final EvaluatorException e ) {
throw new ClassNotFoundException(e.getMessage(), e);
} catch (IOException e) {
} catch (final IOException e) {
throw new ClassNotFoundException(e.getMessage(), e);
} finally {
Context.exit();
@@ -212,7 +212,7 @@ private Class<?> compileClass( final Context pContext, final String pSourceName,

store.write(clazzName.replace('.', '/') + ".class", clazzBytes);

Class<?> c = loader.defineClass(clazzName, clazzBytes);
final Class<?> c = loader.defineClass(clazzName, clazzBytes);
loader.linkClass(c);

if (i == 0) {
@@ -224,7 +224,7 @@ private Class<?> compileClass( final Context pContext, final String pSourceName,
return clazz;
}

private String getName(String s) {
private String getName(final String s) {
final int i = s.lastIndexOf('/');
if (i < 0) {
return s;
@@ -257,13 +257,13 @@ public CompilationResult compile( final String[] pResourcePaths, final ResourceR

final RhinoCompilingClassLoader cl = new RhinoCompilingClassLoader(pReader, pStore, pClassLoader);

for (int i = 0; i < pResourcePaths.length; i++) {
log.debug("compiling " + pResourcePaths[i]);
for (final String pResourcePath : pResourcePaths) {
log.debug("compiling " + pResourcePath);

final String clazzName = ConversionUtils.convertResourceToClassName(pResourcePaths[i]);
final String clazzName = ConversionUtils.convertResourceToClassName(pResourcePath);
try {
cl.loadClass(clazzName);
} catch (ClassNotFoundException e) {
} catch (final ClassNotFoundException e) {
}
}

@@ -104,27 +104,27 @@ public void clearAssertionStatus() {
delegate.clearAssertionStatus();
}
@Override
public URL getResource(String name) {
public URL getResource(final String name) {
return delegate.getResource(name);
}
@Override
public InputStream getResourceAsStream(String name) {
public InputStream getResourceAsStream(final String name) {
return delegate.getResourceAsStream(name);
}
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
public Class<?> loadClass(final String name) throws ClassNotFoundException {
return delegate.loadClass(name);
}
@Override
public void setClassAssertionStatus(String className, boolean enabled) {
public void setClassAssertionStatus(final String className, final boolean enabled) {
delegate.setClassAssertionStatus(className, enabled);
}
@Override
public void setDefaultAssertionStatus(boolean enabled) {
public void setDefaultAssertionStatus(final boolean enabled) {
delegate.setDefaultAssertionStatus(enabled);
}
@Override
public void setPackageAssertionStatus(String packageName, boolean enabled) {
public void setPackageAssertionStatus(final String packageName, final boolean enabled) {
delegate.setPackageAssertionStatus(packageName, enabled);
}
}
@@ -38,7 +38,7 @@ public CompilationResult( final CompilationProblem[] pProblems ) {
final Collection<CompilationProblem> errorsColl = new ArrayList<CompilationProblem>();
final Collection<CompilationProblem> warningsColl = new ArrayList<CompilationProblem>();

for (CompilationProblem problem : pProblems) {
for (final CompilationProblem problem : pProblems) {
if (problem.isError()) {
errorsColl.add(problem);
} else {
@@ -76,7 +76,7 @@ public JavaCompiler createCompiler(final String pHint) {
try {
clazz = Class.forName(className);
classCache.put(className, clazz);
} catch (ClassNotFoundException e) {
} catch (final ClassNotFoundException e) {
clazz = null;
}
}
@@ -87,7 +87,7 @@ public JavaCompiler createCompiler(final String pHint) {

try {
return (JavaCompiler) clazz.newInstance();
} catch (Throwable t) {
} catch (final Throwable t) {
return null;
}
}

0 comments on commit f7e1ae7

Please sign in to comment.