Giter VIP home page Giter VIP logo

explorer's Introduction

ExploReR

ExploReR is a tool that refactors source code to improve understandability by reordering local variable declarations.

Requirements

  • JDK8

Usage

$ java -jar path/to/ExploReR.jar [(-r <path> -s <path>... -t <path>...) | --config <path>]
    --refactored-method <method name> [-x <fqn>...] [-c <path>...] [-w <path>] [-o <path>]
    [-v | -q] [--siblings-count <num>] [--headcount <num>] [--max-generation <num>]
    [--time-limit <sec>] [--test-time-limit <sec>] [--required-solutions <num>] [--random-seed <num>]

Options

Option Description Default
-r, --root-dir Specifies the path to the root directory of the target project. It is recommended to specify the current directory after moving into the root directory of the target project, for implementation reason. Nothing
-s, --src Specifies paths to "product" source code (i.e. main, non-test code), or to directories containing them. Paths are separated with spaces. Nothing
-t, --test Specifies paths to test source code, or to directories containing them. Paths are separated with spaces. Nothing
--refactored-method Specifies the method name to be refactored. Nothing
-x, --exec-test Specifies fully qualified names of test classes executed during evaluation of variants (i.e. refactoring-candidates). Class names are separated with spaces. All test classes
-c, --cp Specifies class paths needed to build the target project. Paths are separated with spaces. Nothing
-o, --out-dir Writes patches ExploReR generated under the specified directory. Patches are outputted to a directory having a name of the execution time and date under the specified directory. A directory named kgenprog-out is created in the current directory.
-v, --verbose Be more verbose, printing DEBUG level logs. false
-q, --quiet Be more quiet, suppressing non-ERROR logs. false
--mutation-generating-count Specifies how many variants are generated in a generation by a mutation. 10
--crossover-generating-count Specifies how many variants are generated in a generation by a crossover. 10
--headcount Specifies how many variants survive in a generation. 100
--max-generation Terminates searching solutions when the specified number of generations reached. 10
--time-limit Terminates searching solutions when the specified time in seconds has passed. 60
--test-time-limit Specifies a time limit in seconds to build and test each variant. 10
--required-solutions Terminates searching solutions when the specified number of solutions are found. 1
--random-seed Specifies a random seed used by a random number generator. 0
--scope Specify the scope from which source code to be reused is selected. (PROJECT, PACKAGE, FILE). PACKAGE

explorer's People

Contributors

a3636tako avatar dependabot[bot] avatar h-matsuo avatar hnyma avatar keigo01 avatar mtj0928 avatar shinsuke-mat avatar tanimon avatar ty-v1 avatar yoshikihigo avatar

explorer's Issues

JDTASTLocation#locate の結果がズレることがある

問題は?

JDTASTLocation#locate を呼び出したときに,Location が内部で保持している ASTNode に対応するものが返ってこないことがある.

再現手順

java -jar build/libs/kGenProg-1.1.0.jar \
-r example/refactoring/SumOf1To3 \
-s example/refactoring/SumOf1To3/src/example/Sum.java \
-t example/refactoring/SumOf1To3/src/example/SumTest.java \
--refactored-method example.Sum#sum \
--max-generation 100 \
--time-limit 60 \
--mutation-generating-count 20 \
--crossover-generating-count 0 \
--headcount 10 \
--required-solutions 10 \
-v

以下のように,MoveAfterOperation 内で,Location が内部で保持している ASTNode と,locate 結果の ASTNode を表示している.
https://github.com/a-tanikd/kGenProg/blob/01b9830d87159a2317a604cc21af22c40a3b782b/src/main/java/jp/kusumotolab/kgenprog/project/jdt/MoveAfterOperation.java#L28-L29

しかし,以下のログの最終行のように,これらが一致しないことがある.

...
2019-01-30 14:22:30 [main] [INFO]  KGenProgMain - entered the era of 2nd generation.
2019-01-30 14:22:30 [main] [DEBUG] MoveAfterOperation - src : c=3;
 -> c=3;

2019-01-30 14:22:30 [main] [DEBUG] MoveAfterOperation - dest: return a + b + c;
 -> return a + b + c;

2019-01-30 14:22:30 [main] [DEBUG] MoveAfterOperation - src : int a;
 -> int a;

2019-01-30 14:22:30 [main] [DEBUG] MoveAfterOperation - dest: c=3;
 -> c=3;

2019-01-30 14:22:30 [main] [DEBUG] MoveAfterOperation - src : c=3;
 -> int a;
...

java.lang.IllegalArgumentException: Node is not inside the AST が多発する

問題は?

JDTOperation#applyjava.lang.IllegalArgumentException: Node is not inside the AST というエラーが多発する.

原因は?

発生箇所はここ.
https://github.com/a-tanikd/kGenProg/blob/ba946119fb4c19062c51baae98280f7dbc7284ba/src/main/java/jp/kusumotolab/kgenprog/project/jdt/SwapOperation.java#L26

