Author: sco...@google.com Date: Fri Feb 13 15:24:42 2009 New Revision: 4722
Modified: releases/1.6/dev/core/src/com/google/gwt/dev/javac/CompilationUnitInvalidator.java releases/1.6/dev/core/src/com/google/gwt/dev/javac/GWTProblem.java Log: Allow GWTProblems to generate warning log messages. Review by: jat (TBR) Modified: releases/1.6/dev/core/src/com/google/gwt/dev/javac/CompilationUnitInvalidator.java ============================================================================== --- releases/1.6/dev/core/src/com/google/gwt/dev/javac/CompilationUnitInvalidator.java (original) +++ releases/1.6/dev/core/src/com/google/gwt/dev/javac/CompilationUnitInvalidator.java Fri Feb 13 15:24:42 2009 @@ -17,6 +17,7 @@ import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.TreeLogger.HelpInfo; +import com.google.gwt.core.ext.TreeLogger.Type; import com.google.gwt.dev.javac.CompilationUnit.State; import com.google.gwt.dev.util.Util; @@ -55,37 +56,57 @@ continue; } CompilationResult result = unit.getJdtCud().compilationResult(); - if (result.hasErrors()) { - anyRemoved = true; + if (result.hasProblems()) { - // TODO: defer this until later? - TreeLogger branch = logger.branch(TreeLogger.ERROR, "Errors in '" - + unit.getDisplayLocation() + "'", null); - - for (CategorizedProblem error : result.getErrors()) { + // Log the errors and GWT warnings. + TreeLogger branch = null; + for (CategorizedProblem problem : result.getProblems()) { + TreeLogger.Type logLevel; + if (problem.isError()) { + // Log errors. + logLevel = TreeLogger.ERROR; + // Only log GWT-specific warnings. + } else if (problem.isWarning() && problem instanceof GWTProblem) { + logLevel = TreeLogger.WARN; + } else { + // Ignore all other problems. + continue; + } // Append 'Line #: msg' to the error message. StringBuffer msgBuf = new StringBuffer(); - int line = error.getSourceLineNumber(); + int line = problem.getSourceLineNumber(); if (line > 0) { msgBuf.append("Line "); msgBuf.append(line); msgBuf.append(": "); } - msgBuf.append(error.getMessage()); + msgBuf.append(problem.getMessage()); HelpInfo helpInfo = null; - if (error instanceof GWTProblem) { - GWTProblem gwtProblem = (GWTProblem) error; + if (problem instanceof GWTProblem) { + GWTProblem gwtProblem = (GWTProblem) problem; helpInfo = gwtProblem.getHelpInfo(); } - branch.log(TreeLogger.ERROR, msgBuf.toString(), null, helpInfo); + if (branch == null) { + Type branchType = result.hasErrors() ? TreeLogger.ERROR + : TreeLogger.WARN; + String branchString = result.hasErrors() ? "Errors" : "Warnings"; + branch = logger.branch(branchType, branchString + " in '" + + unit.getDisplayLocation() + "'", null); + } + branch.log(logLevel, msgBuf.toString(), null, helpInfo); } - Util.maybeDumpSource(branch, unit.getDisplayLocation(), - unit.getSource(), unit.getTypeName()); + if (branch != null) { + Util.maybeDumpSource(branch, unit.getDisplayLocation(), + unit.getSource(), unit.getTypeName()); + } - // TODO: hold onto errors? - unit.setState(State.ERROR); + // Invalidate the unit if there are errors. + if (result.hasErrors()) { + unit.setState(State.ERROR); + anyRemoved = true; + } } } Modified: releases/1.6/dev/core/src/com/google/gwt/dev/javac/GWTProblem.java ============================================================================== --- releases/1.6/dev/core/src/com/google/gwt/dev/javac/GWTProblem.java (original) +++ releases/1.6/dev/core/src/com/google/gwt/dev/javac/GWTProblem.java Fri Feb 13 15:24:42 2009 @@ -32,24 +32,30 @@ public static void recordInCud(ASTNode node, CompilationUnitDeclaration cud, String message, HelpInfo helpInfo) { + recordInCud(ProblemSeverities.Error, node, cud, message, helpInfo); + } + + public static void recordInCud(int problemSeverity, ASTNode node, + CompilationUnitDeclaration cud, String message, HelpInfo helpInfo) { CompilationResult compResult = cud.compilationResult(); int[] lineEnds = compResult.getLineSeparatorPositions(); int startLine = Util.getLineNumber(node.sourceStart(), lineEnds, 0, lineEnds.length - 1); int startColumn = Util.searchColumnNumber(lineEnds, startLine, node.sourceStart()); - DefaultProblem problem = new GWTProblem(compResult.fileName, message, - node.sourceStart(), node.sourceEnd(), startLine, startColumn, helpInfo); + DefaultProblem problem = new GWTProblem(problemSeverity, + compResult.fileName, message, node.sourceStart(), node.sourceEnd(), + startLine, startColumn, helpInfo); compResult.record(problem, cud); } private HelpInfo helpInfo; - public GWTProblem(char[] originatingFileName, String message, + GWTProblem(int problemSeverity, char[] originatingFileName, String message, int startPosition, int endPosition, int line, int column, HelpInfo helpInfo) { super(originatingFileName, message, IProblem.ExternalProblemNotFixable, - null, ProblemSeverities.Error, startPosition, endPosition, line, column); + null, problemSeverity, startPosition, endPosition, line, column); this.helpInfo = helpInfo; } --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---