Skip to content

Commit

Permalink
spartanizing and removing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ravivos committed Jul 1, 2017
1 parent 4bec512 commit 398566c
Show file tree
Hide file tree
Showing 334 changed files with 2,806 additions and 2,808 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class InflateHandler extends AbstractHandler {
HandlerUtil.toggleCommandState(¢.getCommand());
return goWheelAction();
}
final Selection ret = Selection.Util.current().setUseBinding();
return ret.isTextSelection ? doSingle() : goAggressiveAction(ret);
final Selection $ = Selection.Util.current().setUseBinding();
return $.isTextSelection ? doSingle() : goAggressiveAction($);
}

public static Void doSingle() {
Expand Down Expand Up @@ -74,21 +74,21 @@ public static Void goAggressiveAction(final Selection ¢) {
return null;
}
private static List<Listener> getListeners(final StyledText t) {
final List<Listener> ret = an.empty.list();
final List<Listener> $ = an.empty.list();
if (t == null)
return ret;
return $;
final List<Listener> ls = as.list(t.getListeners(SWT.KeyDown));
if (ls == null)
return ret;
ret.addAll(
return $;
$.addAll(
ls.stream().filter(λ -> λ instanceof TypedListener && ((TypedListener) λ).getEventListener() instanceof InflaterListener).collect(toList()));
return ret;
return $;
}
private static StyledText getText(final ITextEditor ¢) {
if (¢ == null)
return null;
final Control ret = ¢.getAdapter(Control.class);
return !(ret instanceof StyledText) ? null : (StyledText) ret;
final Control $ = ¢.getAdapter(Control.class);
return !($ instanceof StyledText) ? null : (StyledText) $;
}
public static GUIApplicator applicator() {
return (GUIApplicator) SpartanizationHandler.applicator(OPERATION_ACTIVITY).setRunAction(
Expand All @@ -104,9 +104,9 @@ private static IPartService getPartService() {
final IWorkbench w = PlatformUI.getWorkbench();
if (w == null)
return null;
final IWorkbenchWindow ret = w.getActiveWorkbenchWindow();
final IWorkbenchWindow $ = w.getActiveWorkbenchWindow();
final IWorkbenchWindow[] wds = w.getWorkbenchWindows();
return ret != null ? ret.getPartService() : wds != null && wds.length != 0 ? wds[0].getPartService() : null;
return $ != null ? $.getPartService() : wds != null && wds.length != 0 ? wds[0].getPartService() : null;
}
@SuppressWarnings("unused") private static IPartListener pageListener() {
return new IPartListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class InflaterListener implements KeyListener, Listener {
private static final List<Predicate<Event>> spartan_keys = Arrays.asList(λ -> λ.keyCode == SWT.KEYPAD_SUBTRACT, λ -> λ.keyCode == '-',
λ -> λ.type == SWT.MouseWheel && λ.count < 0, λ -> λ.keyCode == '[' && λ.type == SWT.KeyUp);

@SuppressWarnings("restriction") public InflaterListener(final StyledText text, final ITextEditor editor, final Selection selection) {
public InflaterListener(final StyledText text, final ITextEditor editor, final Selection selection) {
this.text = text;
this.editor = editor;
this.selection = selection;
Expand Down Expand Up @@ -163,10 +163,10 @@ public void finilize() {
deactivate();
}
public Listener find(final Iterable<Listener> ls) {
TypedListener ret = null;
TypedListener $ = null;
for (final Listener ¢ : ls)
ifinstanceof TypedListener && equals(((TypedListener) ¢).getEventListener()))
ret = (TypedListener) ¢;
return ret;
$ = (TypedListener) ¢;
return $;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ private SingleFlater() {}
* @param ¢ JD
* @return new */
public static SingleFlater in(final ASTNode ¢) {
final SingleFlater ret = new SingleFlater();
ret.root = ¢;
return ret;
final SingleFlater $ = new SingleFlater();
$.root = ¢;
return $;
}
/** Sets {@link OperationProvider} for this flater.
* @param ¢ JD
Expand Down Expand Up @@ -72,9 +72,9 @@ public SingleFlater usesDisabling(final boolean ¢) {
}
protected <N extends ASTNode> Tipper<N> getTipper(final N n) {
return robust.lyNull(() -> {
final Tipper<N> ret = operationsProvider.getTipper(n);
setTipper(ret);
return ret;
final Tipper<N> $ = operationsProvider.getTipper(n);
setTipper($);
return $;
}, λ -> note.bug(this, λ));
}
/** Main operation. Commit a single change to the {@link CompilationUnit}.
Expand Down Expand Up @@ -219,7 +219,7 @@ protected static class WindowInformation {
public int startLine;
public int endLine;

@Deprecated @SuppressWarnings("restriction") private WindowInformation(final ITextEditor e) {
@Deprecated private WindowInformation(final ITextEditor e) {
if (!(e instanceof CompilationUnitEditor)) {
invalidate();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public SingleFlaterMonitor(final SingleFlater singleFlater) {
logger.log(FINE, "Rewrite {0}", current().rewrite());
}
private String node() {
final ASTNode ret = current().node();
return String.format("%s(%s)", English.name(ret), Trivia.gist(ret));
final ASTNode $ = current().node();
return String.format("%s(%s)", English.name($), Trivia.gist($));
}
private Tip tip() {
return current().tip();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class AddModifiersToEnums extends ReplaceCurrentNode<EnumDeclaration> imp
return "add all the unecessary modifiers to the enum";
}
@Override @SuppressWarnings("unchecked") public ASTNode replacement(final EnumDeclaration ¢) {
final EnumDeclaration ret = copy.of(¢);
final EnumDeclaration $ = copy.of(¢);
if (!extract.modifiers(¢).contains(¢.getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD)))
ret.modifiers().add(¢.getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
return ret;
$.modifiers().add(¢.getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
return $;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ public class AddModifiersToMethodDeclaration extends CarefulTipper<MethodDeclara
final BodyDeclaration wrap = az.bodyDeclaration(d.getParent());
if (wrap == null)
return null;
final MethodDeclaration ret = copy.of(d);
final MethodDeclaration $ = copy.of(d);
if (iz.interface¢(wrap)) {
if (!wrap.modifiers().contains(Modifier.ABSTRACT))
ret.modifiers().add(Modifier.ABSTRACT);
$.modifiers().add(Modifier.ABSTRACT);
if (!wrap.modifiers().contains(Modifier.PUBLIC))
ret.modifiers().add(Modifier.PUBLIC);
$.modifiers().add(Modifier.PUBLIC);
} else {
if (iz.constructor(d) && iz.typeDeclaration(wrap) && !wrap.modifiers().contains(Modifier.PUBLIC) && !d.modifiers().contains(Modifier.PUBLIC))
ret.modifiers().add(Modifier.PUBLIC);
$.modifiers().add(Modifier.PUBLIC);
if (iz.final¢(wrap) && !d.modifiers().contains(Modifier.FINAL) && !iz.constructor(d))
ret.modifiers().add(ret.getAST().newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
$.modifiers().add($.getAST().newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
}
return new Tip(description(d), getClass(), d) {
@Override public void go(final ASTRewrite r, final TextEditGroup g) {
if (d.modifiers().size() != ret.modifiers().size())
r.replace(d, ret, g);
if (d.modifiers().size() != $.modifiers().size())
r.replace(d, $, g);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public class AssignmentOperatorBloater extends CarefulTipper<Assignment>//
static Expression fix(final InfixExpression x, final ITypeBinding b) {
if (!"byte".equals(b.getName()))
return x;
final CastExpression ret = x.getAST().newCastExpression();
ret.setType(x.getAST().newPrimitiveType(PrimitiveType.BYTE));
ret.setExpression(make.parethesized(x));
return ret;
final CastExpression $ = x.getAST().newCastExpression();
$.setType(x.getAST().newPrimitiveType(PrimitiveType.BYTE));
$.setExpression(make.parethesized(x));
return $;
}
private static boolean validTypes(final Assignment ¢) {
final ITypeBinding $ = left(¢).resolveTypeBinding(), br = right(¢).resolveTypeBinding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ public class AssignmentTernaryBloater extends ReplaceCurrentNode<ExpressionState
;
}
private static ASTNode innerAssignReplacement(final Expression x, final Expression left, final Operator o) {
final ConditionalExpression ret = az.conditionalExpression(core(x));
if (ret == null)
final ConditionalExpression $ = az.conditionalExpression(core(x));
if ($ == null)
return null;
final ExpressionStatement e1 = az.expressionStatement(ret.getAST().newExpressionStatement(pair(left, then(ret)).to(o)));
ExpressionStatement e2 = az.expressionStatement(ret.getAST().newExpressionStatement(pair(left, elze(ret)).to(o)));
if (wizard.eq(left, then(ret)))
return pair(e2, null).toIf(make.notOf(ret.getExpression()));
if (wizard.eq(left, elze(ret)))
final ExpressionStatement e1 = az.expressionStatement($.getAST().newExpressionStatement(pair(left, then($)).to(o)));
ExpressionStatement e2 = az.expressionStatement($.getAST().newExpressionStatement(pair(left, elze($)).to(o)));
if (wizard.eq(left, then($)))
return pair(e2, null).toIf(make.notOf($.getExpression()));
if (wizard.eq(left, elze($)))
e2 = null;
return pair(e1, e2).toIf(ret.getExpression());
return pair(e1, e2).toIf($.getExpression());
}
private static ASTNode replaceAssignment(final Statement ¢) {
final ExpressionStatement expressionStatement = az.expressionStatement(¢);
if (expressionStatement == null)
return null;
final Assignment ret = az.assignment(expressionStatement.getExpression());
return ret == null ? null : innerAssignReplacement(right(ret), left(ret), ret.getOperator());
final Assignment $ = az.assignment(expressionStatement.getExpression());
return $ == null ? null : innerAssignReplacement(right($), left($), $.getOperator());
}
@Override public ASTNode replacement(final ExpressionStatement ¢) {
return replaceAssignment(¢);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public class BooleanExpressionBloater extends CarefulTipper<InfixExpression>//
&& (isComplicated(¢.getLeftOperand()) || isComplicated(¢.getRightOperand())) && !iz.lambdaExpression(¢.getParent());
}
@Override public Tip tip(final InfixExpression ¢) {
final VariableDeclarationStatement ret = getSeperate(¢.getLeftOperand()), v2 = getSeperate(¢.getRightOperand());
final InfixExpression i = subject.pair(step.fragments(ret).get(0).getName(), step.fragments(v2).get(0).getName()).to(¢.getOperator());
final VariableDeclarationStatement $ = getSeperate(¢.getLeftOperand()), v2 = getSeperate(¢.getRightOperand());
final InfixExpression i = subject.pair(step.fragments($).get(0).getName(), step.fragments(v2).get(0).getName()).to(¢.getOperator());
return new Tip(description(¢), getClass(), ¢) {
@Override public void go(final ASTRewrite r, final TextEditGroup g) {
final ListRewrite l = r.getListRewrite(yieldAncestors.untilContainingBlock().from(¢), Block.STATEMENTS_PROPERTY);
l.insertBefore(ret, yieldAncestors.untilClass(Statement.class).from(¢), g);
l.insertAfter(v2, ret, g);
l.insertBefore($, yieldAncestors.untilClass(Statement.class).from(¢), g);
l.insertAfter(v2, $, g);
r.replace(¢, i, g);
}
};
Expand All @@ -50,9 +50,9 @@ private static VariableDeclarationStatement getSeperate(final Expression x) {
f.setInitializer(copy.of(x));
final PrimitiveType t = x.getAST().newPrimitiveType(PrimitiveType.BOOLEAN);
f.setName(make.from(x).identifier(scope.newName(x, t)));
final VariableDeclarationStatement ret = x.getAST().newVariableDeclarationStatement(f);
ret.setType(t);
return ret;
final VariableDeclarationStatement $ = x.getAST().newVariableDeclarationStatement(f);
$.setType(t);
return $;
}
@Override public String description(@SuppressWarnings("unused") final InfixExpression __) {
return "Expand boolean expression";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,26 @@ else if (ret instanceof SwitchCase) {
return null;
}
private static List<Statement> getAdditionalStatements(final List<Statement> ss, final SwitchCase c) {
final List<Statement> ret = an.empty.list();
final List<Statement> $ = an.empty.list();
boolean additionalStatements = false;
for (final Statement ¢ : ss.subList(ss.indexOf(c), ss.size())) {
ifinstanceof SwitchCase)
additionalStatements = true;
else if (additionalStatements)
ret.add(¢);
$.add(¢);
if (iz.sequencerComplex(¢))
return ret;
return $;
}
return ret;
return $;
}
static Map<String, String> getMapOldToNewNames(final List<Statement> ss) {
final Map<String, String> ret = new HashMap<>();
final Map<String, String> $ = new HashMap<>();
ss.forEach(n -> {
if (iz.variableDeclarationStatement(n))
extract.fragments(n).forEach(
λ -> ret.put(λ.getName().getIdentifier(), scope.newName(λ, az.variableDeclarationStatement(n).getType(), λ.getName().getIdentifier())));
λ -> $.put(λ.getName().getIdentifier(), scope.newName(λ, az.variableDeclarationStatement(n).getType(), λ.getName().getIdentifier())));
});
return ret;
return $;
}
static Statement replaceNames(final Statement target, final Map<String, String> m) {
target.accept(new ASTVisitor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class DeclarationWithInitializerBloater extends CarefulTipper<VariableDec
|| collect.usesOf(the.firstOf(fragments(¢)).getName()).in(¢.getParent()).stream().noneMatch(λ -> iz.switchCase(λ.getParent())));
}
@Override public Tip tip(final VariableDeclarationStatement ¢) {
final VariableDeclarationStatement ret = copy.of(¢);
((VariableDeclaration) the.firstOf(fragments(ret))).setInitializer(null);
final VariableDeclarationStatement $ = copy.of(¢);
((VariableDeclaration) the.firstOf(fragments($))).setInitializer(null);
final VariableDeclarationFragment f2 = the.firstOf(fragments(¢));
final Assignment a = subject.pair(copy.of(az.expression(f2.getName())), copy.of(az.expression(f2.getInitializer())))
.to(Assignment.Operator.ASSIGN);
Expand All @@ -48,7 +48,7 @@ public class DeclarationWithInitializerBloater extends CarefulTipper<VariableDec
final ListRewrite l = r.getListRewrite(¢.getParent(), !SwitchStatement.STATEMENTS_PROPERTY.getNodeClass().isInstance(¢.getParent())
? Block.STATEMENTS_PROPERTY : SwitchStatement.STATEMENTS_PROPERTY);
l.insertAfter(¢.getAST().newExpressionStatement(a), ¢, g);
l.insertAfter(ret, ¢, g);
l.insertAfter($, ¢, g);
l.remove(¢, g);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class IfElseToSwitch extends ReplaceCurrentNode<IfStatement>//
if (!isMyCase(xs))
return null;
final AST create = ¢.getAST();
final SwitchStatement ret = create.newSwitchStatement();
ret.setExpression(copy.of(az.simpleName(left(az.comparison(the.firstOf(xs))))));
final List<Statement> ss = statements(ret);
final SwitchStatement $ = create.newSwitchStatement();
$.setExpression(copy.of(az.simpleName(left(az.comparison(the.firstOf(xs))))));
final List<Statement> ss = statements($);
final List<Block> bs = getAllBlocks(¢);
int i = 0;
for (final Expression x : xs) {
Expand All @@ -40,13 +40,13 @@ public class IfElseToSwitch extends ReplaceCurrentNode<IfStatement>//
++i;
}
if (xs.size() == bs.size())
return ret;
return $;
final SwitchCase sc = create.newSwitchCase();
sc.setExpression(null);
ss.add(sc);
statements(bs.get(i)).forEach(λ -> ss.add(copy.of(λ)));
ss.add(create.newBreakStatement());
return ret;
return $;
}
private static boolean isMyCase(final List<Expression> xs) {
if (xs == null || xs.isEmpty() || !iz.infixEquals(the.firstOf(xs)))
Expand All @@ -68,37 +68,37 @@ private static boolean isMyCase(final List<Expression> xs) {
return true;
}
private static List<Expression> getAllExpressions(final IfStatement s) {
final List<Expression> ret = an.empty.list();
final List<Expression> $ = an.empty.list();
for (Statement p = s; iz.ifStatement(p); p = az.ifStatement(p).getElseStatement()) // TOUGH
ret.add(expression(az.ifStatement(p)));
return ret;
$.add(expression(az.ifStatement(p)));
return $;
}
private static List<Block> getAllBlocks(final IfStatement s) {
final List<Block> ret = an.empty.list();
final Statement p = addAllBlocks(s, ret);
final List<Block> $ = an.empty.list();
final Statement p = addAllBlocks(s, $);
if (p == null)
return ret;
return $;
if (iz.block(p))
ret.add(az.block(p));
$.add(az.block(p));
else {
final Block b = s.getAST().newBlock();
statements(b).add(copy.of(p));
ret.add(b);
$.add(b);
}
return ret;
return $;
}
private static Statement addAllBlocks(final IfStatement s, final Collection<Block> collectInto) {
Statement ret = s;
for (; iz.ifStatement(ret); ret = az.ifStatement(ret).getElseStatement()) {
final Statement then = copy.of(then(az.ifStatement(ret)));
Statement $ = s;
for (; iz.ifStatement($); $ = az.ifStatement($).getElseStatement()) {
final Statement then = copy.of(then(az.ifStatement($)));
Block b = az.block(then);
if (b == null) {
b = s.getAST().newBlock();
statements(b).add(az.statement(then));
}
collectInto.add(b);
}
return ret;
return $;
}
@Override public String description(final IfStatement __) {
return "Replace if-else statement with one parameter into switch-case";
Expand Down
Loading

0 comments on commit 398566c

Please sign in to comment.