Skip to content

2. Extractor

Timur Sağlam edited this page Feb 24, 2017 · 5 revisions

The Java Project Extractor

The Java Project Extractor is accessed through the class JavaProjectExtractor in the package eme.extractor. Its use is pretty straight forward. It offers a method buildIntermediateModel() which takes an IJavaProject as parameter (An IJavaProject can be created from an IProject with the JDT API method call JavaCore.create()). The method buildIntermediateModel() extracts all information from the Java code in the project the IJavaProject belongs to and build the intermediate model, which is then returned.

Extractor Class Diagram

The package eme.extractor contains five classes. All tasks related to the extracting of types will be delegated from the JavaProjectExtractor to the JavaTypeExtractor. The JavaTypeExtractor delegates all tasks related to the extracting of methods to the class JavaMethodExtractor. For every data type the class DataTypeExtractor is used to create the related model component (attributes, parameters, return types, throws declarations). The extracting process makes heavy use of the JDT API to analyze the Java code. Therefore, the JDTUtil class simplifies JDT functionality that is only accessable through complex interfaces or makes the code unreadable when used. The class offers simple static methods to encapsulate the problematic JDT functionality.

The extracting of the Java code and the creating of the intermediate model is executed internally in the following order:

  1. Extracting of all source packages
  2. Unifying all packages under one root package.
  3. For every package unit, for every compilation unit:
  4. Extracting of all types, which can be a:
    1. Class (Extracting methods, attributes, generic type parameters & super type references)
    2. Interface (Extracting methods, attributes, generic type parameters & super type references)
    3. Enumeration (Extracting enumerals, methods, attributes, generic type parameters & super type references)
  5. For every method: Extract parameters, return type, access level modifier, throws declarations & static/final keywords.
  6. For every attribute: Extract name, data type, access level modifier, static/final keywords and generic arguments.
  7. Pextractarsing of all external types (All resolvable types that are not types in the intermediate model from the set of data type names of the class DataTypeExtractor`).

The progress of the extracting is logged for every extracted package with its name, its number and the total number of packages. The last step is also logged.

The Data Type Extractor

To extract data types, the class DataTypeExtractor offers six methods:

  • extractField() is used to extract an IField field of an IType. Fields can be attributes and references and are modeled internally as ExtractedAttribute.

  • extractParameter() is used to extract an ILocalVariable parameter of an IMethod. Parameters are modeled internally as * ExtractedParameter.

  • extractReturnType() is used to extract a return type of an IMethod. return types are modeled internally as ExtractedDataType. You cannot use the method extractDataType() for return types, because return types can be void.

  • extractTypeParameters() is used to extract all type parameters of an IType and add them to an ExtractedType. type parameters are modeled internally as ExtractedTypeParameter.

  • extractDataType() is called by the other extracting methods and should only be called if other extracting methods of the class do not work for a data type. It is also used for the extracting of simple data types like throws declarations. These simple data types are signature strings and are modeled internally as ExtractedDataType.

  • getDataTypes returns a set of the names of all extacted data types. This is used to identify the external types.

Clone this wiki locally