-
Notifications
You must be signed in to change notification settings - Fork 3
Reverting some message logging changes in JavaToolMonitor #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import consulo.application.util.concurrent.AppExecutorUtil; | ||
| import consulo.compiler.CacheCorruptedException; | ||
| import consulo.compiler.CompileContext; | ||
| import consulo.compiler.CompilerMessageCategory; | ||
| import consulo.compiler.localize.CompilerLocalize; | ||
| import consulo.java.rt.common.compiler.JavaCompilerInterface; | ||
| import consulo.localize.LocalizeValue; | ||
|
|
@@ -114,26 +115,17 @@ public void dispose() { | |
|
|
||
| @Override | ||
| public void logInfo(String message, String fileUri, long lineNumber, long columnNumber) throws TException { | ||
| new MessageBuilderWrapper(myCompileContext.newInfo(LocalizeValue.of(message))) | ||
| .url(fileUri) | ||
| .position((int) lineNumber, (int) columnNumber) | ||
| .add(); | ||
| logMessage(CompilerMessageCategory.INFORMATION, message, fileUri, lineNumber, columnNumber); | ||
| } | ||
|
|
||
| @Override | ||
| public void logError(String message, String fileUri, long lineNumber, long columnNumber) throws TException { | ||
| new MessageBuilderWrapper(myCompileContext.newError(LocalizeValue.of(message))) | ||
| .url(fileUri) | ||
| .position((int) lineNumber, (int) columnNumber) | ||
| .add(); | ||
| logMessage(CompilerMessageCategory.ERROR, message, fileUri, lineNumber, columnNumber); | ||
| } | ||
|
|
||
| @Override | ||
| public void logWarning(String message, String fileUri, long lineNumber, long columnNumber) throws TException { | ||
| new MessageBuilderWrapper(myCompileContext.newWarning(LocalizeValue.of(message))) | ||
| .url(fileUri) | ||
| .position((int) lineNumber, (int) columnNumber) | ||
| .add(); | ||
| logMessage(CompilerMessageCategory.WARNING, message, fileUri, lineNumber, columnNumber); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -176,39 +168,21 @@ public void fileWrote(String filePath) throws TException { | |
| // } | ||
| // } | ||
|
|
||
| private class MessageBuilderWrapper implements CompileContext.MessageBuilder { | ||
| private final CompileContext.MessageBuilder myDelegate; | ||
|
|
||
| private MessageBuilderWrapper(CompileContext.MessageBuilder delegate) { | ||
| myDelegate = delegate; | ||
| } | ||
|
|
||
| @Override | ||
| public CompileContext.MessageBuilder url(String url) { | ||
| try { | ||
| VirtualFile fileByURL = VirtualFileUtil.findFileByURL(new URI(url).toURL()); | ||
| if (fileByURL != null) { | ||
| myDelegate.url(fileByURL.getUrl()); | ||
| } | ||
| } | ||
| catch (Exception ignored) { | ||
| private void logMessage(CompilerMessageCategory category, String message, String fileUri, long lineNumber, long columnNumber) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracting a shared One follow-up: this new method inlines exactly what (Those lines are outside this diff hunk, so a one-click suggestion cannot be attached; please remove the class manually.) |
||
| String fileUrl = null; | ||
| try { | ||
| URI uri = new URI(fileUri); | ||
| VirtualFile fileByURL = VirtualFileUtil.findFileByURL(uri.toURL()); | ||
| if (fileByURL != null) { | ||
| fileUrl = fileByURL.getUrl(); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public CompileContext.MessageBuilder position(int line, int column) { | ||
| return myDelegate.position(line, column); | ||
| catch (Exception ignored) { | ||
| } | ||
|
|
||
| @Override | ||
| public CompileContext.MessageBuilder navigatable(Navigatable navigatable) { | ||
| return myDelegate.navigatable(navigatable); | ||
| } | ||
|
|
||
| @Override | ||
| public void add() { | ||
| myDelegate.add(); | ||
| } | ||
| myCompileContext.newMessage(category, LocalizeValue.of(message)) | ||
| .optionalUrl(fileUrl) | ||
| .position((int) lineNumber, (int) columnNumber) | ||
| .add(); | ||
| } | ||
| } | ||
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.
Nice cleanup — collapsing
logInfo/logError/logWarninginto a singlelogMessage(category, …)and routing throughnewMessage(category, …).optionalUrl(fileUrl)preserves the original URI→VirtualFileresolution while removing the triplicated builder code. TheMessageBuilderWrapperclass is fully removed in this diff, so the dead-code concern is already handled. 👍One small leftover: now that
MessageBuilderWrapper.navigatable(Navigatable)is gone, theimport consulo.navigation.Navigatable;(line 12) is unused and can be removed — it has no other reference in this file. (That line is outside the diff hunks, so a one-clicksuggestionblock cannot be attached here.)