[apache-rat-pd] r53 committed - Comments in whole project have been write down according to javadoc st...

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 21, 2009, 8:05:27 PM8/21/09
to apache-rat...@googlegroups.com
Revision: 53
Author: maka82
Date: Fri Aug 21 17:04:14 2009
Log: Comments in whole project have been write down according to javadoc
standard trying to give more informations about parameters and about
returning informations for functions.
Some misspelled words have been written correct now.
Also, CamelCases are used now in a project where it is needed.
Some TODOs are fixed.
http://code.google.com/p/apache-rat-pd/source/detail?r=53

Modified:
/trunk/src/main/java/org/apache/rat/pd/core/PdCommandLine.java
/trunk/src/main/java/org/apache/rat/pd/core/PlagiarismDetector.java
/trunk/src/main/java/org/apache/rat/pd/core/SourceCodeAnalyser.java
/trunk/src/main/java/org/apache/rat/pd/engines/ISearchEngine.java
/trunk/src/main/java/org/apache/rat/pd/engines/KodersCodeSearchParser.java
/trunk/src/main/java/org/apache/rat/pd/engines/Managable.java
/trunk/src/main/java/org/apache/rat/pd/engines/RetryManager.java

/trunk/src/main/java/org/apache/rat/pd/engines/google/GoogleCodeSearchParser.java

/trunk/src/main/java/org/apache/rat/pd/engines/google/MultilineRegexGenerator.java

/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicChecker.java

/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/FortranFunctionHeuristicChecker.java

/trunk/src/main/java/org/apache/rat/pd/heuristic/misspellings/MisspellingsHeuristicChecker.java
/trunk/src/main/java/org/apache/rat/pd/util/FileManipulator.java
/trunk/src/test/java/org/apache/rat/pd/core/SlidingWindowAlgorithmTest.java

/trunk/src/test/java/org/apache/rat/pd/engines/google/RegexGeneratorTest.java

/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicCheckerTest.java

