-
Notifications
You must be signed in to change notification settings - Fork 38
[eclipse/xtext#1777] ported xtend code 2 java #629
Conversation
org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java
Outdated
Show resolved
Hide resolved
cache.put(fileName, null); | ||
return null; | ||
} | ||
ClassFileReader reader = ClassFileReader.read(url.openStream(), fileName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use try-with-resources for url.openStream()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try (InputStream is = url.openStream()) {
ClassFileReader reader = ClassFileReader.read(is, fileName);
NameEnvironmentAnswer result = new NameEnvironmentAnswer(reader, null);
cache.put(fileName, result);
return result;
}
org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java
Outdated
Show resolved
Hide resolved
org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java
Show resolved
Hide resolved
org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java
Outdated
Show resolved
Hide resolved
org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java
Outdated
Show resolved
Hide resolved
org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java
Outdated
Show resolved
Hide resolved
8b10fd1
to
e8f0a42
Compare
ListExtensions.map(Arrays.asList(sources), | ||
(JavaSource it) -> new CompilationUnit(it.getCode().toCharArray(), it.getFileName(), null)), | ||
ICompilationUnit.class)); | ||
compiler.compile(units); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor to:
ICompilationUnit[] units = Stream.of(sources).map(it -> new CompilationUnit(it.getCode().toCharArray(), it.getFileName(), null)).toArray(ICompilationUnit[]::new);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not about refactoring everything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current code is way more hard to read. Above statement does the same.
message.append("PROBLEMS : "); | ||
message.newLine(); | ||
message.append("\t"); | ||
message.append(Joiner.on("\n").join(result.getCompilationProblems()), "\t"); | ||
message.newLineIfNotEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract to method, sequence is used twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:(
message.append("Java code compiled with errors:"); | ||
message.newLine(); | ||
message.append(Joiner.on("\n").join( | ||
Iterables.filter(result.getCompilationProblems(), CategorizedProblem::isError))); | ||
message.newLineIfNotEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract to method, sequence is used twice
sourceCode.append("public class __Generated implements org.eclipse.xtext.xbase.lib.Functions.Function0<"); | ||
sourceCode.append(returnType.getName()); | ||
sourceCode.append("> {"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may read better with
sourceCode.append(String.format("public class __Generated implements org.eclipse.xtext.xbase.lib.Functions.Function0<%s> {", returnType.getName())
If you agree there are other line candidates.
8b15a76
to
a515e57
Compare
ping @kthoms @szarnekow |
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
[eclipse/xtext#1777] ported xtend code 2 java
Signed-off-by: Christian Dietrich christian.dietrich@itemis.de