Skip to content

Commit

Permalink
Spartanize and fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yossigil committed Dec 26, 2016
1 parent 2776fdf commit f1e6364
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 39 deletions.
2 changes: 2 additions & 0 deletions scrapbook.jpage
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System.getProperties();(java.util.Properties) {java.runtime.name=OpenJDK Runtime Environment, sun.boot.library.path=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64, java.vm.version=25.111-b14, java.vm.vendor=Oracle Corporation, java.vendor.url=http://java.oracle.com/, path.separator=:, java.vm.name=OpenJDK 64-Bit Server VM, file.encoding.pkg=sun.io, user.country=US, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=unknown, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/home/yogi/git/Spartanizer, java.runtime.version=1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.endorsed.dirs=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/endorsed, os.arch=amd64, java.io.tmpdir=/tmp, line.separator=
, java.vm.specification.vendor=Oracle Corporation, os.name=Linux, sun.jnu.encoding=UTF-8, java.library.path=/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib, java.specification.name=Java Platform API Specification, java.class.version=52.0, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, os.version=4.4.0-57-generic, user.home=/home/yogi, user.timezone=, java.awt.printerjob=sun.print.PSPrinterJob, file.encoding=UTF-8, java.specification.version=1.8, java.class.path=/home/yogi/eclipse/java-neon3/eclipse/configuration/org.eclipse.osgi/207/0/.cp/snippetsupport.jar, user.name=yogi, java.vm.specification.version=1.8, sun.java.command=org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain file:/home/yogi/Neon1/.metadata/.plugins/org.eclipse.core.resources/.projects/il.org.spartan.plugin/org.eclipse.jdt.debug.ui/ file:/home/yogi/.p2/pool/plugins/org.eclipse.ui_3.108.1.v20160929-1045.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.swt_3.105.2.v20161122-0613.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.swt.gtk.linux.x86_64_3.105.2.v20161122-0613.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.jface_3.12.1.v20160923-1528.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.core.commands_3.8.0.v20160316-1921.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.ui.workbench_3.108.2.v20161025-2029.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.e4.ui.workbench3_0.13.100.v20160506-0759.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.core.runtime_3.12.0.v20160606-1342.jar file:/home/yogi/.p2/pool/plugins/javax.inject_1.0.0.v20091030.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.osgi_3.11.2.v20161107-1947.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.osgi.compatibility.state_1.0.200.v20160504-1419.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.equinox.common_3.8.0.v20160509-1230.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.core.jobs_3.8.0.v20160509-0411.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.equinox.registry_3.6.100.v20160223-2218.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.equinox.preferences_3.6.1.v20160815-1406.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.core.contenttype_3.5.100.v20160418-1621.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.equinox.app_1.3.400.v20150715-1528.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.ltk.core.refactoring_3.7.0.v20160419-0705.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.ltk.ui.refactoring_3.8.0.v20160518-1817.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.jdt.core_3.12.2.v20161117-1814.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.jdt.compiler.apt_1.2.100.v20160418-1457.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.jdt.compiler.tool_1.1.100.v20160418-1457.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.jdt.ui_3.12.2.v20160929-0804.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.jface.text_3.11.2.v20161113-1700.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.text_3.6.0.v20160503-1849.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.core.resources_3.11.1.v20161107-2032.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.ui.ide_3.12.2.v20161115-1450.jar file:/home/yogi/.p2/pool/plugins/org.junit_4.12.0.v201504281640/junit.jar file:/home/yogi/.p2/pool/plugins/org.hamcrest.core_1.3.0.v201303031735.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.ui.workbench.texteditor_3.10.1.v20160818-1626.jar file:/home/yogi/.p2/pool/plugins/org.eclipse.ui.views_3.8.101.v20160816-1954.jar file:/home/yogi/git/Spartanizer/target/classes/ file:/home/yogi/git/Spartanizer/lib/hamcrest-all-1.3.jar file:/home/yogi/git/Spartanizer/lib/junit-4.12.jar file:/home/yogi/git/Spartanizer/lib/mockito-all-2.0.2-beta.jar file:/home/yogi/git/Spartanizer/lib/spartan-1.2.jar file:/home/yogi/git/Spartanizer/lib/cli-1.02.jar, java.home=/usr/lib/jvm/java-8-openjdk-amd64/jre, sun.arch.data.model=64, user.language=en, java.specification.vendor=Oracle Corporation, awt.toolkit=sun.awt.X11.XToolkit, java.vm.info=mixed mode, java.version=1.8.0_111, java.ext.dirs=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext:/usr/java/packages/lib/ext, sun.boot.class.path=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jfr.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/classes, java.vendor=Oracle Corporation, file.separator=/, java.vendor.url.bug=http://bugreport.sun.com/bugreport/, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=gnome, sun.cpu.isalist=}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public class ExtractExpressionFromReturn extends CarefulTipper<ReturnStatement>
}

