Coder Social home page Coder Social logo

spartanrefactoring / main Goto Github PK

View Code? Open in Web Editor NEW
100.0 100.0 56.0 152.64 MB

Eclipse plugin that performs automatic refactoring of Java source code, making it shorter, more idiomatic and more readable

Home Page: https://www.spartan.org.il

Java 99.78% Shell 0.01% Python 0.07% Lex 0.13% sed 0.01%
eclipse-platform eclipse-plugin refactorings spartan-programming

main's People

Contributors

amirsagiv83 avatar annabel7 avatar aviadco avatar danabra avatar danielmittelman avatar dngreenst avatar dormaayan avatar geniashand avatar kfir-marx avatar kobybs avatar m4tt30rru avatar m4tteo avatar mdoron avatar michalcohen avatar nikitadizhur avatar nivshalmon avatar oran1248 avatar orenafek avatar orimarco avatar oriroth avatar ravivos avatar roeiraz avatar roeymaor avatar sapirbismot avatar sharonkl avatar slashertech avatar tomerr90 avatar viviansh avatar yossigil avatar yuvalsimon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

main's Issues

Remove temporary project references from the build path

Since plug-ins can't have inter-project dependencies (meaning that they depend on other projects in the workspace), convert those dependencies into Maven dependencies once the CLI and Spartan projects are deployed to Maven Central

Errors in running Spartan Plugin with latest update (on stable branch)

I am experiencing some errors that during the build of the application, namely after running "Run as application" with the latest udpate (commit 38acb5c).

The error is the following.

Errors running builder 'Spartanization Checker' on project 'mina-parent'.
Could not initialize class il.org.spartan.refactoring.spartanizations.Spartanizations.

The program throws the following Exception (taken from the console):

!MESSAGE Errors running builder 'Spartanization Checker' on project 'mina-benchmarks-common'.
!STACK 0
java.lang.ExceptionInInitializerError
at il.org.spartan.refactoring.builder.Builder.addMarkers(Builder.java:57)
at il.org.spartan.refactoring.builder.Builder.addMarkers(Builder.java:72)
at il.org.spartan.refactoring.builder.Builder.lambda$1(Builder.java:110)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:119)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:83)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:129)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:93)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:51)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:116)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:104)
at il.org.spartan.refactoring.builder.Builder.fullBuild(Builder.java:109)
at il.org.spartan.refactoring.builder.Builder.build(Builder.java:90)
at il.org.spartan.refactoring.builder.Builder.build(Builder.java:102)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:359)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:382)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.NullPointerException
at il.org.spartan.refactoring.spartanizations.Spartanizations$1.(Spartanizations.java:67)
at il.org.spartan.refactoring.spartanizations.Spartanizations.(Spartanizations.java:64)
... 34 more

When trying to enable the Spartanization suggestions (by toggling on the corresponding item on the project's menu) it throws the following Exception

java.lang.NoClassDefFoundError: il/org/spartan/Utils
at il.org.spartan.refactoring.handlers.ToggleSpartanizationHandler.enableNature(ToggleSpartanizationHandler.java:36)
at il.org.spartan.refactoring.handlers.ToggleSpartanizationHandler.toggleNature(ToggleSpartanizationHandler.java:57)
at il.org.spartan.refactoring.handlers.ToggleSpartanizationHandler.execute(ToggleSpartanizationHandler.java:44)
at il.org.spartan.refactoring.handlers.ToggleSpartanizationHandler.execute(ToggleSpartanizationHandler.java:64)
at il.org.spartan.refactoring.handlers.ToggleSpartanizationHandler.execute(ToggleSpartanizationHandler.java:1)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:295)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:252)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:234)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:493)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:486)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:799)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:675)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:659)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:592)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4481)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1329)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3819)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3430)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.ClassNotFoundException: il.org.spartan.Utils cannot be found by il.org.spartan.refactoring_2.5.0
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 50 more

It did not happen before.
If I reset to the commit 30a65bd it works fine - I choose this commit because I remember that it was working fine since then.

Configurations:

On my laptop:

Eclipse Mars.2 Release (4.5.2)
JDK version "1.8.0_91"
Ubuntu 14.04

On the workstation

Eclipse Neon 4.6.0
JDK version "1.8.0_91"
Ubuntu Mate 16.04

Refactor the spartanizations mechanism

There's currently only one functional spartanization (called Trimmer). Refactor the code by removing the old, unused classes extending spartanization, and move Trimmer to the spartanization package

New wring: change parameter name to "sent"

Similarly to changing return variable name to $, change the name a parameter
to a function with a single generic parameter to ¢

Should not apply to constructors or to setters.

Complete missing features in preferences

Complete the top two fields in the preferences, for controlling how the plugin behaves on startup and whether to apply the plugin automatically to new projects

Rethink limiting the number of chained ternary operators

