From: Hannu Niemistö Date: Sun, 22 Jan 2017 21:45:57 +0000 (+0200) Subject: Showing compilation warnings in SCL issue view and editors X-Git-Tag: v1.27.0~6 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F88%2F288%2F1;p=simantics%2Fplatform.git Showing compilation warnings in SCL issue view and editors refs #6987 Change-Id: I127a72d134789982cb842ae351df5ef8604bae40 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/DeclarationClassification.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/DeclarationClassification.java index 6c2befb5c..7c6d53ac8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/DeclarationClassification.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/DeclarationClassification.java @@ -34,14 +34,10 @@ import org.simantics.scl.compiler.internal.parsing.translation.ProcessedDInstanc import org.simantics.scl.compiler.internal.parsing.translation.RelationRepository; import org.simantics.scl.compiler.internal.parsing.translation.ValueRepository; import org.simantics.scl.compiler.module.ImportDeclaration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import gnu.trove.map.hash.THashMap; public class DeclarationClassification { - private static final Logger LOGGER = LoggerFactory.getLogger(DeclarationClassification.class); - ArrayList importsAst = new ArrayList(); ArrayList dataTypesAst = new ArrayList(); ArrayList typeAliasesAst = new ArrayList(); @@ -241,7 +237,7 @@ public class DeclarationClassification { currentAnnotations = new ArrayList(2); } if(declaration.name.name.equals("Eq") || declaration.name.name.equals("Hashable")) { - LOGGER.warn("Skipped instance definition for " + declaration.name + " for " + declaration.types[0]); + errorLog.logWarning(declaration.location, "Skipped instance definition for " + declaration.name + " for " + declaration.types[0]); return; } instancesAst.add(new ProcessedDInstanceAst( @@ -255,7 +251,7 @@ public class DeclarationClassification { currentAnnotations = new ArrayList(2); } if(declaration.name.name.equals("Eq") || declaration.name.name.equals("Hashable")) { - LOGGER.warn("Skipped instance definition for " + declaration.name + " for " + declaration.types[0]); + errorLog.logWarning(declaration.location, "Skipped instance definition for " + declaration.name + " for " + declaration.types[0]); return; } derivingInstancesAst.add(declaration); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index f5834aef1..0971641e8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -31,9 +31,11 @@ import org.simantics.scl.compiler.elaboration.expressions.ELiteral; import org.simantics.scl.compiler.elaboration.expressions.EVar; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; +import org.simantics.scl.compiler.elaboration.expressions.annotations.AnnotationUtils; import org.simantics.scl.compiler.elaboration.fundeps.Fundep; import org.simantics.scl.compiler.elaboration.java.JavaMethodDeclaration; import org.simantics.scl.compiler.elaboration.macros.StandardMacroRule; +import org.simantics.scl.compiler.elaboration.modules.DeprecatedProperty; import org.simantics.scl.compiler.elaboration.modules.InlineProperty; import org.simantics.scl.compiler.elaboration.modules.MethodImplementation; import org.simantics.scl.compiler.elaboration.modules.PrivateProperty; @@ -310,7 +312,7 @@ public class Elaboration { } }.findComponents(); - if(errorLog.isEmpty()) { + if(errorLog.hasNoErrors()) { for(DTypeAst typeAlias : orderedTypeAliases) { TypeAlias alias = (TypeAlias)module.getTypeDescriptor(typeAlias.name); TypeTranslationContext context = createTypeTranslationContext(); @@ -1212,7 +1214,19 @@ public class Elaboration { value.addProperty(PrivateProperty.INSTANCE); } else if(annotation.id.text.equals("@deprecated")) { - // TODO + String description = ""; + if(annotation.parameters.length > 0) { + if(annotation.parameters.length > 1) + errorLog.log(annotation.location, "Invalid number of parameters, expected one string."); + else { + String temp = AnnotationUtils.extractString(annotation.parameters[0]); + if(temp == null) + errorLog.log(annotation.location, "Invalid parameter, expected one string."); + else + description = temp; + } + } + value.addProperty(new DeprecatedProperty(description)); } else errorLog.log(annotation.location, "Unknown annotation."); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java index 27583ea53..29136b609 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java @@ -56,7 +56,7 @@ public class SCLCompiler { } private boolean hasErrors() { - return !compilationContext.errorLog.isEmpty(); + return !compilationContext.errorLog.hasNoErrors(); } public void compile( @@ -161,6 +161,8 @@ public class SCLCompiler { module.setClasses(classes); module.setModuleInitializer(moduleInitializer); module.setBranchPoints(elaboration.branchPoints); + if(compilationContext.errorLog.hasErrorsOrWarnings()) + module.setWarnings(compilationContext.errorLog.getErrors()); if(SCLCompilerConfiguration.ENABLE_TIMING) { phaseFinished("Code generation"); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java index 3118142df..b8d959e19 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java @@ -237,7 +237,7 @@ public class TypeChecking { compilationContext.errorLog.log(c.getDemandLocation(), "Constraint <"+c.constraint+"> is not given and cannot be derived."); } - if(compilationContext.errorLog.isEmpty()) { // To prevent exceptions + if(compilationContext.errorLog.hasNoErrors()) { // To prevent exceptions expression = ExpressionAugmentation.augmentSolved( red.solvedConstraints, expression); @@ -247,7 +247,7 @@ public class TypeChecking { } } else { - if(compilationContext.errorLog.isEmpty()) // To prevent exceptions + if(compilationContext.errorLog.hasNoErrors()) // To prevent exceptions expression = expression.decomposeMatching(); } expression = expression.closure(vars.toArray(new TVar[vars.size()])); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java index 41f807592..e5b5720ef 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TranslationContext.java @@ -205,6 +205,9 @@ public class TranslationContext extends TypeTranslationContext implements Enviro } if(value == null) return new EError(location); + String deprecatedDescription = value.isDeprecated(); + if(deprecatedDescription != null) + errorLog.logWarning(location, "Deprecated value " + value.getName().name + "." + (deprecatedDescription.isEmpty() ? "" : " " + deprecatedDescription)); return new EConstant(location, value); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/annotations/AnnotationUtils.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/annotations/AnnotationUtils.java new file mode 100644 index 000000000..fb7334cd2 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/annotations/AnnotationUtils.java @@ -0,0 +1,27 @@ +package org.simantics.scl.compiler.elaboration.expressions.annotations; + +import org.simantics.scl.compiler.constants.StringConstant; +import org.simantics.scl.compiler.elaboration.expressions.ELiteral; +import org.simantics.scl.compiler.elaboration.expressions.EStringLiteral; +import org.simantics.scl.compiler.elaboration.expressions.EVar; +import org.simantics.scl.compiler.elaboration.expressions.Expression; + +public class AnnotationUtils { + public static String extractString(Expression expression) { + if(expression instanceof EVar) + return ((EVar)expression).name; + else if(expression instanceof EStringLiteral) { + EStringLiteral literal = (EStringLiteral)expression; + if(literal.strings.length == 1) + return literal.strings[0]; + } + else if(expression instanceof ELiteral) { + ELiteral literal = (ELiteral)expression; + if(literal.getValue() instanceof StringConstant) { + StringConstant constant = (StringConstant)literal.getValue(); + return constant.getValue(); + } + } + return null; + } +} diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/DeprecatedProperty.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/DeprecatedProperty.java new file mode 100644 index 000000000..8298bfc1b --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/DeprecatedProperty.java @@ -0,0 +1,9 @@ +package org.simantics.scl.compiler.elaboration.modules; + +public class DeprecatedProperty implements SCLValueProperty { + public final String description; + + public DeprecatedProperty(String description) { + this.description = description; + } +} diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/SCLValue.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/SCLValue.java index 2d9ed6fe1..408eb01e5 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/SCLValue.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/modules/SCLValue.java @@ -144,6 +144,13 @@ public final class SCLValue implements Typed { return true; return false; } + + public String isDeprecated() { + for(SCLValueProperty property : properties) + if(property instanceof DeprecatedProperty) + return ((DeprecatedProperty)property).description; + return null; + } public void setDocumentation(String documentation) { this.documentation = documentation; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java index 4328d15e0..df86c1130 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java @@ -186,7 +186,7 @@ public class Environments { TypeAst typeAst = (TypeAst)parser.parseType(); TypeTranslationContext context = new TypeTranslationContext(compilationContext); Type type = context.toType(typeAst); - if(compilationContext.errorLog.isEmpty()) + if(compilationContext.errorLog.hasNoErrors()) return type; } catch(SCLSyntaxErrorException e) { compilationContext.errorLog.log(e.location, e.getMessage()); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/CompilationError.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/CompilationError.java index bf355285c..a26823fe8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/CompilationError.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/CompilationError.java @@ -9,14 +9,20 @@ public class CompilationError implements Comparable { public final long location; public final String description; + public final ErrorSeverity severity; - public CompilationError(long location, String description) { + public CompilationError(long location, String description, ErrorSeverity severity) { if(description == null) throw new NullPointerException(); this.location = location; this.description = description; + this.severity = severity; } + public CompilationError(long location, String description) { + this(location, description, ErrorSeverity.ERROR); + } + public CompilationError(long location, Exception exception) { this(location, exceptionToString(exception)); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java index f2e648b00..62d5d8c3d 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java @@ -6,20 +6,27 @@ import java.util.Collections; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; public class ErrorLog { - ArrayList errors = new ArrayList(); + ArrayList errors = new ArrayList(); + int errorCount; long exceptionPosition = Locations.NO_LOCATION; public void log(String message) { - errors.add(new CompilationError(message)); + log(new CompilationError(message)); } public void log(CompilationError error) { errors.add(error); + if(error.severity == ErrorSeverity.ERROR) + ++errorCount; } public void log(long locatable, String description) { log(new CompilationError(locatable, description)); } + + public void logWarning(long locatable, String description) { + log(new CompilationError(locatable, description, ErrorSeverity.WARNING)); + } public void log(Exception e) { long location = Locations.NO_LOCATION; @@ -34,8 +41,16 @@ public class ErrorLog { log(new CompilationError(location, e)); } - public boolean isEmpty() { - return errors.isEmpty(); + public boolean hasNoErrors() { + return errorCount == 0; + } + + public boolean hasErrors() { + return errorCount > 0; + } + + public boolean hasErrorsOrWarnings() { + return !errors.isEmpty(); } public CompilationError[] getErrors() { @@ -49,6 +64,7 @@ public class ErrorLog { } public String getErrorsAsString() { + Collections.sort(errors); StringBuilder b = new StringBuilder(); for(CompilationError error : errors) b.append(error.description).append('\n'); @@ -61,6 +77,6 @@ public class ErrorLog { } public int getErrorCount() { - return errors.size(); + return errorCount; } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorSeverity.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorSeverity.java new file mode 100644 index 000000000..9f65cb3e8 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorSeverity.java @@ -0,0 +1,6 @@ +package org.simantics.scl.compiler.errors; + +public enum ErrorSeverity { + ERROR, + WARNING +} diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java index 2f6d52bdb..a8b51a8be 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java @@ -19,6 +19,7 @@ import org.simantics.scl.compiler.elaboration.relations.SCLRelation; import org.simantics.scl.compiler.elaboration.rules.MappingRelation; import org.simantics.scl.compiler.elaboration.rules.TransformationRule; import org.simantics.scl.compiler.environment.filter.NamespaceFilter; +import org.simantics.scl.compiler.errors.CompilationError; import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor; import org.simantics.scl.compiler.top.ModuleInitializer; import org.simantics.scl.compiler.types.TCon; @@ -41,7 +42,8 @@ public class ConcreteModule implements Module { THashMap mappingRelations = new THashMap(); ArrayList dependencies = new ArrayList(); THashMap branchPoints; - + CompilationError[] warnings = CompilationError.EMPTY_ARRAY; + Map classes = Collections.emptyMap(); ModuleInitializer moduleInitializer; @@ -267,6 +269,13 @@ public class ConcreteModule implements Module { @Override public void dispose() { - + } + + public void setWarnings(CompilationError[] warnings) { + this.warnings = warnings; + } + + public CompilationError[] getWarnings() { + return warnings; } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java index 00871dcdf..fe57054cc 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java @@ -5,7 +5,6 @@ import java.util.Collections; import org.simantics.scl.compiler.elaboration.modules.Documentation; import org.simantics.scl.compiler.elaboration.modules.SCLValue; -import org.simantics.scl.compiler.elaboration.modules.TypeAlias; import org.simantics.scl.compiler.elaboration.modules.TypeClass; import org.simantics.scl.compiler.elaboration.modules.TypeClassInstance; import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor; @@ -13,6 +12,7 @@ import org.simantics.scl.compiler.elaboration.relations.SCLEntityType; import org.simantics.scl.compiler.elaboration.relations.SCLRelation; import org.simantics.scl.compiler.elaboration.rules.MappingRelation; import org.simantics.scl.compiler.elaboration.rules.TransformationRule; +import org.simantics.scl.compiler.errors.CompilationError; import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor; import org.simantics.scl.compiler.top.ModuleInitializer; import org.simantics.scl.compiler.types.TCon; @@ -134,4 +134,9 @@ public abstract class LazyModule implements Module { public THashMap getBranchPoints() { return null; } + + @Override + public CompilationError[] getWarnings() { + return CompilationError.EMPTY_ARRAY; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java index e8a111336..180509521 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java @@ -14,6 +14,7 @@ import org.simantics.scl.compiler.elaboration.relations.SCLRelation; import org.simantics.scl.compiler.elaboration.rules.MappingRelation; import org.simantics.scl.compiler.elaboration.rules.TransformationRule; import org.simantics.scl.compiler.environment.filter.NamespaceFilter; +import org.simantics.scl.compiler.errors.CompilationError; import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor; import org.simantics.scl.compiler.top.ModuleInitializer; import org.simantics.scl.compiler.types.TCon; @@ -51,5 +52,7 @@ public interface Module { THashMap getBranchPoints(); void dispose(); + + CompilationError[] getWarnings(); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java index f4e9c7de0..4f22022e5 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java @@ -90,7 +90,7 @@ public abstract class TextualModuleSource implements ModuleSource { listener), moduleName, getJavaReferenceValidator()); - if(compiler.getErrorLog().isEmpty()) + if(compiler.getErrorLog().hasNoErrors()) return new Success(compiler.getModule()); else { LOGGER.error("While compiling " + getModuleName() + ":"); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java index d87beec65..c1881fbca 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java @@ -253,7 +253,7 @@ public class ExpressionEvaluator { { TranslationContext context = new TranslationContext(compilationContext, localEnvironment); expression = expression.resolve(context); - if(!errorLog.isEmpty()) + if(!errorLog.hasNoErrors()) throw new SCLExpressionCompilationException(errorLog.getErrors()); } @@ -278,7 +278,7 @@ public class ExpressionEvaluator { expectedType.addPolarity(Polarity.POSITIVE); context.solveSubsumptions(expression.location); - if(!errorLog.isEmpty()) + if(!errorLog.hasNoErrors()) throw new SCLExpressionCompilationException(errorLog.getErrors()); if(decorateExpression && Types.canonical(expectedEffect) != Types.NO_EFFECTS) { ExpressionDecorator decorator = @@ -288,7 +288,7 @@ public class ExpressionEvaluator { expression = context.solveConstraints(environment, expression); expressionType = expression.getType(); - if(!errorLog.isEmpty()) + if(!errorLog.hasNoErrors()) throw new SCLExpressionCompilationException(errorLog.getErrors()); if(localEnvironment != null) @@ -319,7 +319,7 @@ public class ExpressionEvaluator { new SimplificationContext(compilationContext, DummyJavaReferenceValidator.INSTANCE); expression = expression.simplify(context); - if(!errorLog.isEmpty()) + if(!errorLog.hasNoErrors()) throw new SCLExpressionCompilationException(errorLog.getErrors()); if(SCLCompilerConfiguration.SHOW_EXPRESSION_BEFORE_EVALUATION) diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.scl b/bundles/org.simantics.scl.runtime/scl/Prelude.scl index c2307014a..2c5966dc4 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -1396,6 +1396,7 @@ instance Show String where instance Read String where read str = str +@deprecated "`splitString text pattern` splits the string into a list of string where the parts are sepratated in the original list by the given pattern." splitString :: String -> String -> [String] splitString source pattern = arrayToList $ splitString_ source pattern diff --git a/bundles/org.simantics.scl.ui/icons/warning.png b/bundles/org.simantics.scl.ui/icons/warning.png new file mode 100644 index 000000000..628cf2dae Binary files /dev/null and b/bundles/org.simantics.scl.ui/icons/warning.png differ diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/Activator.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/Activator.java index ca35872ec..a408e7f30 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/Activator.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/Activator.java @@ -33,6 +33,7 @@ public class Activator extends AbstractUIPlugin { reg.put("find", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/find.png") ); reg.put("disk", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/disk.png") ); reg.put("error", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/error.png") ); + reg.put("warning", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/warning.png") ); } @Override diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLAnnotationModel.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLAnnotationModel.java index e432a179a..b8010ef82 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLAnnotationModel.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLAnnotationModel.java @@ -9,9 +9,12 @@ import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.AnnotationModel; import org.simantics.scl.compiler.errors.CompilationError; +import org.simantics.scl.compiler.errors.DoesNotExist; +import org.simantics.scl.compiler.errors.ErrorSeverity; import org.simantics.scl.compiler.errors.Failable; import org.simantics.scl.compiler.errors.Failure; import org.simantics.scl.compiler.errors.Locations; +import org.simantics.scl.compiler.errors.Success; import org.simantics.scl.compiler.module.Module; import org.simantics.scl.compiler.module.repository.ModuleRepository; import org.simantics.scl.compiler.module.repository.UpdateListener; @@ -41,17 +44,21 @@ public class SCLAnnotationModel extends AnnotationModel { Failure failure = (Failure)result; setAnnotations(Arrays.asList(failure.errors)); } - else { + else if(result == DoesNotExist.INSTANCE) setAnnotations(Collections.emptyList()); - } + else + setAnnotations(Arrays.asList(result.getResult().getWarnings())); } protected void setAnnotations(List errors) { synchronized(getLockObject()) { removeAllAnnotations(); for(CompilationError error : errors) { - Annotation annotation = new Annotation("org.eclipse.ui.workbench.texteditor.error", true, - error.description); + Annotation annotation = new Annotation( + error.severity == ErrorSeverity.ERROR ? + "org.eclipse.ui.workbench.texteditor.error" : + "org.eclipse.ui.workbench.texteditor.warning", + true, error.description); int begin = Locations.beginOf(error.location); int end = Locations.endOf(error.location); Position position = new Position(begin, end - begin); diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesContentProvider.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesContentProvider.java index 7a5daffdb..4772ad5ba 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesContentProvider.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesContentProvider.java @@ -9,6 +9,7 @@ import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.widgets.Control; import org.simantics.scl.compiler.errors.CompilationError; +import org.simantics.scl.compiler.errors.DoesNotExist; import org.simantics.scl.compiler.errors.Failable; import org.simantics.scl.compiler.errors.Failure; import org.simantics.scl.compiler.module.Module; @@ -28,7 +29,7 @@ public class SCLIssuesContentProvider implements IStructuredContentProvider { boolean disposed = false; AtomicBoolean refreshInProgress = new AtomicBoolean(false); - THashMap currentFailures = new THashMap(); + THashMap currentFailures = new THashMap(); THashMap updateListeners = new THashMap(); @Override @@ -64,11 +65,22 @@ public class SCLIssuesContentProvider implements IStructuredContentProvider { synchronized(currentFailures) { if(result instanceof Failure) { Failure failure = (Failure)result; - currentFailures.put(moduleName, failure); + currentFailures.put(moduleName, failure.errors); } - else + else if(result == DoesNotExist.INSTANCE) { if(currentFailures.remove(moduleName) == null) return; + } + else { + CompilationError[] warnings = result.getResult().getWarnings(); + if(warnings.length == 0) { + if(currentFailures.remove(moduleName) == null) + return; + } + else { + currentFailures.put(moduleName, warnings); + } + } } refresh(); } @@ -133,8 +145,8 @@ public class SCLIssuesContentProvider implements IStructuredContentProvider { String[] moduleNames = currentFailures.keySet().toArray(new String[currentFailures.size()]); Arrays.sort(moduleNames); for(String moduleName : moduleNames) { - Failure failure = currentFailures.get(moduleName); - for(CompilationError error : failure.errors) + CompilationError[] errors = currentFailures.get(moduleName); + for(CompilationError error : errors) result.add(new SCLIssuesTableEntry(moduleName, error)); if(result.size() >= MAX_ISSUE_COUNT) break; diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesTableEntry.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesTableEntry.java index 74e01066b..2b49dd125 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesTableEntry.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesTableEntry.java @@ -16,7 +16,10 @@ public class SCLIssuesTableEntry implements Comparable { public int compareTo(SCLIssuesTableEntry o) { if(this == o) return 0; - int cmp = moduleName.compareTo(o.moduleName); + int cmp = error.severity.compareTo(o.error.severity); + if(cmp != 0) + return cmp; + cmp = moduleName.compareTo(o.moduleName); if(cmp != 0) return cmp; cmp = Locations.compare(error.location, o.error.location); diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java index 112a5f471..b4fd1edd8 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java @@ -24,6 +24,7 @@ import org.eclipse.ui.IMemento; import org.eclipse.ui.IViewSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.ViewPart; +import org.simantics.scl.compiler.errors.ErrorSeverity; import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.ui.Activator; import org.simantics.scl.ui.editor2.OpenSCLDefinition; @@ -86,7 +87,10 @@ public class SCLIssuesView extends ViewPart { } @Override public Image getImage(Object element) { - return imageRegistry.get("error"); + SCLIssuesTableEntry entry = (SCLIssuesTableEntry)element; + return entry.error.severity == ErrorSeverity.ERROR + ? imageRegistry.get("error") + : imageRegistry.get("warning"); } });