Author: lektran
Date: Sat May 3 22:38:38 2008 New Revision: 653181 URL: http://svn.apache.org/viewvc?rev=653181&view=rev Log: Added a method to strip comments when parsing java files, the artifact info stuff was getting a bit confused by them Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java?rev=653181&r1=653180&r2=653181&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java Sat May 3 22:38:38 2008 @@ -99,7 +99,9 @@ int nextOpen = javaFile.indexOf("{", blockStart+1); int nextClose = javaFile.indexOf("}", blockStart+1); - + if (nextOpen > 0 && nextClose > 0 && nextClose > nextOpen) { + String javaFragment = javaFile.substring(nextOpen, nextClose); + } // if no close, end with couldn't find if (nextClose < 0) return -1; // while nextOpen is found and is before the next close, then recurse (list @@ -223,4 +225,33 @@ return entityNameSet; } + + public static String stripComments(String javaFile) { + StringBuilder strippedFile = new StringBuilder(); + int commentOpen = javaFile.indexOf("/*"); + int commentClose = javaFile.indexOf("*/"); + if (commentOpen > -1) { + if (commentOpen > 0) { + strippedFile.append(javaFile.substring(0, commentOpen)); + } + commentOpen = javaFile.indexOf("/*", commentClose); + while (commentOpen > -1) { + strippedFile.append(javaFile.substring(commentClose + 2, commentOpen)); + commentClose = javaFile.indexOf("*/", commentOpen); + commentOpen = javaFile.indexOf("/*", commentClose); + } + strippedFile.append(javaFile.substring(commentClose + 2)); + } else { + strippedFile.append(javaFile); + } + + String lineSeparator = System.getProperty("line.separator"); + int lineComment = strippedFile.indexOf("//"); + while (lineComment > -1) { + int endOfLine = strippedFile.indexOf(lineSeparator, lineComment); + strippedFile.delete(lineComment, endOfLine); + lineComment = strippedFile.indexOf("//", lineComment); + } + return strippedFile.toString(); + } } Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java?rev=653181&r1=653180&r2=653181&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java (original) +++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java Sat May 3 22:38:38 2008 @@ -109,7 +109,7 @@ Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module); return; } - + javaFile = UtilJavaParse.stripComments(javaFile); int methodBlockStart = UtilJavaParse.findServiceMethodBlockStart(this.modelService.invoke, javaFile); int methodBlockEnd = UtilJavaParse.findEndOfBlock(methodBlockStart, javaFile); Set<String> allEntityNameSet = UtilJavaParse.findEntityUseInBlock(methodBlockStart, methodBlockEnd, javaFile); |
Free forum by Nabble | Edit this page |