Skip to content

Commit

Permalink
Added support for recording the applied Extract Clone refactorings.
Browse files Browse the repository at this point in the history
Updated plug-in version to 5.0.68
  • Loading branch information
tsantalis committed Jun 5, 2018
1 parent fa9ca49 commit 236469f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JDeodorant Plug-in
Bundle-SymbolicName: gr.uom.java.jdeodorant; singleton:=true
Bundle-Version: 5.0.67
Bundle-Version: 5.0.68
Bundle-Activator: gr.uom.java.jdeodorant.refactoring.Activator
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
import gr.uom.java.ast.decomposition.cfg.PDG;
import gr.uom.java.ast.decomposition.cfg.mapping.PDGMapper;
import gr.uom.java.ast.decomposition.cfg.mapping.PDGSubTreeMapper;
import gr.uom.java.jdeodorant.preferences.PreferenceConstants;
import gr.uom.java.jdeodorant.refactoring.Activator;
import gr.uom.java.jdeodorant.refactoring.manipulators.ExtractCloneRefactoring;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -26,6 +34,7 @@
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ltk.core.refactoring.Refactoring;
Expand Down Expand Up @@ -122,6 +131,34 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
} catch (JavaModelException e) {
e.printStackTrace();
}
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
boolean allowUsageReporting = store.getBoolean(PreferenceConstants.P_ENABLE_USAGE_REPORTING);
if(allowUsageReporting) {
try {
String content = URLEncoder.encode("project_name", "UTF-8") + "=" + URLEncoder.encode(selectedProject.getElementName(), "UTF-8");
content += "&" + URLEncoder.encode("source_class_name_1", "UTF-8") + "=" + URLEncoder.encode(methodObject1.getClassName(), "UTF-8");
content += "&" + URLEncoder.encode("source_class_name_2", "UTF-8") + "=" + URLEncoder.encode(methodObject2.getClassName(), "UTF-8");
content += "&" + URLEncoder.encode("source_method_name_1", "UTF-8") + "=" + URLEncoder.encode(methodObject1.getSignature(), "UTF-8");
content += "&" + URLEncoder.encode("source_method_name_2", "UTF-8") + "=" + URLEncoder.encode(methodObject2.getSignature(), "UTF-8");
content += "&" + URLEncoder.encode("application_type", "UTF-8") + "=" + URLEncoder.encode("selection", "UTF-8");
content += "&" + URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(System.getProperty("user.name"), "UTF-8");
content += "&" + URLEncoder.encode("tb", "UTF-8") + "=" + URLEncoder.encode("4", "UTF-8");
URL url = new URL(Activator.RANK_URL);
URLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream printout = new DataOutputStream(urlConn.getOutputStream());
printout.writeBytes(content);
printout.flush();
printout.close();
DataInputStream input = new DataInputStream(urlConn.getInputStream());
input.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
Refactoring refactoring = new ExtractCloneRefactoring(mapper.getSubTreeMappers());
MyRefactoringWizard wizard = new MyRefactoringWizard(refactoring, null);
RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
Expand Down
44 changes: 43 additions & 1 deletion src/gr/uom/java/jdeodorant/refactoring/views/DuplicatedCode.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package gr.uom.java.jdeodorant.refactoring.views;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -42,6 +48,7 @@
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModel;
Expand Down Expand Up @@ -114,6 +121,8 @@
import gr.uom.java.ast.CompilationUnitCache;
import gr.uom.java.ast.decomposition.cfg.mapping.CloneInstanceMapper;
import gr.uom.java.ast.decomposition.cfg.mapping.PDGRegionSubTreeMapper;
import gr.uom.java.jdeodorant.preferences.PreferenceConstants;
import gr.uom.java.jdeodorant.refactoring.Activator;
import gr.uom.java.jdeodorant.refactoring.manipulators.ExtractCloneRefactoring;

public class DuplicatedCode extends ViewPart {
Expand Down Expand Up @@ -770,6 +779,39 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
} catch (JavaModelException e) {
e.printStackTrace();
}
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
boolean allowUsageReporting = store.getBoolean(PreferenceConstants.P_ENABLE_USAGE_REPORTING);
if(allowUsageReporting) {
try {
boolean allowSourceCodeReporting = store.getBoolean(PreferenceConstants.P_ENABLE_SOURCE_CODE_REPORTING);
String content = URLEncoder.encode("project_name", "UTF-8") + "=" + URLEncoder.encode(selectedProject.getElementName(), "UTF-8");
content += "&" + URLEncoder.encode("source_class_name_1", "UTF-8") + "=" + URLEncoder.encode(instance1.getContainingClassFullyQualifiedName(), "UTF-8");
content += "&" + URLEncoder.encode("source_class_name_2", "UTF-8") + "=" + URLEncoder.encode(instance2.getContainingClassFullyQualifiedName(), "UTF-8");
content += "&" + URLEncoder.encode("source_method_name_1", "UTF-8") + "=" + URLEncoder.encode(instance1.getMethodSignature(), "UTF-8");
content += "&" + URLEncoder.encode("source_method_name_2", "UTF-8") + "=" + URLEncoder.encode(instance2.getMethodSignature(), "UTF-8");
if(allowSourceCodeReporting) {
content += "&" + URLEncoder.encode("clone_fragment_1", "UTF-8") + "=" + URLEncoder.encode(instance1.getOriginalCodeFragment(), "UTF-8");
content += "&" + URLEncoder.encode("clone_fragment_2", "UTF-8") + "=" + URLEncoder.encode(instance2.getOriginalCodeFragment(), "UTF-8");
}
content += "&" + URLEncoder.encode("application_type", "UTF-8") + "=" + URLEncoder.encode("import", "UTF-8");
content += "&" + URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(System.getProperty("user.name"), "UTF-8");
content += "&" + URLEncoder.encode("tb", "UTF-8") + "=" + URLEncoder.encode("4", "UTF-8");
URL url = new URL(Activator.RANK_URL);
URLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream printout = new DataOutputStream(urlConn.getOutputStream());
printout.writeBytes(content);
printout.flush();
printout.close();
DataInputStream input = new DataInputStream(urlConn.getInputStream());
input.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
Refactoring refactoring = new ExtractCloneRefactoring(mapper.getSubTreeMappers());
MyRefactoringWizard wizard = new MyRefactoringWizard(refactoring, null);
RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
Expand All @@ -782,7 +824,7 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
}
else {
MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), MESSAGE_DIALOG_TITLE,
"Unfortunatley, no refactoring opportunities were found.");
"Unfortunately, no refactoring opportunities were found.");
}
CompilationUnitCache.getInstance().releaseLock();
}
Expand Down

0 comments on commit 236469f

Please sign in to comment.