Skip to content

Commit

Permalink
Merge pull request #55 from AyechiNour/refact_NA
Browse files Browse the repository at this point in the history
Refactorisation des fonctions d'analyse
  • Loading branch information
fuhrmanator authored May 26, 2024
2 parents a066c82 + 25fb88f commit 74d8d55
Show file tree
Hide file tree
Showing 18 changed files with 2,066 additions and 1,815 deletions.
76 changes: 32 additions & 44 deletions src/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { Project } from "ts-morph";
import * as fs from 'fs';
import { FamixRepository } from "./lib/famix/src/famix_repository";
import * as FamixFunctions from "./famix_functions/famix_object_creator";
import { ProcessFiles } from "./analyze_functions/processFiles";
import { ProcessAccesses } from "./analyze_functions/processAccesses";
import { ProcessInvocations } from "./analyze_functions/processInvocations";
import { ProcessInheritances } from "./analyze_functions/processInheritances";
import { ProcessImportClauses } from "./analyze_functions/processImportClauses";

import { Logger } from "tslog";
import * as processFunctions from "./analyze_functions/process_functions";
import { EntityDictionary } from "./famix_functions/EntityDictionary";
import path from "path";

export const logger = new Logger({ name: "ts2famix", minLevel: 3});
export const config = { "expectGraphemes": false };
export const entityDictionary = new EntityDictionary();

/**
* This class is used to build a Famix model from a TypeScript source code
Expand All @@ -26,12 +22,7 @@ export class Importer {
}
}
); // The project containing the source files to analyze
private processFiles = new ProcessFiles(); // ProcessFiles object, it contains all the functions needed to process the source files
private processAccesses = new ProcessAccesses(); // ProcessAccesses object, it contains all the functions needed to process the accesses
private processInvocations = new ProcessInvocations(); // ProcessInvocations object, it contains all the functions needed to process the invocations
private processInheritances = new ProcessInheritances(); // ProcessInheritances object, it contains all the functions needed to process the inheritances
private processImportClauses = new ProcessImportClauses(); // ProcessImportClauses object, it contains all the functions needed to process the import clauses


/**
* Main method
* @param paths An array of paths to the source files to analyze
Expand All @@ -43,19 +34,11 @@ export class Importer {
logger.debug(`famixRepFromPaths: paths: ${paths}`);
this.project.addSourceFilesAtPaths(paths);

// get compiler options
const compilerOptions = this.project.getCompilerOptions();

// get baseUrl
const baseUrl = compilerOptions.baseUrl;

const absoluteBaseUrl = path.resolve(baseUrl);

FamixFunctions.famixRep.setAbsolutePath(absoluteBaseUrl);
initFamixRep(this.project);

this.processEntities(this.project);

const famixRep = FamixFunctions.famixRep;
const famixRep = entityDictionary.famixRep;
// }
// catch (error) {
// logger.error(`> ERROR: got exception ${error}. Exiting...`);
Expand All @@ -68,19 +51,19 @@ export class Importer {
}

private processEntities(project) {
this.processFiles.processFiles(project.getSourceFiles());
const accesses = this.processFiles.getAccesses();
const methodsAndFunctionsWithId = this.processFiles.getMethodsAndFunctionsWithId();
const classes = this.processFiles.getClasses();
const interfaces = this.processFiles.getInterfaces();
const modules = this.processFiles.getModules();
const exports = this.processFiles.getExports();

this.processImportClauses.processImportClausesForImportEqualsDeclarations(project.getSourceFiles(), exports);
this.processImportClauses.processImportClausesForModules(modules, exports);
this.processAccesses.processAccesses(accesses);
this.processInvocations.processInvocations(methodsAndFunctionsWithId);
this.processInheritances.processInheritances(classes, interfaces);
processFunctions.processFiles(project.getSourceFiles());
const accesses = processFunctions.accessMap;
const methodsAndFunctionsWithId = processFunctions.methodsAndFunctionsWithId;
const classes = processFunctions.classes;
const interfaces = processFunctions.interfaces;
const modules = processFunctions.modules;
const exports = processFunctions.exportedMap;

processFunctions.processImportClausesForImportEqualsDeclarations(project.getSourceFiles(), exports);
processFunctions.processImportClausesForModules(modules, exports);
processFunctions.processAccesses(accesses);
processFunctions.processInvocations(methodsAndFunctionsWithId);
processFunctions.processInheritances(classes, interfaces);
}

/**
Expand Down Expand Up @@ -110,7 +93,18 @@ export class Importer {
//const sourceFileNames = project.getSourceFiles().map(f => f.getFilePath()) as Array<string>;

//const famixRep = this.famixRepFromPaths(sourceFileNames);

initFamixRep(project);

this.processEntities(project);

return entityDictionary.famixRep;
}

}

function initFamixRep(project :Project ): void {

// get compiler options
const compilerOptions = project.getCompilerOptions();

Expand All @@ -119,11 +113,5 @@ export class Importer {

const absoluteBaseUrl = path.resolve(baseUrl);

FamixFunctions.famixRep.setAbsolutePath(path.normalize(absoluteBaseUrl));

this.processEntities(project);

return FamixFunctions.famixRep;
}

}
entityDictionary.famixRep.setAbsolutePath(path.normalize(absoluteBaseUrl));
}
48 changes: 0 additions & 48 deletions src/analyze_functions/processAccesses.ts

This file was deleted.

Loading

0 comments on commit 74d8d55

Please sign in to comment.