Giter Club home page Giter Club logo

jpal's Introduction

JPAL - Javaparser Aid Library

build status Download

Jpal is a library for javaparser which provides additional features like cross referencing, qualified types, symbol solving and other useful classes.

Development on GitLab: https://gitlab.com/arturbosch/JPAL Mirror on GitHub: https://github.com/arturbosch/JPAL

Table of contents

  1. Build
  2. Cross Referencing
  3. Symbol solving
  4. Helpers
  5. FAQ
  6. Contribute
  7. Who uses JPAL

Bintray

For Gradle use:

repositories {
    maven {
        url  "http://dl.bintray.com/arturbosch/generic" 
    }
}

compile 'io.gitlab.arturbosch.jpal:jpal:1.0.RC3'

For Maven see https://bintray.com/arturbosch/generic/JPAL -> SetUp

<dependency>
  <groupId>io.gitlab.arturbosch.jpal</groupId>
  <artifactId>jpal</artifactId>
  <version>1.0.RC3</version>
</dependency>

Raw

  • Make sure gradle is installed
  • Download the jpal git repository
  • Use gradle clean build publishToMavenLocal
  • This will install the library into your local m2 folder

Is provided by type resolving and caching of qualified types, paths and compilation units via a CompilationStorage.

CompilationStorage

Should be used before you process the AST as the compilation storage analyzes given project path and caches all compilation units. Compilation units are wrapped into CompilationInfo's which stores additional information like used qualified types within this unit.

CompilationStorage storage = JPAL.new(projectPath)

Obtaining a compilation info can be done through two methods:

def maybeInfo = CompilationStorage.getCompilationInfo(path)
def maybeInfo = CompilationStorage.getCompilationInfo(qualifiedType)
Updating the CompilationStorage

UpdatableCompilationStorage storage = JPAL.updatable()

This creates a new empty updatable storage instance.

UpdatableCompilationStorage storage = JPAL.initializedUpdatable(projectPath)

This creates a precompiled storage with all java sub paths down from project path. All methods of CompilationStorage to retrieve CompilationInfo work also on updatable storages.

Use methods following methods to update the storage:

storage.updateCompilationInfo(List<Path> paths)
storage.relocateCompilationInfo(Map<Path, Path> relocates)
storage.removeCompilationInfo(List<Path> paths)

QualifiedType

The easiest way to obtain a qualified type is to use the Resolver:

ClassOrInterfaceDeclaration clazz = ...;
`Optional<QualifiedType> maybeType = TypeHelper.getQualifiedType(clazz);

This has the advantage that only a class or interface declaration is needed but costs extra time finding the declared compilation unit.

If the compilation unit is known or you are sure that the class is within a specific package, use:

QualifiedType type = TypeHelper.getQualifiedType(ClassOrInterfaceDeclaration n, CompilationUnit unit)
QualifiedType type = TypeHelper.getQualifiedTypeFromPackage(TypeDeclaration n, PackageDeclaration packageDeclaration)

The preferred way is to use a Resolver.

Resolver

If you want the qualified type but only have a Type or any subclass use the Resolver and CompilationInfo classes.

CompilationStorage storage = JPAL.new(projectPath)
Resolver resolver = new Resolver(storage)
CompilationInfo info = storage.getCompilationInfo(myPath/myType)
ClassOrInterfaceType searchedType = ...
resolver.resolveType(seachedType, info)

The resolver checks for following situations:

  • Type is a primitive or boxed primitive
  • Type is in the imports and can be easily constructed
  • Type is in within an asterisk import
  • Type is in java.lang
  • Type is within the package

SimpleName classes of javaparser are treated as symbols. A Resolver can resolve symbols and find the type and declaration of a symbol.

CompilationStorage storage = JPAL.new(projectPath)
Resolver resolver = new Resolver(storage)
CompilationInfo info = storage.getCompilationInfo(myPath/myType)
resolver.resolveSymbol(symbol,info)
  • ClassHelper - signatures, scope check etc
  • LocaleVariableHelper - finds locale variable within a method
  • MethodHelper - getter/setter/anonymous method checks etc
  • NodeHelper - find (declaring) nodes
  • TypeHelper - get qualified types
  • VariableHelper - transforms parameters/fields/locale vars to JpalVariables

How to create qualified types for inner classes?

If you use the CompilationStorage with a CompilationUnit, you can get all inner classes with info.getInnerClasses().

How to get all inner classes names

TypeHelper.getQualifiedTypesOfInnerClasses(CompilationUnit unit)

How to create a type signature?

ClassHelper.createFullSignature(ClassOrInterfaceDeclaration n)

This creates a full signature of given class with respect to anonymous or inner class checks.

If these checks are not needed use:

ClassHelper.createSignature(ClassOrInterfaceDeclaration n)

What information is stored within a CompilationInfo?

final QualifiedType qualifiedType
final CompilationUnit unit
final Path path
final TypeDeclaration mainType
final ResolutionData data
final Map<QualifiedType, TypeDeclaration> innerClasses
  • Report Bugs or make feature requests through issues
  • Push merge requests

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.