1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

Cosmetics.

Change-Id: I32e482e24ed992d8a4939f0447e540e039eb9e04
This commit is contained in:
Jonah Graham 2016-12-12 21:00:02 +00:00 committed by Doug Schaefer
parent da53010a32
commit f0ba639995
2 changed files with 77 additions and 61 deletions

View file

@ -36,7 +36,8 @@ public class BuildConsolePartition extends TypedRegion {
fStream = stream; fStream = stream;
} }
public BuildConsolePartition(BuildConsoleStreamDecorator stream, int offset, int length, String type, ProblemMarkerInfo marker) { public BuildConsolePartition(BuildConsoleStreamDecorator stream, int offset, int length, String type,
ProblemMarkerInfo marker) {
super(offset, length, type); super(offset, length, type);
fStream = stream; fStream = stream;
fMarker = marker; fMarker = marker;
@ -88,8 +89,10 @@ public class BuildConsolePartition extends TypedRegion {
int end = start + getLength(); int end = start + getLength();
int otherStart = partition.getOffset(); int otherStart = partition.getOffset();
int otherEnd = otherStart + partition.getLength(); int otherEnd = otherStart + partition.getLength();
boolean overlap = (otherStart >= start && otherStart <= end) || (start >= otherStart && start <= otherEnd); boolean overlap = (otherStart >= start && otherStart <= end)
return getStream() != null && overlap && type.equals(partition.getType()) && getStream().equals(partition.getStream()); || (start >= otherStart && start <= otherEnd);
return getStream() != null && overlap && type.equals(partition.getType())
&& getStream().equals(partition.getStream());
} }
/** /**
@ -111,6 +114,7 @@ public class BuildConsolePartition extends TypedRegion {
/** /**
* Creates a new partition of this type with the given offset, and length. * Creates a new partition of this type with the given offset, and length.
*
* @param offset * @param offset
* @param length * @param length
* @return a new partition with the given range * @return a new partition with the given range
@ -124,10 +128,9 @@ public class BuildConsolePartition extends TypedRegion {
} }
public static boolean isProblemPartitionType(String type) { public static boolean isProblemPartitionType(String type) {
return type==BuildConsolePartition.ERROR_PARTITION_TYPE return type == BuildConsolePartition.ERROR_PARTITION_TYPE
|| type==BuildConsolePartition.WARNING_PARTITION_TYPE || type == BuildConsolePartition.WARNING_PARTITION_TYPE
|| type==BuildConsolePartition.INFO_PARTITION_TYPE; || type == BuildConsolePartition.INFO_PARTITION_TYPE;
} }
} }

View file

@ -271,8 +271,8 @@ public class BuildConsolePartitioner
* A queue of stream entries written to standard out and standard err. * A queue of stream entries written to standard out and standard err.
* Entries appended to the end of the queue and removed from the front. * Entries appended to the end of the queue and removed from the front.
*/ */
private final Deque<StreamEntry> fQueue = private final Deque<StreamEntry> fQueue = new SynchronizedDeque<StreamEntry>(
new SynchronizedDeque<StreamEntry>(new ArrayDeque<StreamEntry>()); new ArrayDeque<StreamEntry>());
private URI fLogURI; private URI fLogURI;
private OutputStream fLogStream; private OutputStream fLogStream;
@ -300,9 +300,11 @@ public class BuildConsolePartitioner
} }
/** /**
* This constructor is used for special events such as clear console or close log. * This constructor is used for special events such as clear console or
* close log.
* *
* @param event - kind of event. * @param event
* - kind of event.
*/ */
public StreamEntry(int event) { public StreamEntry(int event) {
fText = null; fText = null;
@ -369,8 +371,8 @@ public class BuildConsolePartitioner
} }
/** /**
* Sets the indicator that stream was opened so logging can be started. Should be called * Sets the indicator that stream was opened so logging can be started.
* when opening the output stream. * Should be called when opening the output stream.
*/ */
public void setStreamOpened() { public void setStreamOpened() {
fQueue.add(new StreamEntry(StreamEntry.EVENT_OPEN_LOG)); fQueue.add(new StreamEntry(StreamEntry.EVENT_OPEN_LOG));
@ -378,9 +380,9 @@ public class BuildConsolePartitioner
} }
/** /**
* Open the stream for appending. Must be called after a call to setStreamOpened(). * Open the stream for appending. Must be called after a call to
* Can be used to reopen a stream for writing after it has been closed, without * setStreamOpened(). Can be used to reopen a stream for writing after it
* emptying the log file. * has been closed, without emptying the log file.
*/ */
public void setStreamAppend() { public void setStreamAppend() {
fQueue.add(new StreamEntry(StreamEntry.EVENT_OPEN_APPEND_LOG)); fQueue.add(new StreamEntry(StreamEntry.EVENT_OPEN_APPEND_LOG));
@ -388,9 +390,10 @@ public class BuildConsolePartitioner
} }
/** /**
* Sets the indicator that stream was closed so logging should be stopped. Should be called when * Sets the indicator that stream was closed so logging should be stopped.
* build process has finished. Note that there could still be unprocessed console * Should be called when build process has finished. Note that there could
* stream entries in the queue being worked on in the background. * still be unprocessed console stream entries in the queue being worked on
* in the background.
*/ */
public void setStreamClosed() { public void setStreamClosed() {
fQueue.add(new StreamEntry(StreamEntry.EVENT_CLOSE_LOG)); fQueue.add(new StreamEntry(StreamEntry.EVENT_CLOSE_LOG));
@ -400,20 +403,25 @@ public class BuildConsolePartitioner
/** /**
* Adds the new text to the document. * Adds the new text to the document.
* *
* @param text - the text to append. * @param text
* @param stream - the stream to append to. * - the text to append.
* @param stream
* - the stream to append to.
*/ */
public void appendToDocument(String text, BuildConsoleStreamDecorator stream, ProblemMarkerInfo marker) { public void appendToDocument(String text, BuildConsoleStreamDecorator stream, ProblemMarkerInfo marker) {
boolean addToQueue = true; boolean addToQueue = true;
synchronized (fQueue) { synchronized (fQueue) {
StreamEntry entry = fQueue.peekLast(); StreamEntry entry = fQueue.peekLast();
if (entry != null) { if (entry != null) {
// If last stream is the same and the size of the queued entry has not exceeded // If last stream is the same and the size of the queued entry
// the batch size, avoid creating a new entry and append the new text to the last // has not exceeded
// entry in the queue. The batch size is adaptive and grows with the length of // the batch size, avoid creating a new entry and append the new
// text to the last
// entry in the queue. The batch size is adaptive and grows with
// the length of
// the queue. // the queue.
if (entry.getStream() == stream && entry.getEventType() == StreamEntry.EVENT_APPEND && if (entry.getStream() == stream && entry.getEventType() == StreamEntry.EVENT_APPEND
entry.getMarker() == marker && entry.size() < 2000 * fQueue.size()) { && entry.getMarker() == marker && entry.size() < 2000 * fQueue.size()) {
entry.appendText(text); entry.appendText(text);
addToQueue = false; addToQueue = false;
} }
@ -428,9 +436,9 @@ public class BuildConsolePartitioner
} }
/** /**
* Asynchronous processing of stream entries to append to console. * Asynchronous processing of stream entries to append to console. Note that
* Note that all these are processed by the same thread - the user-interface thread * all these are processed by the same thread - the user-interface thread as
* as of {@link Display#asyncExec(Runnable)}. * of {@link Display#asyncExec(Runnable)}.
*/ */
private void asyncProcessQueue() { private void asyncProcessQueue() {
Runnable r = new Runnable() { Runnable r = new Runnable() {
@ -466,8 +474,10 @@ public class BuildConsolePartitioner
boolean allowSlack = false; boolean allowSlack = false;
entry = fQueue.peekFirst(); entry = fQueue.peekFirst();
if (entry != null && entry.getEventType() == StreamEntry.EVENT_APPEND) { if (entry != null && entry.getEventType() == StreamEntry.EVENT_APPEND) {
// Buffer truncation is an expensive operation. Allow some slack // Buffer truncation is an expensive operation.
// if more data is coming and we will be truncating the buffer // Allow some slack
// if more data is coming and we will be
// truncating the buffer
// again soon. // again soon.
allowSlack = true; allowSlack = true;
} }
@ -488,7 +498,10 @@ public class BuildConsolePartitioner
/** /**
* Open the log * Open the log
* @param append Set to true if the log should be opened for appending, false for overwriting. *
* @param append
* Set to true if the log should be opened for appending,
* false for overwriting.
*/ */
private void logOpen(boolean append) { private void logOpen(boolean append) {
fLogURI = fManager.getLogURI(fProject); fLogURI = fManager.getLogURI(fProject);
@ -548,10 +561,8 @@ public class BuildConsolePartitioner
ProblemMarkerInfo marker = entry.getMarker(); ProblemMarkerInfo marker = entry.getMarker();
if (marker == null) { if (marker == null) {
// It is plain unmarkered console output // It is plain unmarkered console output
addPartition(new BuildConsolePartition(fLastStream, addPartition(new BuildConsolePartition(fLastStream, fDocument.getLength(),
fDocument.getLength(), entry.getText().length(), BuildConsolePartition.CONSOLE_PARTITION_TYPE));
entry.getText().length(),
BuildConsolePartition.CONSOLE_PARTITION_TYPE));
} else { } else {
// this text line in entry is markered with ProblemMarkerInfo, // this text line in entry is markered with ProblemMarkerInfo,
// create special partition for it. // create special partition for it.
@ -563,10 +574,8 @@ public class BuildConsolePartitioner
} else { } else {
errorPartitionType = BuildConsolePartition.ERROR_PARTITION_TYPE; errorPartitionType = BuildConsolePartition.ERROR_PARTITION_TYPE;
} }
addPartition(new BuildConsolePartition(fLastStream, addPartition(new BuildConsolePartition(fLastStream, fDocument.getLength(),
fDocument.getLength(), entry.getText().length(), errorPartitionType, marker));
entry.getText().length(),
errorPartitionType, marker));
} }
fDocument.replace(fDocument.getLength(), 0, entry.getText()); fDocument.replace(fDocument.getLength(), 0, entry.getText());
} }
@ -613,7 +622,7 @@ public class BuildConsolePartitioner
*/ */
@Override @Override
public String[] getLegalContentTypes() { public String[] getLegalContentTypes() {
return new String[]{BuildConsolePartition.CONSOLE_PARTITION_TYPE}; return new String[] { BuildConsolePartition.CONSOLE_PARTITION_TYPE };
} }
/** /**
@ -643,8 +652,8 @@ public class BuildConsolePartitioner
ITypedRegion partition = fPartitions.get(i); ITypedRegion partition = fPartitions.get(i);
int partitionStart = partition.getOffset(); int partitionStart = partition.getOffset();
int partitionEnd = partitionStart + partition.getLength(); int partitionEnd = partitionStart + partition.getLength();
if ((offset >= partitionStart && offset <= partitionEnd) || if ((offset >= partitionStart && offset <= partitionEnd)
(offset < partitionStart && end >= partitionStart)) { || (offset < partitionStart && end >= partitionStart)) {
list.add(partition); list.add(partition);
} }
} }
@ -722,7 +731,8 @@ public class BuildConsolePartitioner
int endOffset = offset + region.getLength(); int endOffset = offset + region.getLength();
if (endOffset < overflow || BuildConsolePartition.isProblemPartitionType(type)) { if (endOffset < overflow || BuildConsolePartition.isProblemPartitionType(type)) {
// Remove partition, // Remove partition,
// partitions with problem markers can't be split - remove them too. // partitions with problem markers can't be split -
// remove them too.
} else { } else {
// Split partition // Split partition
int length = endOffset - overflow; int length = endOffset - overflow;
@ -731,7 +741,8 @@ public class BuildConsolePartitioner
} else { } else {
// Modify partition offset // Modify partition offset
offset = messageConsolePartition.getOffset() - overflow; offset = messageConsolePartition.getOffset() - overflow;
newPartition = messageConsolePartition.createNewPartition(offset, messageConsolePartition.getLength(), type); newPartition = messageConsolePartition.createNewPartition(offset,
messageConsolePartition.getLength(), type);
} }
if (newPartition != null) { if (newPartition != null) {
newParitions.add(newPartition); newParitions.add(newPartition);
@ -793,7 +804,6 @@ public class BuildConsolePartitioner
}); });
} }
if (BuildConsolePreferencePage.isClearBuildConsole()) { if (BuildConsolePreferencePage.isClearBuildConsole()) {
appendToDocument("", null, null); //$NON-NLS-1$ appendToDocument("", null, null); //$NON-NLS-1$
} }
@ -801,17 +811,20 @@ public class BuildConsolePartitioner
@Override @Override
public ConsoleOutputStream getOutputStream() throws CoreException { public ConsoleOutputStream getOutputStream() throws CoreException {
return new BuildOutputStream(this, fManager.getStreamDecorator(BuildConsoleManager.BUILD_STREAM_TYPE_OUTPUT)); return new BuildOutputStream(this,
fManager.getStreamDecorator(BuildConsoleManager.BUILD_STREAM_TYPE_OUTPUT));
} }
@Override @Override
public ConsoleOutputStream getInfoStream() throws CoreException { public ConsoleOutputStream getInfoStream() throws CoreException {
return new BuildOutputStream(this, fManager.getStreamDecorator(BuildConsoleManager.BUILD_STREAM_TYPE_INFO)); return new BuildOutputStream(this,
fManager.getStreamDecorator(BuildConsoleManager.BUILD_STREAM_TYPE_INFO));
} }
@Override @Override
public ConsoleOutputStream getErrorStream() throws CoreException { public ConsoleOutputStream getErrorStream() throws CoreException {
return new BuildOutputStream(this, fManager.getStreamDecorator(BuildConsoleManager.BUILD_STREAM_TYPE_ERROR)); return new BuildOutputStream(this,
fManager.getStreamDecorator(BuildConsoleManager.BUILD_STREAM_TYPE_ERROR));
} }
/** This method is useful for future debugging and bug-fixing */ /** This method is useful for future debugging and bug-fixing */