Skip to content

Commit

Permalink
merging, fixing warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ravivos committed Jan 23, 2017
2 parents 779baf6 + 7e733ac commit acb57e1
Show file tree
Hide file tree
Showing 48 changed files with 334 additions and 477 deletions.
2 changes: 1 addition & 1 deletion src/main/java/il/org/spartan/bloater/DeflaterProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public DeflaterProvider(final Toolbox tb) {
}

@Override public Function<List<Operation<?>>, List<Operation<?>>> getFunction() {
return (¢) -> Collections.singletonList(¢.get(¢.size() - 1));
return (list) -> Collections.singletonList(list.get(list.size() - 1));
}
}
44 changes: 7 additions & 37 deletions src/main/java/il/org/spartan/bloater/InflaterListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.util.*;
import java.util.List;
import java.util.Map.*;
import java.util.concurrent.atomic.*;
import java.util.function.*;

Expand All @@ -24,12 +23,10 @@
public class InflaterListener implements MouseWheelListener, KeyListener {
private static final Function<Device, Color> INFLATE_COLOR = d -> new Color(d, 200, 200, 255);
private static final Function<Device, Color> DEFLATE_COLOR = d -> new Color(d, 200, 255, 200);
private static final Integer[] wheelEvents = { Integer.valueOf(SWT.MouseHorizontalWheel), Integer.valueOf(SWT.MouseVerticalWheel),
Integer.valueOf(SWT.MouseWheel) };
static final int CURSOR_IMAGE = SWT.CURSOR_CROSS;
final StyledText text;
final ITextEditor editor;
final Map<Integer, List<Listener>> externalListeners;
final List<Listener> externalListeners;
final Cursor activeCursor;
final Cursor inactiveCursor;
final Selection selection;
Expand All @@ -42,8 +39,8 @@ public InflaterListener(final StyledText text, final ITextEditor editor, final S
this.text = text;
this.editor = editor;
this.selection = selection;
externalListeners = new HashMap<>();
updateListeners(); // not needed probably
externalListeners = new ArrayList<>();
Collections.addAll(externalListeners, text.getListeners(SWT.MouseWheel));
final Display display = PlatformUI.getWorkbench().getDisplay();
activeCursor = new Cursor(display, CURSOR_IMAGE);
inactiveCursor = text.getCursor();
Expand Down Expand Up @@ -92,19 +89,17 @@ private void deflate() {
deactivate();
}

private void activate() {
@SuppressWarnings("boxing") private void activate() {
active = true;
updateListeners();
removeListeners();
InflateHandler.removeListeners(text, externalListeners, SWT.MouseWheel);
if (!text.isDisposed())
text.setCursor(activeCursor);
System.out.println(text.getListeners(SWT.MouseWheel));
}

private void deactivate() {
@SuppressWarnings("boxing") private void deactivate() {
text.setSelectionBackground(originalBackground);
active = false;
restoreListeners();
InflateHandler.addListeners(text, externalListeners, SWT.MouseWheel);
if (!text.isDisposed())
text.setCursor(inactiveCursor);
}
Expand All @@ -113,29 +108,4 @@ public void finilize() {
if (active)
deactivate();
}

private void updateListeners() {
externalListeners.clear();
for (Integer i : wheelEvents) {
List<Listener> l = new LinkedList<>();
Collections.addAll(l, text.getListeners(i.intValue()));
TypedListener tl = null;
for (Listener ¢ : l)
ifinstanceof TypedListener && this.equals(((TypedListener) ¢).getEventListener()))
tl = (TypedListener) ¢;
if (tl != null)
l.remove(tl);
externalListeners.put(i, l);
}
}

private void removeListeners() {
for (Entry<Integer, List<Listener>> ¢ : externalListeners.entrySet())
InflateHandler.removeListeners(text, ¢.getValue(), ¢.getKey());
}

private void restoreListeners() {
for (Entry<Integer, List<Listener>> ¢ : externalListeners.entrySet())
InflateHandler.addListeners(text, ¢.getValue(), ¢.getKey());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ public class ExtractExpressionFromReturn extends CarefulTipper<ReturnStatement>/
return "Extract expression from " + ¢ + " statement";
}

// TODO: Doron - I spartanized your code. --yg
@Override public Tip tip(final ReturnStatement s) {
return expression(s) == null || !iz.assignment(expression(s)) || !iz.block(s.getParent()) ? null : new Tip(description(s), s, getClass()) {
@Override public void go(final ASTRewrite r, final TextEditGroup g) {
final Assignment a = az.assignment(expression(s));
// TODO: Doron Meshulam: with class subject, you do not need to create
// new objects. It does that for you.
final ExpressionStatement exp = r.getAST().newExpressionStatement(copy.of(expression(s)));
final AST create = r.getAST();
final ExpressionStatement exp = create.newExpressionStatement(copy.of(expression(s)));
final ReturnStatement retNoExp = subject.operand(expression(exp)).toReturn();
retNoExp.setExpression(copy.of(left(a)));
final ListRewrite l = r.getListRewrite(s.getParent(), Block.STATEMENTS_PROPERTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ private static boolean isMyCase(final List<Expression> xs) {
InfixExpression px = az.comparison(xs.get(0));
if (!iz.infixEquals(px))
return false;
final SimpleName switchVariable = !iz.simpleName(left(px)) ? null : az.simpleName(left(px));
final SimpleName switchVariable = !iz.simpleName(step.left(px)) ? null : az.simpleName(step.left(px));
if (switchVariable == null)
return false;
for (final Expression e : xs) {
px = az.comparison(e);
if (!iz.infixEquals(px))
return false;
final SimpleName currName = !iz.simpleName(left(px)) ? null : az.simpleName(left(px));
final SimpleName currName = !iz.simpleName(step.left(px)) ? null : az.simpleName(step.left(px));
if (currName == null || !currName.getIdentifier().equals(switchVariable.getIdentifier()))
return false;
}
Expand All @@ -70,7 +70,7 @@ private static boolean isMyCase(final List<Expression> xs) {
private static List<Expression> getAllExpressions(final IfStatement s) {
final List<Expression> $ = new ArrayList<>();
for (Statement p = s; iz.ifStatement(p); p = az.ifStatement(p).getElseStatement()) // TOUGH
$.add(expression(az.ifStatement(p)));
$.add(step.expression(az.ifStatement(p)));
return $;
}

Expand All @@ -84,7 +84,7 @@ private static List<Block> getAllBlocks(final IfStatement s) {
return $;
}
final Block b = s.getAST().newBlock();
statements(b).add(copy.of(p));
step.statements(b).add(copy.of(p));
$.add(b);
return $;
}
Expand All @@ -96,7 +96,7 @@ private static Statement addAllBlocks(final IfStatement s, final List<Block> col
Block b = az.block(then);
if (b == null) {
b = s.getAST().newBlock();
statements(b).add(az.statement(then));
step.statements(b).add(az.statement(then));
}
collectInto.add(b);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import il.org.spartan.spartanizer.ast.safety.*;
import il.org.spartan.spartanizer.dispatch.*;
import il.org.spartan.spartanizer.engine.*;
import il.org.spartan.spartanizer.engine.nominal.*;
import il.org.spartan.spartanizer.java.namespace.*;
import il.org.spartan.spartanizer.tipping.*;
import il.org.spartan.zoomer.zoomin.expanders.*;
Expand Down Expand Up @@ -53,9 +52,9 @@ public class RenameShortNamesMethodDec extends EagerTipper<MethodDeclaration>//
for (final SingleVariableDeclaration parameter : parameters(d)) {
final SimpleName $ = parameter.getName();
assert $ != null;
if (!in($.getIdentifier(), namer.return¢, "¢", "__", "_") && $.getIdentifier().length() > 1)
if (!in($.getIdentifier(), "$", "¢", "__", "_") && $.getIdentifier().length() > 1)
continue;
if (in($.getIdentifier(), namer.return¢)) {
if (in($.getIdentifier(), "$")) {
prev.add($);
after.add(d.getAST().newSimpleName("ret"));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import il.org.spartan.spartanizer.ast.safety.*;
import il.org.spartan.spartanizer.dispatch.*;
import il.org.spartan.spartanizer.engine.*;
import il.org.spartan.spartanizer.engine.nominal.*;
import il.org.spartan.spartanizer.java.namespace.*;
import il.org.spartan.spartanizer.tipping.*;
import il.org.spartan.zoomer.zoomin.expanders.*;
Expand Down Expand Up @@ -51,9 +50,9 @@ public class RenameShortNamesVarDec extends EagerTipper<VariableDeclarationState
final List<SimpleName> prev = new ArrayList<>(), after = new ArrayList<>();
for (final Object v : az.variableDeclarationExpression(s).fragments()) {
final SimpleName $ = ((VariableDeclarationFragment) v).getName();
if (!in($.getIdentifier(), namer.return¢, "¢", "__", "_") && $.getIdentifier().length() > 1)
if (!in($.getIdentifier(), "$", "¢", "__", "_") && $.getIdentifier().length() > 1)
return null;
if (in($.getIdentifier(), namer.return¢)) {
if (in($.getIdentifier(), "$")) {
prev.add($);
after.add(s.getAST().newSimpleName("ret"));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ private static ASTNode innerThrowReplacement(final Expression x, final Statement
if (!(x instanceof ParenthesizedExpression))
¢ = az.conditionalExpression(x);
else {
// TODO: Doron - use extract.core()
final Expression unpar = expression(az.parenthesizedExpression(x));
// TODO: Doron - if you do az.conditional, you do not need to check for type.
if (!(unpar instanceof ConditionalExpression))
return null;
¢ = az.conditionalExpression(unpar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import il.org.spartan.*;
import il.org.spartan.spartanizer.ast.factory.*;
import il.org.spartan.spartanizer.ast.safety.*;
import il.org.spartan.spartanizer.engine.nominal.*;
import il.org.spartan.spartanizer.java.*;
import il.org.spartan.spartanizer.utils.*;

Expand Down Expand Up @@ -441,7 +440,7 @@ private static Expression onlyExpression(final List<Expression> $) {
}

public static SimpleName onlyName(final VariableDeclarationExpression ¢) {
return step.fragments(¢).stream().filter($ -> !iz.identifier(namer.return¢, $.getName())).map(VariableDeclaration::getName).findFirst().orElse(null);
return step.fragments(¢).stream().filter($ -> !iz.identifier("$", $.getName())).map(VariableDeclaration::getName).findFirst().orElse(null);
}

public static SimpleName onlyName(final VariableDeclarationStatement ¢) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public interface wizard {
PrefixExpression.Operator[] prefixOperators = { INCREMENT, DECREMENT, PLUS1, MINUS1, COMPLEMENT, NOT, };
PostfixExpression.Operator[] postfixOperators = { INCREMENT_POST, DECREMENT_POST };
Bool resolveBinding = Bool.valueOf(false);

static void addImport(final CompilationUnit u, final ASTRewrite r, final ImportDeclaration d) {
r.getListRewrite(u, CompilationUnit.IMPORTS_PROPERTY).insertLast(d, null);
}
Expand Down
44 changes: 22 additions & 22 deletions src/main/java/il/org/spartan/spartanizer/dispatch/Toolbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private static Toolbox emptyToolboox() {
return new Toolbox();
}

@SafeVarargs public static <N extends ASTNode> Tipper<N> findTipper(final N n, final Tipper<N>... ns) {
@SafeVarargs
public static <N extends ASTNode> Tipper<N> findTipper(final N n, final Tipper<N>... ns) {
return Arrays.asList(ns).stream().filter($ -> $.canTip(n)).findFirst().orElse(null);
}

Expand All @@ -97,9 +98,7 @@ public static Toolbox freshCopyOfAllTippers() {
new EnhancedForRedundantContinue(), //
null)//
.add(Initializer.class, new InitializerEmptyRemove()) //
.add(LambdaExpression.class, new LambdaExpressionRemoveRedundantCurlyBraces(), //
new LambdaExpressionRenameSingleParameterToCent(), //
null) //
.add(LambdaExpression.class, new LambdaExpressionRemoveRedundantCurlyBraces()) //
.add(ExpressionStatement.class, new ExpressionStatementAssertTrueFalse()) //
.add(Modifier.class, //
new ModifierRedundant(), //
Expand Down Expand Up @@ -205,14 +204,15 @@ public static Toolbox freshCopyOfAllTippers() {
new InfixConditionalCommon(), //
// new InfixIndexOfToStringContains(), // v 2.7
new SimplifyComparisionOfAdditions(), new SimplifyComparisionOfSubtractions(), //
null)//
null)
.add(MethodDeclaration.class, //
new AnnotationSort<MethodDeclaration>(), //
new AnnotationSort.ofMethod(), //
new MethodDeclarationRenameReturnToDollar(), //
new BodyDeclarationModifiersSort<>(), //
new MethodDeclarationRenameSingleParameterToCent() , //
// new MethodDeclarationConstructorMoveToInitializers(), //
new $BodyDeclarationModifiersSort.ofMethod(), //
new MethodDeclarationRenameSingleParameterToCent(), //
new MethodDeclarationConstructorMoveToInitializers(), //
// new MatchCtorParamNamesToFieldsIfAssigned(),
// v 2.7 // This is a new // tipper // #20
null)
.add(MethodInvocation.class, //
new MethodInvocationEqualsWithLiteralString(), //
Expand Down Expand Up @@ -276,36 +276,36 @@ public static Toolbox freshCopyOfAllTippers() {
new SameEvaluationConditional(), //
new TernaryBranchesAreOppositeBooleans(), //
new SameEvaluationConditional(), null) //
.add(EnumConstantDeclaration.class, new BodyDeclarationModifiersSort<>()) //
.add(EnumConstantDeclaration.class, new $BodyDeclarationModifiersSort.ofEnumConstant()) //
.add(TypeDeclaration.class, //
new BodyDeclarationModifiersSort<>(), //
new AnnotationSort<>(), //
new $BodyDeclarationModifiersSort.ofType(), //
new AnnotationSort.ofType(), //
new TypeDeclarationClassExtendsObject(), null) //
.add(EnumDeclaration.class, //
new BodyDeclarationModifiersSort<>(), //
new AnnotationSort<>(), //
new $BodyDeclarationModifiersSort.ofEnum(), //
new AnnotationSort.ofEnum(), //
null) //
.add(FieldDeclaration.class, //
new BodyDeclarationModifiersSort<>(), //
new AnnotationSort<>(), //
new $BodyDeclarationModifiersSort.ofField(), //
new AnnotationSort.ofField(), //
null) //
.add(CastExpression.class, //
new CastToDouble2Multiply1(), //
new CastToLong2Multiply1L(), //
null) //
.add(EnumConstantDeclaration.class, //
new BodyDeclarationModifiersSort<>(), //
new AnnotationSort<>(), //
new $BodyDeclarationModifiersSort.ofEnumConstant(), //
new AnnotationSort.ofEnumConstant(), //
null) //
.add(NormalAnnotation.class, //
new AnnotationDiscardValueName(), //
new AnnotationRemoveEmptyParentheses(), //
null) //
.add(AnnotationTypeDeclaration.class, new BodyDeclarationModifiersSort<>(), //
new AnnotationSort<AnnotationTypeDeclaration>(), //
.add(AnnotationTypeDeclaration.class, new $BodyDeclarationModifiersSort.ofAnnotation(), //
new AnnotationSort.ofAnnotation(), //
null)
.add(AnnotationTypeMemberDeclaration.class, new BodyDeclarationModifiersSort<>(), //
new AnnotationSort<>(), //
.add(AnnotationTypeMemberDeclaration.class, new $BodyDeclarationModifiersSort.ofAnnotationTypeMember(), //
new AnnotationSort.ofAnnotationTypeMember(), //
null)
.add(VariableDeclarationFragment.class, //
new DeclarationRedundantInitializer(), //
Expand Down
Loading

0 comments on commit acb57e1

Please sign in to comment.