次の条件が成り立つときに例外が発生する.

astNode.getAST() != astRewrite.getAST()

メトリクスの値が大きい Variant が選択されている

DefaultVariantSelection では Fitness がより大きい Variant を選択している.
しかし,並べ替えリファクタリングでは Fitness(= メトリクス値)が小さいものを選択したい.

Fitness がより小さい Variant を選択する VariantSelection を実装する.

VariantSelection で IllegalArgumentException が発生することがある

==================== kGenProg Configuration ====================
targetProject = example/refactoring/Foo
executionTests = []
workingDir = /var/folders/fg/bcs1pclj33j6vfjs6ljs58s00000gn/T/kgenprog-work4556390598327865833
outDir = kgenprog-out
mutationGeneratingCount = 40
crossoverGeneratingCount = 0
headcount = 30
maxGeneration = 100
timeLimit = PT30M
testTimeLimit = PT10S
requiredSolutionsCount = 10
logLevel = INFO
randomSeed = 0
scope = PACKAGE
needNotOutput = false
currentDirectory = /Users/a-tanikd/src/github.com/a-tanikd/kgenprog
================================================================
2019-01-01 19:44:01 [main] [INFO]  KGenProgMain - entered the era of 1st generation.
2019-01-01 19:44:03 [main] [INFO]  KGenProgMain - 
----------------------------------------------------------------
Elapsed time: 1 seconds
Variants: generated 40, syntax-valid 11, build-succeeded 2
Fitness: max 24.0(1), min 21.0(1), ave 22.5
----------------------------------------------------------------

2019-01-01 19:44:03 [main] [INFO]  KGenProgMain - entered the era of 2nd generation.
2019-01-01 19:44:04 [main] [INFO]  KGenProgMain - 
----------------------------------------------------------------
Elapsed time: 2 seconds
Variants: generated 40, syntax-valid 0, build-succeeded 0
Fitness: max --, min --, ave NaN
----------------------------------------------------------------

java.lang.IllegalArgumentException: Comparison method violates its general contract!
    at java.util.TimSort.mergeHi(TimSort.java:899)
    at java.util.TimSort.mergeAt(TimSort.java:516)
    at java.util.TimSort.mergeCollapse(TimSort.java:441)
    at java.util.TimSort.sort(TimSort.java:245)
    at java.util.Arrays.sort(Arrays.java:1512)
    at java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:348)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at jp.kusumotolab.kgenprog.ga.selection.AscendingVariantSelection.exec(AscendingVariantSelection.java:22)
    at jp.kusumotolab.kgenprog.Strategies.execVariantSelection(Strategies.java:76)
    at jp.kusumotolab.kgenprog.ga.variant.VariantStore.proceedNextGeneration(VariantStore.java:149)
    at jp.kusumotolab.kgenprog.KGenProgMain.run(KGenProgMain.java:116)
    at jp.kusumotolab.kgenprog.CUILauncher.launch(CUILauncher.java:58)
    at jp.kusumotolab.kgenprog.CUILauncher.main(CUILauncher.java:30)

MetricValidation の Fitness 計測でクラス以外を読み込むとバグる

Interface や Enum を読み込むとバグる

Exception in thread "main" spoon.SpoonException: parseClass only considers classes (and not interfaces and enums). Please consider using a Launcher object for more advanced usage.
	at spoon.Launcher.parseClass(Launcher.java:875)
	at jp.kusumotolab.kgenprog.ga.MetricValidation.calculateFitness(MetricValidation.java:31)

定義・参照間距離の計測方法変更

as is

各参照からその定義までの距離を計測している.

to be

各参照から,その変数の直近の状態の変化(再代入,参照しているインスタンスの状態の変化)までの距離を計測する.

ReorderingMutation の入れ替え対象候補の選択が不適切

KGenProgMain#run でこうしてる

mutation.setCandidates(initialVariant.getGeneratedSourceCode()
    .getProductAsts());

2つの問題が絡んでる

  • 入れ替え対象候補がプロジェクトの全体から選択されている
  • 初期状態のコードから入れ替え対象候補を選択している

SmellLocalizationTest のアサーションが緩い

SmellLocalizationTest#testNestedSuspiciousness でネストされた要素に対して Suspiciousness が計測されているかをテストしている.
しかし,内実は要素数をカウントしているだけ.
より厳密にテストする.

リファクタリングするメソッドを指定できるようにする

as is

プログラム全体をリファクタリングする.
どのメソッドがリファクタリングされるかは分からない.

to be

どのメソッドをリファクタリングするか指定できるようにし,それ以外のメソッドが編集されないようにする.

移動対象の変更

as is

定義までの距離が長い参照を移動対象にしている.

to be

各参照までの距離が長い定義を移動対象にする.

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.