From c2ca279bcc2b9797f864950bc6fd3f3436e02dd3 Mon Sep 17 00:00:00 2001 From: Yiming Date: Tue, 26 Jun 2018 22:00:40 -0400 Subject: [PATCH 1/2] mismatch --- .../hunter/log/core/analysis/LogAnalyzer.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java index dcb73ac2..08b5c21d 100644 --- a/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java +++ b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java @@ -1,6 +1,7 @@ package edu.cuny.hunter.log.core.analysis; import java.util.HashSet; +import java.util.LinkedList; import java.util.Map; import java.util.Set; import java.util.logging.Level; @@ -35,13 +36,27 @@ public void analyze() { Map> projectToLoggings = this.getLogInvocationSet().stream() .collect(Collectors.groupingBy(LogInvocation::getExpressionJavaProject, Collectors.toSet())); + HashSet degreeOfInterests = new HashSet<>(); this.getLogInvocationSet().forEach(e -> { e.logInfo(); + degreeOfInterests.add(e.getDegreeOfInterestValue()); }); // TODO: analyze logging here. } + + /** + * Build a list of boundary. The DOI values could be divided into 7 groups by + * this boundary. 7 groups are corresponding to 7 logging levels + * + * @param degreeOfInterests + * @return a list of boundary + */ + private LinkedList buildBoundary(HashSet degreeOfInterests) { + //TODO: implementation + return null; + } public Set getLogInvocationSet() { return this.logInvocationSet; From f9f0d7baf3ea8c103b74f2eb81de1ca7471188b2 Mon Sep 17 00:00:00 2001 From: Yiming Date: Wed, 27 Jun 2018 18:57:39 -0400 Subject: [PATCH 2/2] mismatch --- .../hunter/log/core/analysis/LogAnalyzer.java | 93 +++++++++++++++++-- 1 file changed, 84 insertions(+), 9 deletions(-) diff --git a/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java index 08b5c21d..77b3f721 100644 --- a/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java +++ b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java @@ -7,11 +7,11 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; +import java.util.stream.IntStream; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.MethodInvocation; - import edu.cuny.hunter.log.core.utils.LoggerNames; import edu.cuny.hunter.log.core.utils.Util; @@ -21,6 +21,8 @@ public class LogAnalyzer extends ASTVisitor { private Set logInvocationSet = new HashSet<>(); + private static LinkedList boundary; + private boolean test; public LogAnalyzer(boolean b) { @@ -37,15 +39,60 @@ public void analyze() { .collect(Collectors.groupingBy(LogInvocation::getExpressionJavaProject, Collectors.toSet())); HashSet degreeOfInterests = new HashSet<>(); - this.getLogInvocationSet().forEach(e -> { - e.logInfo(); - degreeOfInterests.add(e.getDegreeOfInterestValue()); - }); + for (LogInvocation logInvocation : this.logInvocationSet) { + logInvocation.logInfo(); + degreeOfInterests.add(logInvocation.getDegreeOfInterestValue()); + } + + // build boundary + boundary = buildBoundary(degreeOfInterests); + // check whether action is needed + for (LogInvocation logInvocation : this.logInvocationSet) + if (this.doAction(logInvocation)) + // TODO: add more log messages here + LOGGER.info("Refactoring happens!"); + + } - // TODO: analyze logging here. + private boolean doAction(LogInvocation logInvocation) { + Level currentLogLevel = logInvocation.getLogLevel(); + Level suggestedLogLevel = getSuggestedLogLevel(boundary, logInvocation.getDegreeOfInterestValue()); + // TODO: do action here + if (currentLogLevel == suggestedLogLevel) + return false; + if (suggestedLogLevel == null || currentLogLevel == null) + return false; + return true; + } + + /** + * Get the suggested log level based on boundary. + * + * @param boundary + * @param DOI + * @return the suggested log level + */ + private static Level getSuggestedLogLevel(LinkedList boundary, float DOI) { + if (boundary == null) + return null; + if (DOI >= boundary.get(0) && DOI < boundary.get(1)) + return Level.FINEST; + if (DOI < boundary.get(2)) + return Level.FINER; + if (DOI < boundary.get(3)) + return Level.FINE; + if (DOI < boundary.get(4)) + return Level.CONFIG; + if (DOI < boundary.get(5)) + return Level.INFO; + if (DOI < boundary.get(6)) + return Level.WARNING; + if (DOI <= boundary.get(7)) + return Level.SEVERE; + return null; } - + /** * Build a list of boundary. The DOI values could be divided into 7 groups by * this boundary. 7 groups are corresponding to 7 logging levels @@ -54,8 +101,36 @@ public void analyze() { * @return a list of boundary */ private LinkedList buildBoundary(HashSet degreeOfInterests) { - //TODO: implementation - return null; + float min = getMinDOI(degreeOfInterests); + float max = getMaxDOI(degreeOfInterests); + LinkedList boundary = new LinkedList<>(); + if (min <= max) { + float interval = (max - min) / 7; + IntStream.range(0, 8).forEach(i -> boundary.add(min + i * interval)); + return boundary; + } else + return null; + } + + /** + * Get the minimum of DOIs + * + * @param degreeOfInterests + */ + private float getMinDOI(HashSet degreeOfInterests) { + float min = Float.MAX_VALUE; + for (float d : degreeOfInterests) + if (d < min) + min = d; + return min; + } + + private float getMaxDOI(HashSet degreeOfInterests) { + float max = Float.MIN_VALUE; + for (float d : degreeOfInterests) + if (d > max) + max = d; + return max; } public Set getLogInvocationSet() {