=======================================
--- /trunk/src/main/java/org/apache/rat/pd/core/PdCommandLine.java Fri Aug
21 06:53:09 2009
+++ /trunk/src/main/java/org/apache/rat/pd/core/PdCommandLine.java Fri Aug
21 17:04:14 2009
@@ -173,7 +173,7 @@
} catch (Exception e) {
// oops, something went wrong
this.out.println("Parsing failed. Reason: " + e.getMessage());
- // if any error is happened, we can say that not all arguments
are
+ // if any error happened, we can say that not all arguments are
// correct
allArgumentsCorrect = false;
}
@@ -194,6 +194,8 @@
* Parse arguments and gets parameters from them.
*
* @param args command line arguments
+ * @throws ParseException
+ * @throws NumberFormatException
*/
private void parseArguments(String[] args) throws ParseException,
NumberFormatException {
CommandLineParser parser = new GnuParser();
@@ -260,7 +262,8 @@
* If some property is invalid an exception is thrown.
*
* @param line CommandLine
- * @throws NumberFormatException , IllegalArgumentException
+ * @throws NumberFormatException
+ * @throws IllegalArgumentException
*/
private void parseCommandLineArguments(CommandLine line) throws
NumberFormatException, IllegalArgumentException {

=======================================
--- /trunk/src/main/java/org/apache/rat/pd/core/PlagiarismDetector.java Fri
Aug 21 06:53:09 2009
+++ /trunk/src/main/java/org/apache/rat/pd/core/PlagiarismDetector.java Fri
Aug 21 17:04:14 2009
@@ -91,6 +91,7 @@
/**
* @param args
* @throws RatReportFailedException
+ * @throws IOException
*/
public static void main(String[] args) throws
RatReportFailedException, IOException {
// instance of PlagiarismDetector
@@ -129,7 +130,7 @@
* Decide which format of report will be used.
*
* @param pdCommandLine command line object to read report format from
- * @return
+ * @return which format of report will be used
*/
private Report configureReport(PdCommandLine pdCommandLine) {
Report reportDocument;
=======================================
--- /trunk/src/main/java/org/apache/rat/pd/core/SourceCodeAnalyser.java Fri
Aug 21 06:53:09 2009
+++ /trunk/src/main/java/org/apache/rat/pd/core/SourceCodeAnalyser.java Fri
Aug 21 17:04:14 2009
@@ -58,7 +58,7 @@
* @param searchEngines list of chosen search engine parsers
* @param algorithmsForChecking list of chosen heuristic algorithms
* @param reportDocument chosen report
- * @param out printStream wnere current information are be printed
+ * @param out printStream where current information are to be printed
*/
public SourceCodeAnalyser(List<ISearchEngine> searchEngines,
List<IHeuristicChecker> algorithmsForChecking,
Report reportDocument, PrintStream out) {
@@ -133,18 +133,18 @@
* @throws IOException
*/
private String readFile(Reader reader) throws IOException {
- String toret = "";
+ String toRet = "";
// TODO encoding is system default now!!!!
BufferedReader input = new BufferedReader(reader);
try {
String line = null;
while ((line = input.readLine()) != null) {
- toret += line + "\n";
+ toRet += line + "\n";
}
} finally {
input.close();
}
- return toret;
+ return toRet;
}

/**
@@ -209,16 +209,16 @@
}

/**
- * Search for code in all engines. If code is found, an reportEntry
will be
- * returned Otherwise, null will be returned.
+ * Search for code in all engines. If code is found, a reportEntry
will be
+ * returned. Otherwise, null will be returned.
*
* @param searchEngines list of chosen search engine parsers
* @param code code to be checked
* @param fileName source file name
- * @return an report entry
+ * @return a report entry
*/
private ReportEntry searchOnInternet(List<ISearchEngine>
searchEngines, String code, String fileName) {
- ReportEntry toret = null;
+ ReportEntry toRet = null;
List<SearchResult> found = new ArrayList<SearchResult>();
for (ISearchEngine searchEngine : searchEngines) {
if (searchEngine.isCodeFound(code.toString())) {
@@ -226,36 +226,36 @@
}
}
if (!found.isEmpty()) {
- toret = new ReportEntry(found, code, fileName);
- }
- return toret;
+ toRet = new ReportEntry(found, code, fileName);
+ }
+ return toRet;
}

/**
- * @param heuristicCheckers lit of chosen heuristic checkers
+ * @param heuristicCheckers list of chosen heuristic checkers
* @param toCheck code to be checked
* @return heuristicCheckerResult with proper information for sliding
window
* algorithm
*/
private HeuristicCheckerResult
isCheckOnInternetNeaded(List<IHeuristicChecker> heuristicCheckers, String
toCheck) {

- HeuristicCheckerResult toret = new HeuristicCheckerResult(false,
true, toCheck, null);
+ HeuristicCheckerResult toRet = new HeuristicCheckerResult(false,
true, toCheck, null);
for (IHeuristicChecker checker : heuristicCheckers) {
- toret = checker.checkByHeuristic(toCheck);
- if (toret.isShouldStretch()) {
+ toRet = checker.checkByHeuristic(toCheck);
+ if (toRet.isShouldStretch()) {
break;
}
}

- return toret;
+ return toRet;
}

/**
* Append tokens from start position until end.
*
* @param tokens list of tokens to combine
- * @param start position
- * @param end position
+ * @param start index of start position
+ * @param end index of end position
* @return appended tokens
*/
private StringBuffer combineTokens(String[] tokens, int start, int
end) {
@@ -290,9 +290,9 @@
*<p>
* Example:Analyzing file : c:\HelloWorld.java Progress: 2/200 (1%)
*
- * @param whole is number of all tokens we iterate
- * @param current is current position of iteration
- * @param fileName is file name of source file
+ * @param whole number of all tokens we iterate
+ * @param current current position of iteration
+ * @param fileName file name of source file
*/
private void printProgress(int whole, int current, String fileName) {
// clear previous state
=======================================
--- /trunk/src/main/java/org/apache/rat/pd/engines/ISearchEngine.java Fri
Aug 21 06:53:09 2009
+++ /trunk/src/main/java/org/apache/rat/pd/engines/ISearchEngine.java Fri
Aug 21 17:04:14 2009
@@ -33,10 +33,10 @@
/**
* Checks if code part exist on this code search engine
*
- * @param posibleCutAndPastedCode
+ * @param possibleCopyAndPastedCode code currently being checked
* @return boolean - true if this code is found on search engine
*/
- boolean isCodeFound(String posibleCutAndPastedCode);
+ boolean isCodeFound(String possibleCopyAndPastedCode);

/**
* This method can return search results with link where we can see
exactly
=======================================
---
/trunk/src/main/java/org/apache/rat/pd/engines/KodersCodeSearchParser.java
Fri Aug 21 06:53:09 2009
+++
/trunk/src/main/java/org/apache/rat/pd/engines/KodersCodeSearchParser.java
Fri Aug 21 17:04:14 2009
@@ -31,7 +31,7 @@
private static final String serch
= "http://www.koders.com/default.aspx?s=MyQuery&btn=&la=%2A&li=%2A";

@Override
- public boolean isCodeFound(String posibleCutAndPastedCode) {
+ public boolean isCodeFound(String possibleCopyAndPastedCode) {
// TODO Auto-generated method stub
return false;
}
=======================================
--- /trunk/src/main/java/org/apache/rat/pd/engines/Managable.java Fri Aug
21 06:53:09 2009
+++ /trunk/src/main/java/org/apache/rat/pd/engines/Managable.java Fri Aug
21 17:04:14 2009
@@ -35,10 +35,10 @@
* This function can retrieve information about potentially
plagiarised code
* from search engine. NOTE: for now there are only this types of
exceptions
*
- * @param posibleCutAndPastedCode
- * @return
+ * @param possibleCopyAndPastedCode code currently being checked
+ * @return information about if code is found
* @throws IOException
* @throws ServiceException
*/
- boolean gueryEngine(String posibleCutAndPastedCode) throws
IOException, ServiceException;
-}
+ boolean gueryEngine(String possibleCopyAndPastedCode) throws
IOException, ServiceException;
+}
=======================================
--- /trunk/src/main/java/org/apache/rat/pd/engines/RetryManager.java Fri
Aug 21 06:53:09 2009
+++ /trunk/src/main/java/org/apache/rat/pd/engines/RetryManager.java Fri
Aug 21 17:04:14 2009
@@ -51,14 +51,14 @@
* query SearchEngine for this information. If an exception happened,
it
* will wait before next retry.
*
- * @param posibleCutAndPastedCode
+ * @param possibleCopyAndPastedCode code currently being checked
* @return information is code plagiarised
*/
- public boolean isCodeFound(String posibleCutAndPastedCode) {
- boolean toret = false;
+ public boolean isCodeFound(String possibleCopyAndPastedCode) {
+ boolean toRet = false;
for (int i = 0; i < numberOfRetry; i++) {
try {
- toret = searchengine.gueryEngine(posibleCutAndPastedCode);
+ toRet =
searchengine.gueryEngine(possibleCopyAndPastedCode);
break;
} catch (Exception e) {
// just print number of retry
@@ -73,7 +73,7 @@
}
}
}
- return toret;
+ return toRet;
}

}
=======================================
---
/trunk/src/main/java/org/apache/rat/pd/engines/google/GoogleCodeSearchParser.java
Fri Aug 21 06:53:09 2009
+++
/trunk/src/main/java/org/apache/rat/pd/engines/google/GoogleCodeSearchParser.java
Fri Aug 21 17:04:14 2009
@@ -46,7 +46,7 @@
/**
* This class is for communication between search engine and this program.
*
- * @author maka:
+ * @author maka
*/
public class GoogleCodeSearchParser implements ISearchEngine, Managable {

@@ -92,12 +92,12 @@
* results will be true.
*
* @param searchResults list of results for our query
- * @param posibleCutAndPastedCode code currently being checked
- * @return information is there any match is found
+ * @param possibleCopyAndPastedCode code currently being checked
+ * @return information is there any match found
*/
- public boolean isMatchFound(List<SearchResult> searchResults,
String posibleCutAndPastedCode) {
- boolean toret = false;
- String[] lines = posibleCutAndPastedCode.split("\n *");
+ public boolean isMatchFound(List<SearchResult> searchResults,
String possibleCopyAndPastedCode) {
+ boolean toRet = false;
+ String[] lines = possibleCopyAndPastedCode.split("\n *");

// iterate ower results
for (SearchResult searchResult : searchResults) {
@@ -106,13 +106,13 @@

for (String line : lines) {
if (isMatchingByDistance(match, line) ||
this.isMatchingByRegex(match, line)) {
- toret = true;
+ toRet = true;
break;
}
}
}
}
- return toret;
+ return toRet;
}

/**
@@ -127,10 +127,10 @@

int maxLength = toMatch.length() > source.length() ?
toMatch.length() : source.length();
int distance = StringUtils.getLevenshteinDistance(toMatch,
source);
- boolean toret = (maxLength > 0) && (similarityFactor < 100 -
(distance * 100) / maxLength);
+ boolean toRet = (maxLength > 0) && (similarityFactor < 100 -
(distance * 100) / maxLength);
// TODO think about lines with only one character. }
// for example!!!
- return toret;
+ return toRet;
}

/**
@@ -166,11 +166,11 @@
}

private String getLanguageQuery() {
- String toret = "";
+ String toRet = "";
if (!language.equals(IHeuristicChecker.ALL_LANGUAGES)) {
- toret = "as_lang=" + this.language + "&";
- }
- return toret;
+ toRet = "as_lang=" + this.language + "&";
+ }
+ return toRet;
}

/*
@@ -184,19 +184,18 @@
}

/**
- * @param posibleCutAndPastedCode code for checking
+ * @param possibleCopyAndPastedCode code currently being checked
* @return proper URL for gdata-codesearch API
* @throws MalformedURLException
*/
@SuppressWarnings("deprecation")
// FIXME URLEncoding is system dependent now
- private URL createUrl(String posibleCutAndPastedCode) throws
MalformedURLException {
- URL toret = new URL(CODESEARCH_FEEDS_URL + getLanguageQuery()
+ "q="
- +
URLEncoder.encode(regexGenerator.stringToRegex(posibleCutAndPastedCode))
+ "&max-results="
+ private URL createUrl(String possibleCopyAndPastedCode) throws
MalformedURLException {
+ URL toRet = new URL(CODESEARCH_FEEDS_URL + getLanguageQuery()
+ "q="
+ +
URLEncoder.encode(regexGenerator.stringToRegex(possibleCopyAndPastedCode))
+ "&max-results="
+ RESULT_NUMBER);

- out.println(posibleCutAndPastedCode + " -> " +
regexGenerator.stringToRegex(posibleCutAndPastedCode));
- return toret;
+ return toRet;
}

/*
@@ -206,9 +205,9 @@
*
org.apache.rat.pd.engines.ISearchEngine#isCodeFound(java.lang.String)
*/
@Override
- public boolean isCodeFound(String posibleCutAndPastedCode) {
+ public boolean isCodeFound(String possibleCopyAndPastedCode) {
searchResults.clear();
- return retryManager.isCodeFound(posibleCutAndPastedCode);
+ return retryManager.isCodeFound(possibleCopyAndPastedCode);
}

/*
@@ -217,46 +216,39 @@
* @see
org.apache.rat.pd.engines.Managable#gueryEngine(java.lang.String)
*/
@Override
- public boolean gueryEngine(String posibleCutAndPastedCode) throws
IOException, ServiceException {
- boolean toreturn = false;
-
- List<URL> listOfFeedUrl = splitLongUrl(posibleCutAndPastedCode,
CODESEARCH_QUERY_MAX_LENGTH);
- // pozovi svaki url i parsiraj rezultate u zajednicku mapu
+ public boolean gueryEngine(String possibleCopyAndPastedCode) throws
IOException, ServiceException {
+ boolean toReturn = false;
+
+ List<URL> listOfFeedUrl = splitLongUrl(possibleCopyAndPastedCode,
CODESEARCH_QUERY_MAX_LENGTH);
+ // call every URL and parse results in one map
for (URL url : listOfFeedUrl) {
CodeSearchFeed myFeed = codesearchService.getFeed(url,
CodeSearchFeed.class);
- List<SearchResult> srList = createSearchResutl(myFeed,
posibleCutAndPastedCode);
- boolean found = (srList.size() > 0) &&
(postprocessor.isMatchFound(srList, posibleCutAndPastedCode));
-
- toreturn = toreturn || found;
+ List<SearchResult> srList = createSearchResutl(myFeed,
possibleCopyAndPastedCode);
+ boolean found = (srList.size() > 0) &&
(postprocessor.isMatchFound(srList, possibleCopyAndPastedCode));
+
+ toReturn = toReturn || found;

if (found) {
searchResults.addAll(srList);
}
- // for test porposes
- // try {
- // printAdditionalInformation(myFeed, System.out);
- // } catch (Exception e) {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
}

- return toreturn;
+ return toReturn;
}

/**
* This method can split code to produce URLs that will not be greater
then
* length. For GoogleCodeSearch length is 1024.
*
- * @param posibleCutAndPastedCode code to be checked
+ * @param possibleCopyAndPastedCode code to be checked
* @param length maximum length of query which code search engine can
manage
- * @return list of url-s not longer then @length
+ * @return list of URL-s not longer then @length
* @throws IOException
*/
- List<URL> splitLongUrl(String posibleCutAndPastedCode, int length)
throws IOException {
- List<URL> toret = new ArrayList<URL>();
+ List<URL> splitLongUrl(String possibleCopyAndPastedCode, int length)
throws IOException {
+ List<URL> toRet = new ArrayList<URL>();
// lines must be less then 1024 characters
- String[] lines = posibleCutAndPastedCode.split("\n *");
+ String[] lines = possibleCopyAndPastedCode.split("\n *");
URL url = null;

int i = 0;
@@ -266,6 +258,7 @@
while (j < lines.length) {
StringBuffer currenCodePart = combineLines(lines, i, j);
URL currentUrl = createUrl(currenCodePart.toString());
+
if (currentUrl.toString().length() <= length) {
url = currentUrl;
j++;
@@ -275,23 +268,23 @@
}
}
if (url != null) {
- toret.add(url);
+ toRet.add(url);
url = null;
}
if (j == lines.length) {
break;
}
}
- return toret;
+ return toRet;
}

/**
* Append tokens from start position until end, inclusive.
*
- * @param tokens
- * @param start
- * @param end
- * @return
+ * @param tokens list of tokens to combine
+ * @param start index of start position
+ * @param end index of end position
+ * @return appended tokens
*/
private StringBuffer combineLines(String[] tokens, int start, int end)
{

@@ -310,7 +303,6 @@
* @param myFeed GoogleCodeSearch feed
* @param entry Google CodeSearchEntry
* @param out print stream for printing current information
- * @throws Exception
*/
private void printAdditionalInformation(CodeSearchFeed myFeed,
CodeSearchEntry entry) {
out.println("\tgetEtag: " + entry.getEtag());
@@ -340,15 +332,15 @@
* us form.
*
* @param myFeed GoogleCodeSearch feed
- * @param posibleCutAndPastedCode code to be checked
+ * @param possibleCopyAndPastedCode code to be checked
* @return list of search result retrieved from GoogleCodeSearch feed
*/
- private List<SearchResult> createSearchResutl(CodeSearchFeed myFeed,
String posibleCutAndPastedCode) {
+ private List<SearchResult> createSearchResutl(CodeSearchFeed myFeed,
String possibleCopyAndPastedCode) {
List<SearchResult> toRet = new ArrayList<SearchResult>();
for (CodeSearchEntry entry : myFeed.getEntries()) {
SearchResult searchResult = new SearchResult();
searchResult.setEngine("GoogleCodeSearch");
- searchResult.setCodeForQuery(posibleCutAndPastedCode);
+ searchResult.setCodeForQuery(possibleCopyAndPastedCode);
searchResult.setLink(entry.getHtmlLink().getHref());
searchResult.setProjectName(entry.getPackage().getName());
searchResult.setOwner(entry.getAuthors().get(0).getName());
=======================================
---
/trunk/src/main/java/org/apache/rat/pd/engines/google/MultilineRegexGenerator.java
Fri Aug 21 06:53:09 2009
+++
/trunk/src/main/java/org/apache/rat/pd/engines/google/MultilineRegexGenerator.java
Fri Aug 21 17:04:14 2009
@@ -43,18 +43,18 @@
*/
@Override
public String stringToRegex(String sourceCode) {
- String toret = "";
+ String toRet = "";
String[] lines = sourceCode.split("\n *");
lines = excludeBlankLines(lines);
for (int i = 0; i < lines.length; i++) {
- toret += LINE_BEGINNING_REGEX + ZERO_OR_MORE_BLANK_SPACE +
super.stringToRegex(lines[i]);
+ toRet += LINE_BEGINNING_REGEX + ZERO_OR_MORE_BLANK_SPACE +
super.stringToRegex(lines[i]);
// for current line, it is better not to add LINE_END_REGEX.
- // we don't know is end of real line in code is reached
+ // we don't know if end of real line in code is reached
if (i != lines.length - 1) {
- toret += ZERO_OR_MORE_BLANK_SPACE + LINE_END_REGEX +
BLANK_MARK_FOR_URL;
+ toRet += ZERO_OR_MORE_BLANK_SPACE + LINE_END_REGEX +
BLANK_MARK_FOR_URL;
}
}
- return toret;
+ return toRet;
}

/**
@@ -72,14 +72,14 @@
}
}
// copy non-blank lines
- String[] toret = new String[lentgh];
+ String[] toRet = new String[lentgh];
int index = 0;
for (String line : lines) {
if (!line.trim().isEmpty()) {
- toret[index] = line;
+ toRet[index] = line;
index++;
}
}
- return toret;
+ return toRet;
}
}
=======================================
---
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicChecker.java
Fri Aug 21 06:53:09 2009
+++
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicChecker.java
Fri Aug 21 17:04:14 2009
@@ -47,8 +47,6 @@
* rhs.GetItsVal()); }
*/
private static final String CPP_FUNCTION_REGEX_2 = "^[\t ]*[\\w+
\\*&]+\\s*\\:\\:\\s*[*&~]?\\s*\\w+ *\\([^()]*?\\)( *const
*)?(\\s)*\\{[\\s\\S]*\\}[\n\r]*";
- // TODO add regular expression which will match functions with a
reference
- // to a string as a returning type for example.
private static final String CPP_FUNCTION_REGEX = "(" +
CPP_FUNCTION_REGEX_1 + ")|(" + CPP_FUNCTION_REGEX_2 + ")";

/**
=======================================
---
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/FortranFunctionHeuristicChecker.java
Fri Aug 21 06:53:09 2009
+++
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/FortranFunctionHeuristicChecker.java
Fri Aug 21 17:04:14 2009
@@ -114,9 +114,11 @@
* or after subprogram. Depends on limit property, function can return
false
* if matched subprogram length is smaller then limit value.
*
- * @param codeToBeChecked
- * @param functionHeader
- * @param functionEndRegex
+ * @param codeToBeChecked code currently being checked
+ * @param functionHeader regular expression which match header of a
+ * subprogram in Fortran
+ * @param functionEndRegex regular expression which match end of a
+ * subprogram in Fortran
* @return true if this is Fortran subprogram.
*/
boolean isFortranFunction(String codeToBeChecked, String
functionHeader, String functionEndRegex) {
@@ -141,9 +143,11 @@
/**
* Method will return functions name from a functions header
*
- * @param functionHeader
- * @param keywordRegex
- * @param functionNameRegex
+ * @param functionHeader regular expression which match header of a
+ * subprogram in Fortran
+ * @param keywordRegex keyword for function and subroutine
+ * @param functionNameRegex regular expression which match keyword and
name
+ * of a subprogram in Fortran
* @return functions name
*/
String getFunctionName(String functionHeader, String keywordRegex,
String functionNameRegex) {
@@ -165,8 +169,8 @@
* Method will return functions header from a string. Functions header
is
* matched by a regular expression regex.
*
- * @param codeToBeChecked
- * @param regex
+ * @param codeToBeChecked code currently being checked
+ * @param regex regular expression which match subprogram's header
* @return functions header if it functions
*/
String getFunctionHeader(String codeToBeChecked, String regex) {
=======================================
---
/trunk/src/main/java/org/apache/rat/pd/heuristic/misspellings/MisspellingsHeuristicChecker.java
Fri Aug 21 06:53:09 2009
+++
/trunk/src/main/java/org/apache/rat/pd/heuristic/misspellings/MisspellingsHeuristicChecker.java
Fri Aug 21 17:04:14 2009
@@ -64,7 +64,7 @@
*/
@Override
public HeuristicCheckerResult checkByHeuristic(String codeToBeChecked)
{
- HeuristicCheckerResult toret = new HeuristicCheckerResult(false,
true, codeToBeChecked, this.getClass());
+ HeuristicCheckerResult toRet = new HeuristicCheckerResult(false,
true, codeToBeChecked, this.getClass());
boolean isCheckingOnInternetNeaded = true;
List<String> words = filterWordsFromCode(codeToBeChecked);
for (String word : words) {
@@ -75,8 +75,8 @@
out.println("Error in decomposing word:" + word + " We
consider that it is misspelled.");
}
}
- toret = new HeuristicCheckerResult(!isCheckingOnInternetNeaded,
false, codeToBeChecked, this.getClass());
- return toret;
+ toRet = new HeuristicCheckerResult(!isCheckingOnInternetNeaded,
false, codeToBeChecked, this.getClass());
+ return toRet;
}

/**
@@ -87,24 +87,24 @@
* @return list of words in codeToBeChecked
*/
List<String> filterWordsFromCode(String codeToBeChecked) {
- List<String> toret = new ArrayList<String>();
+ List<String> toRet = new ArrayList<String>();
Pattern p = Pattern.compile("[a-zA-Z_]+", Pattern.MULTILINE);
Matcher m = p.matcher(codeToBeChecked);
while (m.find()) {
- toret.add(m.group());
- }
- return toret;
+ toRet.add(m.group());
+ }
+ return toRet;
}

boolean isWordCorrect(List<String> combinedWords) throws IOException {
- boolean toret = true;
+ boolean toRet = true;
for (String word : combinedWords) {
// it is assumed that words with capital case are equal to
word with
// all small case in dictionary
- toret = toret && spellChecker.exist(word.toLowerCase());
- out.println(word + " " + toret);
- }
- return toret;
+ toRet = toRet && spellChecker.exist(word.toLowerCase());
+ out.println(word + " " + toRet);
+ }
+ return toRet;
}

/**
@@ -118,11 +118,11 @@
*/
List<String> decomposeCombinedWord(String combinedWord) throws
IllegalArgumentException {
Validate.isTrue(combinedWord.matches("[a-zA-Z_]+"));
- List<String> toret = new ArrayList<String>();
- toret.add(combinedWord);
- toret = decomposeUnderscoreCombinedWords(toret);
- toret = decomposeCamelCombinedWords(toret);
- return toret;
+ List<String> toRet = new ArrayList<String>();
+ toRet.add(combinedWord);
+ toRet = decomposeUnderscoreCombinedWords(toRet);
+ toRet = decomposeCamelCombinedWords(toRet);
+ return toRet;
}

/**
@@ -133,15 +133,15 @@
* @return list of decomposed words
*/
List<String> decomposeUnderscoreCombinedWords(List<String>
combinedWord) {
- List<String> toret = new ArrayList<String>();
+ List<String> toRet = new ArrayList<String>();
for (String word : combinedWord) {
- toret.addAll(new
ArrayList<String>(Arrays.asList(word.split("_+"))));
+ toRet.addAll(new
ArrayList<String>(Arrays.asList(word.split("_+"))));
// sometimes empty string is entered in list
// this remove such entries
- toret.remove("");
+ toRet.remove("");
}

- return toret;
+ return toRet;
}

/**
@@ -152,14 +152,14 @@
* @return list of decomposed words
*/
List<String> decomposeCamelCombinedWords(List<String> combinedWord) {
- List<String> toret = new ArrayList<String>();
+ List<String> toRet = new ArrayList<String>();
for (String word : combinedWord) {
// extract only first part with small caps of string if it
exists
// example: thisIsMyName -> this
Pattern p = Pattern.compile("\\b[a-z]+");
Matcher m = p.matcher(word);
if (m.find()) {
- toret.add(m.group());
+ toRet.add(m.group());
}

// extract all parts of string which starts with capital case
to
@@ -168,10 +168,10 @@
p = Pattern.compile("[A-Z][a-z]*");
m = p.matcher(word);
while (m.find()) {
- toret.add(m.group());
+ toRet.add(m.group());
}
}
- return toret;
+ return toRet;
}

@Override
=======================================
--- /trunk/src/main/java/org/apache/rat/pd/util/FileManipulator.java Fri
Aug 21 06:53:09 2009
+++ /trunk/src/main/java/org/apache/rat/pd/util/FileManipulator.java Fri
Aug 21 17:04:14 2009
@@ -46,17 +46,17 @@
static public String readFile(String path) throws IOException {
File aFile = new File(path);

- String toret = "";
+ String toRet = "";
BufferedReader input = new BufferedReader(new FileReader(aFile));
try {
String line = null;
while ((line = input.readLine()) != null) {
- toret += line + "\n";
+ toRet += line + "\n";
}
} finally {
input.close();
}
- return toret;
+ return toRet;
}

public static String convertStreamToString(InputStream is) {
=======================================
---
/trunk/src/test/java/org/apache/rat/pd/core/SlidingWindowAlgorithmTest.java
Fri Aug 21 06:53:09 2009
+++
/trunk/src/test/java/org/apache/rat/pd/core/SlidingWindowAlgorithmTest.java
Fri Aug 21 17:04:14 2009
@@ -201,8 +201,8 @@
}

@Override
- public boolean isCodeFound(String posibleCutAndPastedCode) {
- String temp = posibleCutAndPastedCode.replaceAll("(F )*(T
)*TEND", "");
+ public boolean isCodeFound(String possibleCopyAndPastedCode) {
+ String temp = possibleCopyAndPastedCode.replaceAll("(F )*(T
)*TEND", "");
if (temp.trim().length() > 0) {
return false;
} else
=======================================
---
/trunk/src/test/java/org/apache/rat/pd/engines/google/RegexGeneratorTest.java
Fri Aug 21 06:53:09 2009
+++
/trunk/src/test/java/org/apache/rat/pd/engines/google/RegexGeneratorTest.java
Fri Aug 21 17:04:14 2009
@@ -29,11 +29,7 @@
private RegexGenerator regexGenerator = new RegexGenerator();
private String TEST_CASE_1 = "public static void main(String[]
args)";//()[]
private String TEST_CASE_2 = "public static void main(String[]
args){}";//{}
- private String TEST_CASE_3 = "private List<String> getArray(){ return
array }";// less
-
//
then
-
//
and
-
//
greater
-
//
then
+ private String TEST_CASE_3 = "private List<String> getArray(){ return
array }";// less then and greater then
private String TEST_CASE_4 = "this.getClass()";// dot
private String TEST_CASE_5 = "for(String s : list)";// two dots
private String TEST_CASE_6 = "evaluate == 1 ? true : false";//
question mark
@@ -44,7 +40,7 @@
private String TEST_CASE_11 = "\"Hello World\"";// semicilumn
private String TEST_CASE_12 = "$";// dollar sign
private String TEST_CASE_13 = "^";// power sign
- private String TEST_CASE_14 = "\\";// back slash
+ private String TEST_CASE_14 = "\\a\\";// back slash

public void testAddWhitespaceAroundDot() {
String regex =
regexGenerator.addWhitespaceAroundNonLiteral(TEST_CASE_4);
@@ -131,7 +127,7 @@
// there was a bug causing application to break when code consist
// backslash character
regex = regexGenerator.stringToRegex(TEST_CASE_14);
- assertEquals("I except that regex is .....", "\\\\", regex);
+ assertEquals("I except that regex is .....", "\\\\a\\\\", regex);

System.out.println(TEST_CASE_14 + " --------> " + regex);

=======================================
---
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicCheckerTest.java
Fri Aug 21 06:53:09 2009
+++
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicCheckerTest.java
Fri Aug 21 17:04:14 2009
@@ -27,7 +27,7 @@
public class CPPFunctionHeuristicCheckerTest extends TestCase {
private CPPFunctionHeuristicChecker checker;

- private static final String SIMPLE_FUNCTION_1 = "void name (){}";
+ private static final String SIMPLE_FUNCTION_1 = "void * name (){}";
private static final String SIMPLE_FUNCTION_2 = "public void name
(int prom1 , \n string prom 2) {\n something; \n}";
private static final String SIMPLE_FUNCTION_3 = "void
BubbleSort(apvector <int> &num)\n" + "{\n"
+ " int i, j, flag = 1; // set flag to 1 to start
first pass\n"
@@ -41,7 +41,7 @@
+ " }\n" + " }\n"
+ " return; //arrays are passed to functions by address;
nothing is returned\n" + "}";

- private static final String SIMPLE_FUNCTION_4
= "MyClass::MyClass(MyClass&)\n" + "{\n"
+ private static final String SIMPLE_FUNCTION_4 = "MyClass::~
MyClass(MyClass&)\n" + "{\n"
+ " std::cout << \"Simple Cat Constructor...\n\";\n" + "
itsAge = 1;\n" + "}";
private static final String SIMPLE_FUNCTION_5 = "MyType
MyType::Add(const MyType & rhs)\n" + " {\n"
+ " return MyType(itsVal+ rhs.GetItsVal());\n" + " }";

Reply all
Reply to author
Forward
0 new messages