@Override public Tip tip(final ReturnStatement s) {
if (expression(s) == null || !iz.assignment(expression(s)))
return null;
return new Tip(description(s), s, this.getClass()) {
return expression(s) == null || !iz.assignment(expression(s)) ? null : new Tip(description(s), s, this.getClass()) {
@Override public void go(final ASTRewrite r, final TextEditGroup g) {
Assignment a = az.assignment(expression(s));
final AST create = r.getAST();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ public class ForBlockExpander extends ReplaceCurrentNode<ForStatement> implement
final Block b = $.getAST().newBlock();
b.statements().add(duplicate.of(s.getBody()));
final List<Boolean> cc = new ArrayList<>();
s.getBody().accept(new ASTVisitor() { @SuppressWarnings("boxing")
@Override public boolean visit(@SuppressWarnings("unused") Block node) {
s.getBody().accept(new ASTVisitor() { @Override
@SuppressWarnings("boxing") public boolean visit(@SuppressWarnings("unused") Block node) {
cc.add(true);
return true;
}});
if(!cc.isEmpty()) {
if(!cc.isEmpty())
return null;
}
$.setBody(b);
return $;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ public class OutlineArrayAccess extends CarefulTipper<ArrayAccess> implements Ti
}
};
}

/**[[SuppressWarningsSpartan]]*/

@Override protected boolean prerequisite(final ArrayAccess a) {
final Expression e = a.getIndex();
SimpleName $;
final ASTNode b = extract.containingStatement(a);
final Statement b = extract.containingStatement(a);
if (!iz.block(b.getParent()) || !iz.expressionStatement(b) || !iz.incrementOrDecrement(e) || iz.assignment(e))
return false;
$ = iz.prefixExpression(e) ? az.simpleName(az.prefixExpression(e)) : az.simpleName(az.postfixExpression(e));
/** [[SuppressWarningsSpartan]] */
SimpleName $ = iz.prefixExpression(e) ? az.simpleName(az.prefixExpression(e)) : az.simpleName(az.postfixExpression(e));
if ($ == null)
return false;
final Expression s = expression(az.expressionStatement(b));
return iz.assignment(s) && left(az.assignment(s)).equals(a) && iz.plainAssignment(az.assignment(s)) && !iz.containsName($, right(az.assignment(s)));
return iz.assignment(s) && left(az.assignment(s)).equals(a) && iz.plainAssignment(az.assignment(s))
&& !iz.containsName($, right(az.assignment(s)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ public class WhileBlockExpander extends ReplaceCurrentNode<WhileStatement> imple
final Block b = $.getAST().newBlock();
b.statements().add(duplicate.of(s.getBody()));
final List<Boolean> cc = new ArrayList<>();
s.getBody().accept(new ASTVisitor() { @SuppressWarnings("boxing")
@Override public boolean visit(@SuppressWarnings("unused") Block node) {
s.getBody().accept(new ASTVisitor() { @Override
@SuppressWarnings("boxing") public boolean visit(@SuppressWarnings("unused") Block node) {
cc.add(true);
return true;
}});
if(!cc.isEmpty()) {
if(!cc.isEmpty())
return null;
}
$.setBody(b);
return $;
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/il/org/spartan/spartanizer/ast/safety/iz.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ static boolean comparison(final Operator ¢) {
static boolean compilationUnit(final ASTNode ¢) {
return iz.nodeTypeEquals(¢, COMPILATION_UNIT);
}
/**@param n ASTNode that contains the identifier

/** @param n ASTNode that contains the identifier
* @param x Expression to search the identifier in it
* @return true if x contains the identifier of n
*/
* @return true if x contains the identifier of n */
static boolean containsName(final SimpleName n, final Expression x) {
return !searchDescendants.forClass(SimpleName.class).suchThat(t -> step.identifier(t).equals(step.identifier(n))).inclusiveFrom(x).isEmpty();
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/il/org/spartan/spartanizer/cmdline/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ public final Self put(final String key, final char value) {
}

/** Add a key and a <code><b>double</b><code> value to this instance
* @param key The key to be added; must not be <code><b>null</b></code>
* @param key The key to be added; must not be <code><b>null</b></code>
* @param value The value associated with the key
* @return this */
public Self put(final String key, final double value) {
return put(key, value, new FormatSpecifier[0]);
}

/** Add a key and a <code><b>double</b><code> value to this instance
*
* &#64;param key
* The key to be added; must not be <code><b>null</b></code>
*
* &#64;param key
* The key to be added; must not be <code><b>null</b></code>
* @param value The value associated with the key
* @param ss Which (if any) aggregate statistics should be produced for this
* column
Expand All @@ -106,9 +106,9 @@ public Self put(final String key, final double value, final FormatSpecifier... s
}

/** Add a key and a <code><b>double</b><code> value to this instance
*
* &#64;param key
* The key to be added; must not be <code><b>null</b></code>
*
* &#64;param key
* The key to be added; must not be <code><b>null</b></code>
* @param value The value associated with the key
* @param format How should the value be formatted
* @param ss Which (if any) aggregate statistics should be produced for this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public static void main(final String[] args)
final MethodRecord m = new MethodRecord(¢);
scope.push(m);
statementsCoverageStatistics.get(key).add(m);
final MethodDeclaration after = findFirst.methodDeclaration(wizard.ast(Wrap.Method.off(spartanalyzer.fixedPoint(Wrap.Method.on(¢ + "")))));
m.after = after;
m.after = findFirst.methodDeclaration(wizard.ast(Wrap.Method.off(spartanalyzer.fixedPoint(Wrap.Method.on(¢ + "")))));
} catch (final AssertionError __) {
___.unused(__);
}
Expand Down Expand Up @@ -96,13 +95,14 @@ private static String outputFileName() {
int totalStatementsCovered = 0;
coverageWriter.put("Project", path);
for (int i = 0; i < MAX_STATEMENTS_REPORTED; ++i)
if (statementsCoverageStatistics.containsKey(i)) {
if (!statementsCoverageStatistics.containsKey(i))
coverageWriter.put(i + "", "-");
else {
List<MethodRecord> rs = statementsCoverageStatistics.get(i);
totalStatements += i * rs.size();
totalStatementsCovered += totalStatementsCovered(rs);
coverageWriter.put(i + "", format.decimal(100 * avgCoverage(rs)));
} else
coverageWriter.put(i + "", "-");
}
coverageWriter.put("total Statements covergae %", safe.div(totalStatementsCovered, totalStatements));
coverageWriter.nl();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ private static String outputFileName() {
int totalMethodsTouched = 0;
touchedWriter.put("Project", path);
for (int i = 1; i < MAX_STATEMENTS_REPORTED; ++i)
if (statementsCoverageStatistics.containsKey(i)) {
if (!statementsCoverageStatistics.containsKey(i))
touchedWriter.put(i + "", "-");
else {
List<MethodRecord> rs = statementsCoverageStatistics.get(i);
totalMethods += rs.size();
totalMethodsTouched += totalMethodsTouched(rs);
touchedWriter.put(i + "", format.decimal(100 * fractionOfMethodsTouched(rs)));
} else
touchedWriter.put(i + "", "-");
}
touchedWriter.put("% of methods touched", safe.div(totalMethodsTouched, totalMethods));
touchedWriter.nl();
}

private static double fractionOfMethodsTouched(final List<MethodRecord> rs) {
return safe.div(totalMethodsTouched(rs), rs.size());
private static double fractionOfMethodsTouched(final List<MethodRecord> ¢) {
return safe.div(totalMethodsTouched(¢), ¢.size());
}

private static double totalMethodsTouched(final List<MethodRecord> rs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static ASTNode getCompilationUnit(final String from) {
assert rOOT != null;
final File f = new File(rOOT + from);
assert f != null;
assert f.exists(): f;
assert f.exists() : f;
final ASTNode $ = makeAST.COMPILATION_UNIT.from(f);
assert $ != null;
return $;
Expand Down

0 comments on commit f1e6364

Please sign in to comment.