use of org.erlide.ui.editors.util.ErlangExternalEditorInput in project erlide_eclipse by erlang.
the class ErlModelUtils method getModule.
public static IErlModule getModule(final IEditorInput editorInput) throws CoreException {
if (editorInput instanceof IFileEditorInput) {
final IFileEditorInput input = (IFileEditorInput) editorInput;
final IFile file = input.getFile();
final IErlModel model = ErlangEngine.getInstance().getModel();
IErlModule module = model.findModule(file);
if (module != null) {
return module;
}
final IPath path = file.getLocation();
Charset encoding;
try {
encoding = Charset.forName(file.getCharset());
} catch (Exception e) {
encoding = Charsets.UTF_8;
}
module = model.getModuleFromFile(model, file.getName(), path, encoding);
module.setResource(file);
return module;
}
if (editorInput instanceof ErlangExternalEditorInput) {
final ErlangExternalEditorInput erlangExternalEditorInput = (ErlangExternalEditorInput) editorInput;
return erlangExternalEditorInput.getModule();
}
final String path = ErlModelUtils.getPathForInput(editorInput);
if (path == null) {
return null;
}
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule module = ErlangEngine.getInstance().getModelFindService().findModule(model, null, null, path, IErlElementLocator.Scope.ALL_PROJECTS);
if (module != null) {
return module;
}
final Charset encoding = ErlModelUtils.getEncodingForInput(editorInput);
final IPath p = new Path(path);
return ErlangEngine.getInstance().getModel().getModuleFromFile(null, p.lastSegment(), p, encoding);
}
Aggregations