Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make actions #51

Merged
merged 4 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package edu.cuny.hunter.log.core.analysis;

public enum Action {
NONE,
CONVERT_TO_SEVERE,
CONVERT_TO_WARNING,
CONVERT_TO_INFO,
CONVERT_TO_CONFIG,
CONVERT_TO_FINE,
CONVERT_TO_FINER,
CONVERT_TO_FINEST
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,34 @@ public void analyze() {
// check whether action is needed
for (LogInvocation logInvocation : this.logInvocationSet)
if (this.doAction(logInvocation))
// TODO: add more log messages here
LOGGER.info("Refactoring happens!");
LOGGER.info("Do action: " + logInvocation.getAction() + "! The changed log expression is "
+ logInvocation.getExpression());

}

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;

if (suggestedLogLevel == Level.FINEST)
logInvocation.setAction(Action.CONVERT_TO_FINEST);
if (suggestedLogLevel == Level.FINER)
logInvocation.setAction(Action.CONVERT_TO_FINER);
if (suggestedLogLevel == Level.FINE)
logInvocation.setAction(Action.CONVERT_TO_FINE);
if (suggestedLogLevel == Level.CONFIG)
logInvocation.setAction(Action.CONVERT_TO_CONFIG);
if (suggestedLogLevel == Level.INFO)
logInvocation.setAction(Action.CONVERT_TO_INFO);
if (suggestedLogLevel == Level.WARNING)
logInvocation.setAction(Action.CONVERT_TO_WARNING);
if (suggestedLogLevel == Level.SEVERE)
logInvocation.setAction(Action.CONVERT_TO_SEVERE);
return true;
}

Expand All @@ -76,6 +90,10 @@ private boolean doAction(LogInvocation logInvocation) {
private static Level getSuggestedLogLevel(LinkedList<Float> boundary, float DOI) {
if (boundary == null)
return null;
if (Float.compare(boundary.getFirst(), boundary.getLast()) == 0) {
LOGGER.info("The DOI values are all same. Cannot get valid results.");
return null;
}
if (DOI >= boundary.get(0) && DOI < boundary.get(1))
return Level.FINEST;
if (DOI < boundary.get(2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class LogInvocation {

private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME);

private Action action = Action.NONE;

public LogInvocation(MethodInvocation logExpression, Level loggingLevel) {
this.expression = logExpression;
this.logLevel = loggingLevel;
Expand All @@ -55,7 +57,10 @@ public LogInvocation(MethodInvocation logExpression, Level loggingLevel) {
if (degreeOfInterest != null) {
degreeOfInterestValue = degreeOfInterest.getValue();
}
}

public void setAction(Action action) {
this.action = action;
}

public float getDegreeOfInterestValue() {
Expand Down Expand Up @@ -139,4 +144,8 @@ public void logInfo() {
+ ". Degree of Interest " + (degreeOfInterest == null ? "N/A" : degreeOfInterest.getValue()) + ". ");
}

public Action getAction() {
return this.action;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
CSVPrinter resultPrinter = createCSVPrinter("result.csv",
new String[] { "subject raw", "log expression", "start pos", "logging level",
"type FQN", "enclosing method", "DOI" });
CSVPrinter actionPrinter = createCSVPrinter("log_actions.csv",
new String[] { "subject raw", "log expression", "start pos", "logging level",
"type FQN", "enclosing method", "action" });

// for each selected java project
for (IJavaProject project : javaProjectList) {
Expand All @@ -95,10 +98,17 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
logInvocation.getEnclosingType().getFullyQualifiedName(),
Util.getMethodIdentifier(logInvocation.getEnclosingEclipseMethod()),
logInvocation.getDegreeOfInterestValue());

actionPrinter.printRecord(project.getElementName(), logInvocation.getExpression(),
logInvocation.getStartPosition(), logInvocation.getLogLevel(),
logInvocation.getEnclosingType().getFullyQualifiedName(),
Util.getMethodIdentifier(logInvocation.getEnclosingEclipseMethod()),
logInvocation.getAction());
}
}

resultPrinter.close();
actionPrinter.close();
} catch (IOException e) {
LOGGER.severe("Cannot create printer.");
} catch (OperationCanceledException | CoreException e) {
Expand All @@ -108,4 +118,5 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
}
return null;
}

}