diff --git a/java/execution/impl/src/com/intellij/execution/junit2/SegmentedInputStream.java b/java/execution/impl/src/com/intellij/execution/junit2/SegmentedInputStream.java index 3fc4d64b968c..7ebb739a0366 100644 --- a/java/execution/impl/src/com/intellij/execution/junit2/SegmentedInputStream.java +++ b/java/execution/impl/src/com/intellij/execution/junit2/SegmentedInputStream.java @@ -19,6 +19,7 @@ import com.intellij.rt.execution.junit.segments.Packet; import com.intellij.rt.execution.junit.segments.PacketProcessor; import com.intellij.rt.execution.junit.segments.SegmentedStream; import com.intellij.util.StringBuilderSpinAllocator; +import org.jetbrains.annotations.NotNull; import java.io.BufferedReader; import java.io.IOException; @@ -31,10 +32,11 @@ public class SegmentedInputStream extends InputStream { private PacketProcessor myEventsDispatcher; private int myStartupPassed = 0; - public SegmentedInputStream(final InputStream sourceStream, final Charset charset) { + public SegmentedInputStream(@NotNull InputStream sourceStream, @NotNull Charset charset) { mySourceStream = new PushReader(new BufferedReader(new InputStreamReader(sourceStream, charset))); } + @Override public int read() throws IOException { if (myStartupPassed < SegmentedStream.STARTUP_MESSAGE.length()) { return rawRead(); @@ -86,9 +88,9 @@ public class SegmentedInputStream extends InputStream { } private char[] readMarker() throws IOException { - int nextRead = '0'; final StringBuilder buffer = StringBuilderSpinAllocator.alloc(); try { + int nextRead = '0'; while (nextRead != ' ' && nextRead != SegmentedStream.SPECIAL_SYMBOL) { buffer.append((char)nextRead); nextRead = readNext(); @@ -108,10 +110,12 @@ public class SegmentedInputStream extends InputStream { return mySourceStream.next(); } + @Override public int available() throws IOException { return mySourceStream.ready() ? 1 : 0; } + @Override public void close() throws IOException { mySourceStream.close(); } @@ -126,10 +130,11 @@ public class SegmentedInputStream extends InputStream { i++; chr = chars[i]; if (chr != Packet.ourSpecialSymbol) { - final StringBuffer codeBuffer = new StringBuffer(Packet.CODE_LENGTH); + final StringBuilder codeBuffer = new StringBuilder(Packet.CODE_LENGTH); codeBuffer.append(chr); - for (int j = 1; j < Packet.CODE_LENGTH; j++) - codeBuffer.append(chars[i+j]); + for (int j = 1; j < Packet.CODE_LENGTH; j++) { + codeBuffer.append(chars[i + j]); + } i += Packet.CODE_LENGTH - 1; decodedChar = (char)Integer.parseInt(codeBuffer.toString()); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/make/Form2ByteCodeCompiler.java b/plugins/ui-designer/src/com/intellij/uiDesigner/make/Form2ByteCodeCompiler.java index 8aedf47d3258..b42fd6bf0520 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/make/Form2ByteCodeCompiler.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/make/Form2ByteCodeCompiler.java @@ -59,11 +59,13 @@ import java.util.StringTokenizer; public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.make.Form2ByteCodeCompiler"); + @Override @NotNull public String getDescription() { return UIDesignerBundle.message("component.gui.designer.form.to.bytecode.compiler"); } + @Override public boolean validateConfiguration(CompileScope scope) { return true; } @@ -83,6 +85,7 @@ public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { return new URLClassLoader(urls.toArray(new URL[urls.size()]), null); } + @Override @NotNull public ProcessingItem[] getProcessingItems(final CompileContext context) { final Project project = context.getProject(); @@ -93,6 +96,7 @@ public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { final ArrayList items = new ArrayList(); ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override public void run() { final CompileScope scope = context.getCompileScope(); final CompileScope projectScope = context.getProjectCompileScope(); @@ -257,6 +261,7 @@ public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { return outerQualifiedName.replace('.','/') + _className.substring(outerQualifiedName.length()).replace('.','$'); } + @Override public ProcessingItem[] process(final CompileContext context, final ProcessingItem[] items) { final ArrayList compiledItems = new ArrayList(); @@ -298,21 +303,23 @@ public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { final VirtualFile formFile = item.getFormFile(); context.getProgressIndicator().setText2(formFile.getPresentableUrl()); - final Document doc = ApplicationManager.getApplication().runReadAction(new Computable() { - public Document compute() { + final String text = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public String compute() { if (!belongsToCompileScope(context, formFile, item.getClassToBindFQname())) { return null; } - return FileDocumentManager.getInstance().getDocument(formFile); + Document document = FileDocumentManager.getInstance().getDocument(formFile); + return document == null ? null : document.getText(); } }); - if (doc == null) { + if (text == null) { continue; // does not belong to current scope } final LwRootContainer rootContainer; try { - rootContainer = Utils.getRootContainer(doc.getText(), new CompiledClassPropertiesProvider(loader)); + rootContainer = Utils.getRootContainer(text, new CompiledClassPropertiesProvider(loader)); } catch (Exception e) { addMessage(context, UIDesignerBundle.message("error.cannot.process.form.file", e), formFile, CompilerMessageCategory.ERROR); @@ -326,6 +333,7 @@ public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { new PsiNestedFormLoader(module), false, new PsiClassWriter(module)); ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override public void run() { codeGenerator.patchFile(classFile); } @@ -371,6 +379,7 @@ public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { } } + @Override public ValidityState createValidityState(final DataInput in) throws IOException { return TimestampValidityState.load(in); } @@ -406,6 +415,7 @@ public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { myState = new TimestampValidityState(formFile.getTimeStamp()); } + @Override @NotNull public VirtualFile getFile() { return myClassFile; @@ -419,6 +429,7 @@ public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { return myClassToBindFQname; } + @Override public ValidityState getValidityState() { return myState; }