-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from ponder-lab/31-create-evaluation-plug-in2
Create evaluation plug-in
- Loading branch information
Showing
24 changed files
with
702 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 145 additions & 2 deletions
147
edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/utils/Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,161 @@ | ||
package edu.cuny.hunter.hybridize.core.utils; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.eclipse.core.runtime.Platform.getLog; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.eclipse.core.commands.ExecutionException; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.ILog; | ||
import org.eclipse.jface.text.Document; | ||
import org.eclipse.jface.text.IDocument; | ||
import org.eclipse.ltk.core.refactoring.Refactoring; | ||
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring; | ||
import org.python.pydev.ast.refactoring.TooManyMatchesException; | ||
import org.python.pydev.core.IPythonNature; | ||
import org.python.pydev.navigator.PythonModelProvider; | ||
import org.python.pydev.navigator.elements.PythonFile; | ||
import org.python.pydev.navigator.elements.PythonNode; | ||
import org.python.pydev.navigator.elements.PythonSourceFolder; | ||
import org.python.pydev.outline.ParsedItem; | ||
import org.python.pydev.parser.jython.SimpleNode; | ||
import org.python.pydev.parser.jython.ast.FunctionDef; | ||
import org.python.pydev.parser.visitors.scope.ASTEntryWithChildren; | ||
import org.python.pydev.plugin.nature.PythonNature; | ||
|
||
import edu.cuny.hunter.hybridize.core.analysis.FunctionDefinition; | ||
import edu.cuny.hunter.hybridize.core.analysis.FunctionExtractor; | ||
import edu.cuny.hunter.hybridize.core.refactorings.HybridizeFunctionRefactoringProcessor; | ||
|
||
public class Util { | ||
|
||
private static final ILog LOG = getLog(Util.class); | ||
|
||
private static final PythonModelProvider provider = new PythonModelProvider(); | ||
|
||
public static Refactoring createRefactoring(Set<FunctionDefinition> functionDefinitions) throws TooManyMatchesException { | ||
HybridizeFunctionRefactoringProcessor processor = new HybridizeFunctionRefactoringProcessor(functionDefinitions); | ||
return new ProcessorBasedRefactoring(processor); | ||
return new ProcessorBasedRefactoring(new HybridizeFunctionRefactoringProcessor(functionDefinitions)); | ||
} | ||
|
||
public static HybridizeFunctionRefactoringProcessor createHybridizeFunctionRefactoring(IProject[] projects) | ||
throws ExecutionException, CoreException, IOException { | ||
Set<FunctionDefinition> functionDefinitions = getFunctionDefinitions(Arrays.asList(projects)); | ||
return new HybridizeFunctionRefactoringProcessor(functionDefinitions); | ||
} | ||
|
||
public static Set<FunctionDefinition> getFunctionDefinitions(Iterable<?> iterable) | ||
throws ExecutionException, CoreException, IOException { | ||
Set<FunctionDefinition> ret = new HashSet<>(); | ||
|
||
for (Object obj : iterable) { | ||
Set<PythonNode> nodeSet = getPythonNodes(obj); | ||
|
||
for (PythonNode node : nodeSet) | ||
ret.addAll(process(node)); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
public static Set<PythonNode> getPythonNodes(Object obj) { | ||
Set<PythonNode> ret = new HashSet<>(); | ||
|
||
if (obj instanceof PythonNode) { | ||
PythonNode pythonNode = (PythonNode) obj; | ||
ret.add(pythonNode); | ||
} else { | ||
Object[] children = provider.getChildren(obj); | ||
for (Object child : children) | ||
ret.addAll(getPythonNodes(child)); | ||
} | ||
return ret; | ||
} | ||
|
||
public static Set<FunctionDefinition> process(PythonNode pythonNode) throws ExecutionException, CoreException, IOException { | ||
Set<FunctionDefinition> ret = new HashSet<>(); | ||
|
||
String moduleName = getModuleName(pythonNode); | ||
File file = getFile(pythonNode); | ||
IDocument document = getDocument(pythonNode); | ||
IPythonNature nature = Util.getPythonNature(pythonNode); | ||
|
||
ParsedItem entry = pythonNode.entry; | ||
ASTEntryWithChildren ast = entry.getAstThis(); | ||
SimpleNode simpleNode = ast.node; | ||
|
||
// extract function definitions. | ||
FunctionExtractor functionExtractor = new FunctionExtractor(); | ||
try { | ||
simpleNode.accept(functionExtractor); | ||
} catch (Exception e) { | ||
LOG.error("Failed to start refactoring.", e); | ||
throw new ExecutionException("Failed to start refactoring.", e); | ||
} | ||
|
||
Collection<FunctionDef> definitions = functionExtractor.getDefinitions(); | ||
|
||
for (FunctionDef def : definitions) { | ||
FunctionDefinition function = new FunctionDefinition(def, moduleName, file, document, nature); | ||
ret.add(function); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
private static IFile getActualFile(PythonNode pythonNode) { | ||
PythonFile pythonFile = pythonNode.getPythonFile(); | ||
return pythonFile.getActualObject(); | ||
} | ||
|
||
static IDocument getDocument(PythonNode pythonNode) throws CoreException, IOException { | ||
IFile file = getActualFile(pythonNode); | ||
|
||
try (InputStream contentStream = file.getContents()) { | ||
byte[] bytes = contentStream.readAllBytes(); | ||
String content = new String(bytes, UTF_8); | ||
return new Document(content); | ||
} | ||
} | ||
|
||
static File getFile(PythonNode pythonNode) { | ||
IFile file = getActualFile(pythonNode); | ||
URI uri = file.getRawLocationURI(); | ||
return new File(uri); | ||
} | ||
|
||
static String getFileName(PythonNode pythonNode) { | ||
IFile file = getActualFile(pythonNode); | ||
return file.getName(); | ||
} | ||
|
||
static String getModuleName(PythonNode pythonNode) { | ||
String fileName = getFileName(pythonNode); | ||
int separatorPos = fileName.indexOf('.'); | ||
return fileName.substring(0, separatorPos); | ||
} | ||
|
||
static IPythonNature getPythonNature(PythonNode pythonNode) { | ||
IProject project = getProject(pythonNode); | ||
PythonNature pythonNature = PythonNature.getPythonNature(project); | ||
return pythonNature; | ||
} | ||
|
||
private static IProject getProject(PythonNode pythonNode) { | ||
PythonFile pythonFile = pythonNode.getPythonFile(); | ||
PythonSourceFolder sourceFolder = pythonFile.getSourceFolder(); | ||
IResource resource = sourceFolder.getActualObject(); | ||
IProject project = resource.getProject(); | ||
return project; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>edu.cuny.hunter.hybridize.eval</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
2 changes: 2 additions & 0 deletions
2
edu.cuny.hunter.hybridize.eval/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
9 changes: 9 additions & 0 deletions
9
edu.cuny.hunter.hybridize.eval/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 | ||
org.eclipse.jdt.core.compiler.compliance=11 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=11 |
4 changes: 4 additions & 0 deletions
4
edu.cuny.hunter.hybridize.eval/.settings/org.eclipse.m2e.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: %Bundle-Name | ||
Bundle-SymbolicName: edu.cuny.hunter.hybridize.eval;singleton:=true | ||
Bundle-Vendor: %Bundle-Vendor | ||
Bundle-Version: 1.0.0.qualifier | ||
Import-Package: com.google.common.collect, | ||
org.python.pydev.parser.jython.ast, | ||
org.python.pydev.plugin.nature | ||
Require-Bundle: org.eclipse.ui, | ||
org.eclipse.core.runtime;bundle-version="3.26.0", | ||
org.eclipse.core.resources;bundle-version="3.18.0", | ||
org.python.pydev;bundle-version="[9.3.2,10.0.0)", | ||
edu.cuny.citytech.refactoring.common.eval;bundle-version="3.3.0", | ||
edu.cuny.citytech.refactoring.common.core;bundle-version="3.3.0", | ||
edu.cuny.hunter.hybridize.core;bundle-version="1.0.0", | ||
org.eclipse.ltk.core.refactoring | ||
Automatic-Module-Name: edu.cuny.hunter.hybridize.eval | ||
Bundle-Activator: edu.cuny.hunter.hybridize.eval.ui.plugins.EvaluateHybridizeFunctionRefactoringPlugin | ||
Bundle-RequiredExecutionEnvironment: JavaSE-11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source.. = src/ | ||
output.. = target/classes/ | ||
bin.includes = plugin.xml,\ | ||
META-INF/,\ | ||
.,\ | ||
icons/,\ | ||
bundle.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Bundle-Vendor = City University of New York (CUNY) Hunter College | ||
Bundle-Name = Eclipse Hybridize Functions Refactoring Evaluation Plug-in |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.