Git Product home page Git Product logo

javafypy's Introduction

JavaFyPy : A mechanism to adapt Java AST analysis tools to Python

Over the years, researchers have developed a solid toolset to analyse Java software systems. JavaFyPy enables adapting these tools to Python.

JavaFyPy creates a Python AST that the Java AST mining tools can process. The above diagram shows the steps of AST transformation performed by JavaFyPy.

This repositoy presents all the above tools

You can follow the following steps to adapt Java AST mining tools to Python.

  1. JPythonParser is a Python parser developed in Java. You can use the class PyASTParser to create the initial AST of the Python code content as below.

    mod ast = PyASTParser.parsePython(content);
    
  2. Then the class PythonASTUtil:createPyCompilationUnit in SyntaxtTranformer transforms the syntax and augments the AST with type information using the TypeAugmentor. You can use the type information in https://github.com/mlcodepatterns/PythonTypeInformation for type augmentation.

  3. As the next step, migrate the existing Java parser of your tool to our eclipse JDT parser provided in CustomizedEclipseJDT

Using JavaFyPy, we adapted Java RefactoringMiner and CPATMiner to Python. We provide two example usages below.

  1. Py-RefactoringMiner - click-me
  2. R-CPATMiner - click-me

javafypy's People

Contributors

maldil avatar mlcodepatterns avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

mlcodepatterns

javafypy's Issues

make super().__init__() parsable

    class Norm(base_norm_cls):

        def __init__(self, *args, **kwargs):
            ba = bound_init_signature.bind(*args, **kwargs)
            ba.apply_defaults()
            super().__init__(
                **{k: ba.arguments.pop(k) for k in ["vmin", "vmax", "clip"]})

Python nonlocal results

if more_results is not None:
                    for key, value in more_results.items():
                        all_more_results[key].extend(value)

                nonlocal results

Implement async functions, async with, await

async def run_clang_format_on_file(filename, semaphore, verbose=False):
    """
    Run clang-format on the provided file.
    """
    # -style=file picks up the closest .clang-format, -i formats the files inplace.
    cmd = "{} -style=file -i {}".format(CLANG_FORMAT_PATH, filename)
    async with semaphore:
        proc = await asyncio.create_subprocess_shell(cmd)
        _ = await proc.wait()
    if verbose:
        print("Formatted {}".format(filename))

Make the Floor division

def _synth_regression_dataset(n_samples=100000, n_features=100,
                              dtype=np.float32):
    X, y = make_regression(n_samples=n_samples, n_features=n_features,
                           n_informative=n_features // 10, noise=50,
                           random_state=0)

    X, X_val, y, y_val = train_test_split(X, y, test_size=0.1, random_state=0)
    return X, X_val, y, y_val
InfixExpression.Operator.FLOORDIV

Function calls for binary operators

def test_kernel_operator_commutative():
    # Adding kernels and multiplying kernels should be commutative.
    # Check addition
    assert_almost_equal((RBF(2.0) + 1.0)(X),
                        (1.0 + RBF(2.0))(X))

While with else

            while self._rcvd_idx < self._send_idx:
                info = self._task_info[self._rcvd_idx]
                worker_id = info[0]
                if len(info) == 2 or self._workers_status[worker_id]:  # has data or is still active
                    break
                del self._task_info[self._rcvd_idx]
                self._rcvd_idx += 1
            else:
                # no valid `self._rcvd_idx` is found (i.e., didn't break)
                if not self._persistent_workers:
                    self._shutdown_workers()
                raise StopIteration```

Yield From

        yield from self._staged_raw_predict(X)

List comprehension with conditionals

{
        key: np.asarray([score[key] for score in scores])
        if isinstance(scores[0][key], numbers.Number)
        else [score[key] for score in scores]
        for key in scores[0]
    }

for loops with Tuples

for est_idx, (name, (estimator, param_grid)) in \
        enumerate(zip(names, classifiers)):
    ax = axes[ds_cnt, est_idx + 1]

Calling returned function

res_outputs = (self._residual_fn or default_residual_fn)(inputs, outputs)
    return (res_outputs, new_state)

List comp with conditional

        if weights is None:
            y_pred = np.array([np.mean(_y[ind, :], axis=0)
                               if len(ind) else empty_obs
                               for (i, ind) in enumerate(neigh_ind)])

        else:
            y_pred = np.array([np.average(_y[ind, :], axis=0,
                               weights=weights[i])
                               if len(ind) else empty_obs
                               for (i, ind) in enumerate(neigh_ind)])

power assign

if inplace_csr_row_normalize is inplace_csr_row_normalize_l2:
                    X_csr.data **= 2

yield expression and yield from expression

    class Pop(nn.Module):
        def forward(self, input):
            foo = yield pop("foo")
            return foo # noqa
    def __iter__(self) -> Iterator[Tensor]:
        if self.atomic:
            yield self.tensor
        else:
            yield from self.tensors

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.