Example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileReader getModuleDeclaration

List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileReader getModuleDeclaration

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileReader getModuleDeclaration.

Prototype

public IBinaryModule getModuleDeclaration() 

Source Link

Document

Returns the module declaration that this class file represents.

Usage

From source file:org.eclipse.m2e.jdt.internal.InternalModuleSupport.java

License:Open Source License

private static String getModuleNameFromJar(File file) {
    if (!file.isFile()) {
        return null;
    }//from  w  ww.j a  va 2 s  .  co  m
    char[] moduleName = null;
    try (ZipFile zipFile = new ZipFile(file)) {
        IModule module = null;
        ClassFileReader reader = ClassFileReader.read(zipFile, IModule.MODULE_INFO_CLASS);
        if (reader != null) {
            module = reader.getModuleDeclaration();
            if (module != null) {
                moduleName = module.name();
            }
        }
    } catch (ClassFormatException | IOException ex) {
        log.error(ex.getMessage(), ex);
    }
    if (moduleName == null) {
        moduleName = AutomaticModuleNaming.determineAutomaticModuleName(file.getAbsolutePath());
    }
    return new String(moduleName);
}