use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class ErlTextHover method internalGetHoverInfo.
private static ErlangBrowserInformationControlInput internalGetHoverInfo(final AbstractErlangEditor editor, final ITextViewer textViewer, final IRegion hoverRegion) {
if (editor == null) {
return null;
}
final StringBuffer result = new StringBuffer();
OpenResult element = null;
// TODO our model is too coarse, here we need access to expressions
final Collection<OtpErlangObject> fImports = ErlangEngine.getInstance().getModelUtilService().getImportsAsList(editor.getModule());
final int offset = hoverRegion.getOffset();
final int length = hoverRegion.getLength();
final String debuggerVar = ErlTextHover.makeDebuggerVariableHover(textViewer, offset, length);
if (!debuggerVar.isEmpty()) {
result.append(debuggerVar);
}
final IErlProject erlProject = editor.getProject();
String docPath = "";
String anchor = "";
try {
if (erlProject == null) {
return null;
}
final IOtpRpc backend = BackendCore.getBuildBackend(erlProject);
if (backend == null) {
return null;
}
final IErlModel model = ErlangEngine.getInstance().getModel();
final String externalModulesString = erlProject.getProperties().getExternalModules();
final OtpErlangTuple t = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, offset, editor.getScannerName(), fImports, externalModulesString, model.getPathVars());
if (Util.isOk(t)) {
element = new OpenResult(t.elementAt(2));
final String docStr = Util.stringValue(t.elementAt(1));
result.append(docStr);
if (t.arity() > 4) {
docPath = Util.stringValue(t.elementAt(3));
anchor = Util.stringValue(t.elementAt(4));
}
} else {
element = new OpenResult(t);
final Object found = new OpenUtils().findOpenResult(editor, editor.getModule(), erlProject, element, editor.getElementAt(offset, false));
if (found instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) found;
final String comment = DocumentationFormatter.getDocumentationString(function.getComments(), function.getTypespec());
if (comment.isEmpty()) {
return null;
}
result.append(comment);
} else if (found instanceof IErlPreprocessorDef) {
final IErlPreprocessorDef preprocessorDef = (IErlPreprocessorDef) found;
result.append(preprocessorDef.getExtra());
}
}
} catch (final Exception e) {
ErlLogger.warn(e);
return null;
}
final String strResult = HoverUtil.getHTML(result);
return new ErlangBrowserInformationControlInput(null, editor, element, strResult, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class RenameModuleQuickFix method run.
@Override
public void run() throws Exception {
final IMarker marker = getMarker();
final List<String> margs = getQuickFix().getArgs();
final String moduleName = margs.get(0);
final IErlModel svc = ErlangEngine.getInstance().getModel();
IErlModule newModule;
newModule = svc.findModule(moduleName);
if (newModule != null) {
MessageDialog.openInformation(null, "Rename module quickfix", "A module with name '" + moduleName + "' already exists.");
newModule.dispose();
return;
}
final IFile file = (IFile) marker.getResource();
final IErlModule oldModule = svc.findModule(file);
if (oldModule == null) {
return;
}
String in = Util.getInputStreamAsString(file.getContents(), file.getCharset());
in = in.replaceFirst("-module\\([^)]+\\)\\.", "-module(" + moduleName + ").");
file.setContents(new ByteArrayInputStream(in.getBytes()), IResource.FORCE, null);
}
use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class ErlProject method buildStructure.
@Override
public boolean buildStructure(final IProgressMonitor pm) throws ErlModelException {
final IResource r = getCorrespondingResource();
// check whether the Erlang project can be opened
if (!(r instanceof IContainer) || !r.isAccessible()) {
ErlLogger.warn("Project %s has no resources: res:%s acc:%s cont:%s", getName(), r, r == null ? "?" : r.isAccessible(), r instanceof IContainer);
throw new ErlModelException(new ErlModelStatus(ErlModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
}
addConfigurationChangeListeners();
try {
final IContainer c = (IContainer) r;
final IResource[] elems = c.members();
final List<IErlElement> children = new ArrayList<>(elems.length + 1);
// ErlLogger.debug(">>adding externals");
addExternals(children);
// ErlLogger.debug("childcount %d", children.size());
// ErlLogger.debug(">>adding otp");
addOtpExternals(children);
// ErlLogger.debug("childcount %d", children.size());
final IErlModel model = ErlangEngine.getInstance().getModel();
for (final IResource element : elems) {
if (element instanceof IFolder) {
final IFolder folder = (IFolder) element;
final IErlFolder erlFolder = (IErlFolder) model.create(folder);
children.add(erlFolder);
} else if (element instanceof IFile) {
final IFile file = (IFile) element;
if (CommonUtils.isErlangFileContentFileName(file.getName())) {
final IErlModule m = (IErlModule) model.create(file);
children.add(m);
}
}
}
setChildren(children);
} catch (final CoreException e) {
ErlLogger.error(e);
setChildren(new ArrayList<IErlModule>());
return false;
}
return true;
}
use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class ErlideTestUtils method createModuleFromText.
public static IErlModule createModuleFromText(final String initialText) {
final IErlModel model = ErlangEngine.getInstance().getModel();
final IErlModule module = model.getModuleFromText(model, "test1", initialText, null);
ErlideTestUtils.modulesAndIncludes.add(module);
return module;
}
use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.
the class ErlideTestUtils method createModule.
public static IErlModule createModule(final String moduleName, final String moduleContents, final IFolder folder) throws CoreException {
final IFile file = ErlideTestUtils.createFile(folder.getProject(), folder.getName() + "/" + moduleName, moduleContents);
final IErlModel model = ErlangEngine.getInstance().getModel();
IErlModule module = model.findModule(file);
if (module == null) {
final IPath path = file.getLocation();
module = model.getModuleFromFile(model, file.getName(), path, Charset.defaultCharset());
}
return module;
}
Aggregations