Add MessageCollector#hasErrors, get rid of MessageSeverityCollector

Also fix duplicated wrapping of a message collector into a message severity
collector (in CLICompiler and in the beginning of doExecute in
K2JVMCompiler/K2JSCompiler)
This commit is contained in:
Alexander Udalov
2016-02-14 18:01:39 +03:00
parent c5e2f55ea7
commit 3c81bb4bfc
15 changed files with 107 additions and 111 deletions
@@ -28,4 +28,8 @@ public enum CompilerMessageSeverity {
public static final EnumSet<CompilerMessageSeverity> ERRORS = EnumSet.of(ERROR, EXCEPTION);
public static final EnumSet<CompilerMessageSeverity> VERBOSE = EnumSet.of(OUTPUT, LOGGING);
public boolean isError() {
return ERRORS.contains(this);
}
}
@@ -36,4 +36,9 @@ public class FilteringMessageCollector implements MessageCollector {
messageCollector.report(severity, message, location);
}
}
@Override
public boolean hasErrors() {
return messageCollector.hasErrors();
}
}
@@ -47,19 +47,23 @@ public class GroupingMessageCollector implements MessageCollector {
}
}
public void flush() {
boolean hasError = false;
Collection<String> keys = sortedKeys();
for (String path : keys) {
for (Message message : groupedMessages.get(path)) {
hasError |= CompilerMessageSeverity.ERRORS.contains(message.severity);
@Override
public boolean hasErrors() {
for (Map.Entry<String, Message> entry : groupedMessages.entries()) {
if (entry.getValue().severity.isError()) {
return true;
}
}
for (String path : keys) {
return false;
}
public void flush() {
boolean hasErrors = hasErrors();
for (String path : sortedKeys()) {
for (Message message : groupedMessages.get(path)) {
if (!hasError || CompilerMessageSeverity.ERRORS.contains(message.severity)) {
if (!hasErrors || message.severity.isError()) {
delegate.report(message.severity, message.message, message.location);
}
}
@@ -19,17 +19,19 @@ package org.jetbrains.kotlin.cli.common.messages;
import org.jetbrains.annotations.NotNull;
public interface MessageCollector {
MessageCollector NONE = new MessageCollector() {
@Override
public void report(
@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location
) {
public void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
// Do nothing
}
@Override
public boolean hasErrors() {
return false;
}
};
void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
boolean hasErrors();
}
@@ -1,49 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.cli.common.messages;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Set;
public class MessageSeverityCollector implements MessageCollector {
private final MessageCollector delegate;
private final Set<CompilerMessageSeverity> reportedSeverities = Sets.newHashSet();
public MessageSeverityCollector(@NotNull MessageCollector delegate) {
this.delegate = delegate;
}
@Override
public void report(
@NotNull CompilerMessageSeverity severity,
@NotNull String message,
@NotNull CompilerMessageLocation location
) {
delegate.report(severity, message, location);
reportedSeverities.add(severity);
}
public boolean anyReported(@NotNull CompilerMessageSeverity... severities) {
return reportedSeverities.containsAll(Arrays.asList(severities));
}
}