We discussed this in the past, however nothing was done.

Nowadays, the plugin converts an if statement with multiples cases into a very long ternary chain, for example:

if(exp1)
    stmt1;
else if(exp2)
    stmt2;
else if(exp3)
    stmt3;
else
    stmt4;

Becomes:

exp1 ? stmt1 : exp2 ? stmt2 : exp3 ? stmt3 : stmt4;

I believe this isn't readable and makes understanding the code much harder. I believe we should limit this to at most 2 chained if-else statements (exp1 ? stmt1 : exp2 ? stmt2 : stmt3)

Wring: Change unused variable name to __

In all cases that a variable is annotated with @suppersswarnings("Unused")
change, if possible variable name to __ (double underscore).

This applies to parameters
local variables,
but not fields.

Do NOT invoke eclipse rename.

Stable Spartanization

Starting building stable spartanization. This issue contains all relevant material about the subject:

Known issues need to be solved:

Issues answered:

  • inlining into ClassInstanceCreation node (see DeclarationInitializerReturnExpression) - the new method looks for illegal parents of variable use (such as ClassInstanceCreation), which is sufficient. Maybe needed in other places - the correction is mainly in LocalInlineWithValue#canSafelyInlineInto
  • inline array initialization - not allowed (see DeclarationInitializerStatementTerminatingScope)
  • extraction of common suffix with undefined variables - changed IfBarFooElseBazFoo#make = added a visit of the common suffix to check for variables definitions in prefix, using Collect.definitionsOf (that I made for this purpose)
  • safer BlockSimplify wring - checks for duplicate variables declarations, see BlockSimplify#safeBlockSimplification
  • two assignments same value different types (such as int x;double y;x=0;y=0;) - disabled the option for NumberLiteral assignments (cannot be resolved without binding resolution)
  • No if to ternary conversion that creates a MethodInvocation (maybe could be done better using binding)
  • Dropping of redundant brackets - recursive inspection for if-no-else for blockEssential wring in Is#blockEssential

Also new tests for stabilization, see TrimmerTest

Fixes in original code:

  • Changed Collect.forAllOccurencesExcludingDefinitions to Collect.usesOf in Wring#inlineIntoSingleton: original intention unclear
  • Is#blockEssential - replaced else statement extraction with recursive implementation Funcs#recursiveElze

Notice:

  • Disabled inlining of final variables
  • Ternary pushdown disabled for MethodInvocation

Binding in tests missing

Apparently there is no binding in TrimmerTest, although setting binding resolution to true. Needed for new, binding using wrings.

Travis build failing

Maven packaging and Travis build failing due to changes in pom file(s): SpartanRefactoring/pom.xml missing definition of parent pom, and spartan-refactoring/pom.xml contains Java1.8 declaration. I tried inserting missing definitions to pom or reverting to last version of pom.xml, but it did not work

Concrete switch bug

// ar matrica simetrine, ar teigiamai aprezta? switch (checkMatrix(A)) { case -1: { System.out.println("Duomenų matrica nėra simetrinė."); System.exit(0); } case -2: { System.out.println("Duomenų matrica nėra teigiamai aprėžta."); System.exit(0); } case 0: { System.out.println("Duomenų matrica teigiamai aprėžta ir simetrinė."); break; } }

Enable binding resolution

Create a preference that allows users to enable or disable binding resolution when building the AST, and add wrings the ability to query the preferences whether bindings are resolved or not

Switch bug

I don't think this simplification is correct:

   switch (totalNegation) {
      default:
        break;
      case 0:
        return null;
      case 1:
        if (negationLevel(es.get(0)) == 1)
          return null;
    }

Build fails in Eclipse Mars 2 with Project Lombok annotations

I am using Eclipse Mars 2 and have Lombok installed as a java agent. I installed Spartan Refactoring from the Eclipse Marketplace.

The project I am working on is a Maven multi-module.

On starting Eclipse the following error is displayed:

Errors occurred during the build.
Errors running builder 'Spartanization Checker' on project 'camel-microservices'.
Invalid string literal : >@Data<
Errors running builder 'Spartanization Checker' on project 'first-steps'.
Invalid string literal : >@Data<

As I use Lombok just about everywhere I had to uninstall the plugin

Installation instructtions

I tried installing the source following the instructions, and it simply did no matter how many times I tried, and in which fresh install I used, and permuting the order. Nothing worked. I suspect the problem lies with the fact that the package depends on itself. One of the Build commands.

Daniel, can you please check what's going on? Can you try the instructions with a fresh install?

Applying autoformatting after spartanization

We should consider adding auto-formatting (ctrl + shift + f in eclipse) to apply spartanization - there are some inaccuracies while taking care of comments and overall spartanizating, so easily arranging the code using builtin formatting will resolve all the problem + future issues.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.