Skip to content

Commit

Permalink
Spartan Desktop Application (working) (kind of)
Browse files Browse the repository at this point in the history
  • Loading branch information
OriRoth committed Mar 3, 2017
1 parent 642df51 commit 3c331dc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 54 deletions.
4 changes: 0 additions & 4 deletions spartan_product.product
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<product name="Spartan Refactoring Desktop Application" uid="Spartan Product" id="il.org.spartan.plugin.product" application="il.org.spartan.spartanizer.application" version="1.0.0.0" useFeatures="true" includeLaunchers="true">


<configIni use="default">
</configIni>

Expand All @@ -14,19 +13,16 @@

<windowImages/>


<launcher>
<solaris/>
<win useIco="false">
<bmp/>
</win>
</launcher>


<vm>
</vm>


<plugins>
</plugins>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public class StatementExtractParameters<S extends Statement> extends CarefulTipp
goBlockParent((Block) s.getParent(), v, ns, r, g);
}

void goNonBlockParent(final ASTNode p, final VariableDeclarationStatement x, final Statement s, final ASTRewrite r,
void goNonBlockParent(final ASTNode p, final VariableDeclarationStatement x, final Statement statement, final ASTRewrite r,
final TextEditGroup g) {
// TODO Ori Roth: Use subject to block.
final Block b = p.getAST().newBlock();
statements(b).add(x);
statements(b).add(s);
statements(b).add(statement);
// TODO Ori Roth: Why twice?
r.replace(s, b, g);
r.replace(s, b, g);
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/il/org/spartan/plugin/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ public Plugin() {

/** Called whenever the plugin is first loaded into the workbench */
@Override public void earlyStartup() {
monitor.debug("EARLY STATRTUP: gUIBatchLaconizer");
startSpartan();
try {
monitor.debug("EARLY STATRTUP: gUIBatchLaconizer");
startSpartan();
} catch (IllegalStateException e) {
monitor.log(e);
return;
}
try {
LibrariesManagement.initializeUserLibraries();
} catch (final CoreException ¢) {
Expand All @@ -49,8 +54,13 @@ public Plugin() {
@Override public void start(final BundleContext ¢) throws Exception {
super.start(¢);
monitor.debug("START: gUIBatchLaconizer");
startSpartan();
addPartListener();
try {
startSpartan();
addPartListener();
} catch (IllegalStateException e) {
monitor.log(e);
return;
}
}
@Override public void stop(final BundleContext ¢) throws Exception {
Expand Down
39 changes: 7 additions & 32 deletions src/main/java/il/org/spartan/plugin/old/SpartanizeProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import org.eclipse.core.commands.*;
import org.eclipse.core.runtime.*;
import org.eclipse.jdt.core.*;
import org.eclipse.ui.*;
import org.eclipse.ui.progress.*;

import il.org.spartan.plugin.*;
import il.org.spartan.spartanizer.ast.navigate.*;
import il.org.spartan.spartanizer.dispatch.*;
import il.org.spartan.spartanizer.utils.*;

Expand Down Expand Up @@ -79,8 +75,6 @@ public Void go() {
+ initialCount + "\n" + "Tips after: " + $ + "\n");
}

final IWorkbench workench = PlatformUI.getWorkbench();

void manyPasses() {
for (passNumber = 1;; ++passNumber)
if (passNumber > MAX_PASSES || singlePass())
Expand All @@ -89,34 +83,15 @@ void manyPasses() {

boolean singlePass() {
final Trimmer t = new Trimmer();
final IProgressService ps = workench.getProgressService();
final Int passNum = new Int(passNumber + 1);
final AtomicBoolean $ = new AtomicBoolean(false);
try {
ps.run(true, true, pm -> {
pm.beginTask("Spartanizing project '" + javaProject.getElementName() + "' - " + "Pass " + passNum.get() + " out of maximum of " + MAX_PASSES,
todo.size());
int n = 0;
for (final ICompilationUnit ¢ : todo) {
if (pm.isCanceled()) {
$.set(true);
break;
}
pm.worked(1);
pm.subTask("Compilation unit " + wizard.nth(++n, todo) + " (" + ¢.getElementName() + ")");
if (!t.apply(¢))
done.add(¢);
}
if (!done.isEmpty())
status.append(done.size()).append(" CUs did not change; will not be processed further\n");
todo.removeAll(done);
done.clear();
pm.done();
});
} catch (final InterruptedException | InvocationTargetException ¢) {
monitor.logEvaluationError(this, ¢);
return true;
for (final ICompilationUnit ¢ : todo) {
if (!t.apply(¢))
done.add(¢);
}
if (!done.isEmpty())
status.append(done.size()).append(" CUs did not change; will not be processed further\n");
todo.removeAll(done);
done.clear();
return $.get() || todo.isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public PreferencesPage() {
addField(new ListSelectionEditor("X", "Configure tips for projects:", getFieldEditorParent(), ps,
p -> ProjectPreferencesHandler.execute((IProject) p, changes.getPreference((IProject) p), (pp, es) -> changes.update(pp, es)), //
λ -> changes.getAble((IProject) λ), //
λ -> changes.update((IProject) λ, !changes.getAble((IProject) λ).booleanValue()) //
λ -> changes.update((IProject) λ, Boolean.valueOf(!changes.getAble((IProject) λ).booleanValue())) //
));
}

Expand Down
27 changes: 16 additions & 11 deletions src/main/java/il/org/spartan/spartanizer/cmdline/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import org.eclipse.equinox.app.*;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.dom.*;

import il.org.spartan.*;
import il.org.spartan.collections.*;
import il.org.spartan.plugin.old.*;
import il.org.spartan.spartanizer.dispatch.*;
import il.org.spartan.spartanizer.java.*;
import il.org.spartan.spartanizer.utils.*;
Expand All @@ -21,7 +19,7 @@
* plug-in from the command line.
* @author Daniel Mittelman <code><mittelmania [at] gmail.com></code>
* @since 2015/09/19 */
final class Application implements IApplication {
public final class Application implements IApplication {
/** Count the number of lines in a {@link File} f
* @param ¢ File
* @return
Expand Down Expand Up @@ -102,7 +100,19 @@ private static String getPackageNameFromSource(final Wrapper<String> $, final AS
private int optRounds = 20;
private String optPath;

@Override @SuppressWarnings("OverlyComplexMethod") public Object start(final IApplicationContext arg0) {
@Override public Object start(final IApplicationContext arg0) {
Object $ = startInner(arg0);
try (Scanner s = new Scanner(System.in)) {
try {
s.nextLine();
} catch (@SuppressWarnings("unused") Exception __) {
//
}
}
return $;
}

@SuppressWarnings("OverlyComplexMethod") public Object startInner(final IApplicationContext arg0) {
if (parseArguments(as.list((String[]) arg0.getArguments().get(IApplicationContext.APPLICATION_ARGS))))
return IApplication.EXIT_OK;
try {
Expand All @@ -118,13 +128,8 @@ private static String getPackageNameFromSource(final Wrapper<String> $, final AS
try {
u = openCompilationUnit(f);
final FileStats s = new FileStats(f);
for (int i = 0; i < optRounds; ++i) {
final int n = new SpartanizeProject().countTips();
if (n == 0)
break;
s.addRoundStat(n);
for (int i = 0; i < optRounds; ++i)
new Trimmer().apply(u);
}
FileUtils.writeToFile(determineOutputFilename(f.getAbsolutePath()), u.getSource());
if (optVerbose)
System.out.println("Spartanized file " + f.getAbsolutePath());
Expand Down Expand Up @@ -280,7 +285,7 @@ private class FileStats {
linesBefore = countLines(this.file = file);
}

public void addRoundStat(final int ¢) {
@SuppressWarnings("unused") public void addRoundStat(final int ¢) {
roundStats.add(Integer.valueOf(¢));
}

Expand Down

0 comments on commit 3c331dc

Please sign in to comment.