use of spoon.reflect.declaration.CtModule in project spoon by INRIA.
the class ModuleFactory method getOrCreate.
public CtModule getOrCreate(String moduleName) {
if (moduleName == null || moduleName.isEmpty()) {
return getUnnamedModule();
}
CtModule ctModule = getUnnamedModule().getModule(moduleName);
if (ctModule == null) {
ctModule = factory.Core().createModule().setSimpleName(moduleName);
ctModule.setRootPackage(new CtModelImpl.CtRootPackage());
ctModule.setParent(getUnnamedModule());
}
return ctModule;
}
use of spoon.reflect.declaration.CtModule in project spoon by INRIA.
the class CompilationUnitFactory method getOrCreate.
public CompilationUnit getOrCreate(CtType type) {
if (type == null) {
return null;
}
if (type.getPosition() != null && type.getPosition().getCompilationUnit() != null) {
return type.getPosition().getCompilationUnit();
}
if (type.isTopLevel()) {
CtModule module;
if (type.getPackage() != null && factory.getEnvironment().getComplianceLevel() > 8) {
module = type.getPackage().getParent(CtModule.class);
} else {
module = null;
}
File file = this.factory.getEnvironment().getOutputDestinationHandler().getOutputPath(module, type.getPackage(), type).toFile();
try {
String path = file.getCanonicalPath();
CompilationUnit result = this.getOrCreate(path);
result.setDeclaredPackage(type.getPackage());
result.addDeclaredType(type);
type.setPosition(this.factory.createPartialSourcePosition(result));
return result;
} catch (IOException e) {
throw new SpoonException("Cannot get path for file: " + file.getAbsolutePath(), e);
}
} else {
return getOrCreate(type.getTopLevelType());
}
}
use of spoon.reflect.declaration.CtModule in project spoon by INRIA.
the class CompilationUnitFactory method getOrCreate.
public CompilationUnit getOrCreate(CtPackage ctPackage) {
if (ctPackage.getPosition() != null && ctPackage.getPosition().getCompilationUnit() != null) {
return ctPackage.getPosition().getCompilationUnit();
} else {
CtModule module;
if (factory.getEnvironment().getComplianceLevel() > 8) {
module = ctPackage.getParent(CtModule.class);
} else {
module = null;
}
File file = this.factory.getEnvironment().getOutputDestinationHandler().getOutputPath(module, ctPackage, null).toFile();
try {
String path = file.getCanonicalPath();
CompilationUnit result = this.getOrCreate(path);
result.setDeclaredPackage(ctPackage);
ctPackage.setPosition(this.factory.createPartialSourcePosition(result));
return result;
} catch (IOException e) {
throw new SpoonException("Cannot get path for file: " + file.getAbsolutePath(), e);
}
}
}
use of spoon.reflect.declaration.CtModule in project spoon by INRIA.
the class JDTTreeBuilder method visit.
@Override
public boolean visit(ModuleDeclaration moduleDeclaration, CompilationUnitScope scope) {
CtModule module = getHelper().createModule(moduleDeclaration);
context.compilationUnitSpoon.setDeclaredModule(module);
return true;
}
use of spoon.reflect.declaration.CtModule in project spoon by INRIA.
the class JDTTreeBuilderHelper method createModule.
/**
* Creates an entire object CtModule from a module declaration.
* @return a CtModule
*/
CtModule createModule(ModuleDeclaration moduleDeclaration) {
CtModule module = jdtTreeBuilder.getFactory().Module().getOrCreate(new String(moduleDeclaration.moduleName));
module.setIsOpenModule(moduleDeclaration.isOpen());
jdtTreeBuilder.getContextBuilder().enter(module, moduleDeclaration);
if (moduleDeclaration.requires != null && moduleDeclaration.requires.length > 0) {
List<CtModuleRequirement> moduleRequirements = new ArrayList<>();
for (RequiresStatement requiresStatement : moduleDeclaration.requires) {
moduleRequirements.add(this.createModuleRequirement(requiresStatement));
}
module.setRequiredModules(moduleRequirements);
}
if (moduleDeclaration.exports != null && moduleDeclaration.exports.length > 0) {
List<CtPackageExport> moduleExports = new ArrayList<>();
for (ExportsStatement exportsStatement : moduleDeclaration.exports) {
moduleExports.add(this.createModuleExport(exportsStatement));
}
module.setExportedPackages(moduleExports);
}
if (moduleDeclaration.opens != null && moduleDeclaration.opens.length > 0) {
List<CtPackageExport> moduleOpens = new ArrayList<>();
for (OpensStatement opensStatement : moduleDeclaration.opens) {
moduleOpens.add(this.createModuleExport(opensStatement));
}
module.setOpenedPackages(moduleOpens);
}
if (moduleDeclaration.uses != null && moduleDeclaration.uses.length > 0) {
List<CtUsedService> consumedServices = new ArrayList<>();
for (UsesStatement consumedService : moduleDeclaration.uses) {
consumedServices.add(this.createUsedService(consumedService));
}
module.setUsedServices(consumedServices);
}
if (moduleDeclaration.services != null && moduleDeclaration.services.length > 0) {
List<CtProvidedService> moduleProvidedServices = new ArrayList<>();
for (ProvidesStatement providesStatement : moduleDeclaration.services) {
moduleProvidedServices.add(this.createModuleProvidedService(providesStatement));
}
module.setProvidedServices(moduleProvidedServices);
}
module.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPosition(moduleDeclaration.declarationSourceStart, moduleDeclaration.declarationSourceEnd));
return module;
}
Aggregations