Git Product home page Git Product logo

fast-java's Introduction

FAST-JAVA

CI Moose10 CI Moose11

Coverage Status Moose version Moose version

Represent the Java AST with Famix

Installation

To load the FAST-Java project, execute in a playground

Metacello new
  githubUser: 'moosetechnology' project: 'FAST-JAVA' commitish: 'v3' path: 'src';
  baseline: 'FASTJava';
  load

If you want to load the SmaCC importer with the model (create a FAST Java model from string)

Metacello new
  githubUser: 'moosetechnology' project: 'FAST-JAVA' commitish: 'v3' path: 'src';
  baseline: 'FASTJava';
  load: 'all'

Create a FAST-Java Model based on java string

Thanks to the Smacc Project it is easy to parse Java methods and classes. We used a visitor on the parsed java string to create a FAST-Java model.

If you need to create a FAST-Java model from a method or class, the easiest way is thus to perform:

JavaSmaCCProgramNodeImporterVisitor parseCodeMethodString: 'void hello() {
    // My method string
}'

Full documentation

A full documentation is available on modularmoose.org

UML

meta-model image

fast-java's People

Contributors

badetitou avatar clotildetoullec avatar enwiro avatar fuhrmanator avatar gabriel-darbord avatar isayarlu avatar nicolasanquetil avatar romaindeg avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fast-java's Issues

why two CI actions ?

two YAML files in github actions
testAndBuild.yml

on:
  push:
    branches: 
      - v*

testPR.yml :

on:
  pull_request:
    branches: 
      - v*

do we need both ?

Inccorectly parsed

We should check that we parse correctly this kind of expression

MyClass clzz = new SomeOtherClass(false, AnotherClass.this).new MyClass(args);

It looks like we only get one new expression instead of two

FASTJavaAnnotation >> expression should be a FASTJavaTypeName

#expression contains the annotation class.
ex: in @Deprecated the expression is "Deprecated"

Currently this is typed as FASTJavaVariableExpression but:

  • this is not an expression, it is a name "hard coded"
  • it is not a variable but a class name

Handle multidimensional arrays

There is currently no support for multidimensional arrays:

JavaSmaCCProgramNodeImporterVisitor new parseCodeString: 'class A{int[][] T;}'.

Inspecting the model shows a single instance of FASTJavaArrayTypeExpression with a baseType of FASTJavaIntTypeExpression, and the array's dimensions information has been lost.

I'm proposing a change to make such arrays nested.

Export does not restitue "vertical separation"

When there is a blank line in the original source code separating 2 statements, it is not there in the exported code.

Seems difficult without creating special nodes (EmptyLine) in the AST which does not seem desirable.
May be we could use source anchors to compute this ?

FASTJavaNewArray cannot represent multi-dimensional arrays of unspecified size

When an array initializer specifies the size of each dimension :

image

And when it does not :

image

As you can see, when the size is specified, a FASTJavaIntegerLiteral is added to the arguments field of the node and therefore the information is kept after parsing.
However, if the size are not specified, there is no way (unless we infer it from the children nodes? doesn't sound like a good idea) to know how many dimensions this array has.

Most other array nodes (like accesses, or type expression) are built recursively in order to represent multi-dimensionality, so maybe the same logic could be applied for initializers?

Create FASTJavaComment to hold comments

presumably:

  • block comments (/* ... */) would be attached to the node just after their position in the AST
  • line comments (// ...) would be attached to the node just before their position in the AST

FASTJava importer fails on Annotated methods

visit method calls #expression

visitAnnotation: anAnnotation
	self create: FASTJavaAnnotation from: anAnnotation.
	currentFASTEntity expression: (self clone accept: anAnnotation name).

but anAnnotation name is not an expression

FASTJavaCatchPartStatement should have a type slot

Catch statements only keep in memory the body, parameter and try owner.
However, as the parameter is a FASTJavaVariableExpression, it does not hold information on the type of the variable.

As catch statements can only have one variable, maybe simply adding a type slot (like FASTJavaVarDeclStatement for example) would do the trick.

Modifiers of FASTJavaVarDeclStatement nodes are not added for variables within methods

image

As you can see on the indicated nodes on the AST, modifiers are correctly added for class attributes, but it is not the case for the local variables of a method.

I made this example using this snippet of code :

JavaSmaCCProgramNodeImporterVisitor new parseCodeString: 
'
public class Test { 
	
	public final static String TEST_ATTRIBUTE = "bonjour";
	
	public void testMethod() { 
	
	final String testVariable = "au revoir";
	 
	} 
 
}
'

The problem was however first noticed through ASTs generated using real-world examples.

Refactor FASTJavaExportVisitor>>visitFASTJavaUnaryExpression:

In a visitor, always give priority to a visit from the children rather than a test.

In this case we could have:

FASTJavaExportVisitor >> visitFASTJavaUnaryExpression: aFASTJavaUnaryExpression
  aFASTJavaUnaryExpression isPrefixedUnaryExpression
    ifTrue: [ self visitFASTJavaPrefixedUnaryExpression: aFASTJavaUnaryExpression ]
    ifFalse: [ self visitFASTJavaPostfixedUnaryExpression: aFASTJavaUnaryExpression ]

and then trivially implement the 2 methods #visitFASTJavaPrefixedUnaryExpression and #visitFASTJavaPostfixedUnaryExpression.

The next step is to push up the implementation of FASTJavaExportVisitor>>visitFASTJavaUnaryExpression: into the abstract visitor.

-- @NicolasAnquetil regarding #23

Export indentation is not correct

mostly OK for blocks (statements inside blocks)
but when a if or a loop has only one instruction it is not indented
need to check also loop initialization and increment because they are "statements"

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.