From 4d93d6c4dfbf4ed6d2df5a861214da56db3b7684 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Sun, 27 Apr 2003 20:56:07 +0000 Subject: [PATCH] Patch for Hoda Amer. Logging debug messages of the parser and the C model builder only if CCorePlugin.debug is set to true. --- .../eclipse/cdt/internal/core/model/Util.java | 38 ++++++++++++++++++- .../internal/core/model/CModelBuilder.java | 6 ++- .../cdt/internal/core/parser/Parser.java | 7 +++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java index ca546c3f547..5ba15056ebb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java @@ -10,6 +10,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.text.MessageFormat; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.CModelException; @@ -156,10 +157,43 @@ public class Util { IStatus.ERROR, message, e); - - CCorePlugin.getDefault().getLog().log(status); + Util.log(status); } + public static void log(IStatus status){ + CCorePlugin.getDefault().getLog().log(status); + } + + public static void log(String message){ + IStatus status = new Status(IStatus.INFO, + CCorePlugin.getDefault().getDescriptor().getUniqueIdentifier(), + IStatus.INFO, + message, + null); + Util.log(status); + } + + public static void debugLog(String message) { + if (CCorePlugin.getDefault() != null && CCorePlugin.getDefault().isDebugging()) { + // Time stamp + message = MessageFormat.format( "[{0}] {1}", new Object[] { new Long( System.currentTimeMillis() ), message } ); + while (message.length() > 100) { + String partial = message.substring(0, 100); + message = message.substring(100); + System.out.println(partial + "\\"); + } + if (message.endsWith("\n")) { + System.err.print(message); + } else { + System.out.println(message); + } + } + } + + public static void setDebugging(boolean value){ + CCorePlugin.getDefault().setDebugging(value); + } + /** * Combines two hash codes to make a new one. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java index 7765353beb1..212b5b68bf8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java @@ -95,7 +95,11 @@ public class CModelBuilder { System.out.println( "NullPointer exception generating CModel"); npe.printStackTrace(); } - System.out.println("CModel build: "+ ( System.currentTimeMillis() - startTime ) + "ms" ); + + // For the debuglog to take place, you have to call + // Util.setDebugging(true); + // Or set debug to true in the core plugin preference + Util.debugLog("CModel build: "+ ( System.currentTimeMillis() - startTime ) + "ms"); return this.newElements; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index e2aec3b4d5d..92907315b2f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -17,6 +17,8 @@ import java.io.StringReader; import java.util.HashMap; import java.util.Map; +import org.eclipse.cdt.internal.core.model.Util; + public class Parser implements IParser { private static int DEFAULT_OFFSET = -1; @@ -79,7 +81,10 @@ c, quick); public boolean parse() throws Backtrack { long startTime = System.currentTimeMillis(); translationUnit(); - System.out.println("Parse " + (++parseCount) + ": " + // For the debuglog to take place, you have to call + // Util.setDebugging(true); + // Or set debug to true in the core plugin preference + Util.debugLog( "Parse " + (++parseCount) + ": " + ( System.currentTimeMillis() - startTime ) + "ms" + ( parsePassed ? "" : " - parse failure" ));