use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class ErlangEditor method resetAndCacheScannerAndParser.
public void resetAndCacheScannerAndParser() {
final IErlModule module = getModule();
if (module == null) {
return;
}
resetReconciler();
try {
module.createScanner();
module.getScanner().dispose();
module.resetAndCacheScannerAndParser(getDocument().get());
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class AbstractErlContentAssistProcessor method getBefore.
String getBefore(final ITextViewer viewer, final IDocument doc, final int offset) {
try {
if (module != null) {
try {
final IErlElement element = module.getElementAt(offset);
if (element instanceof ISourceReference) {
final ISourceReference sr = (ISourceReference) element;
final int start = sr.getSourceRange().getOffset();
if (start <= offset) {
return doc.get(start, offset - start);
}
}
} catch (final ErlModelException e) {
}
}
for (int n = offset - 1; n >= 0; --n) {
final char c = doc.getChar(n);
final int type = Character.getType(c);
if (type == Character.LINE_SEPARATOR || type == Character.PARAGRAPH_SEPARATOR || type == Character.CONTROL) {
return doc.get(n + 1, offset - n - 1);
}
}
return doc.get(0, offset);
} catch (final BadLocationException e) {
ErlLogger.warn(e);
}
return "";
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class CallHierarchyAction method run.
@Override
public void run() {
if (module == null) {
return;
}
final IErlElement el = editor.getElementAt(editor.getViewer().getSelectedRange().x, false);
IErlFunction f = null;
if (el instanceof IErlFunction) {
f = (IErlFunction) el;
} else if (el instanceof IErlFunctionClause) {
f = (IErlFunction) el.getParent();
}
if (f == null) {
return;
}
String name = module.getName();
final int i = name.lastIndexOf('.');
if (i > 0) {
name = name.substring(0, i);
}
final FunctionRef ref = new FunctionRef(name, f.getFunctionName(), f.getArity());
final IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IWorkbenchPage page = dw.getActivePage();
final AsyncCaller<CallHierarchyView> ac = new AsyncCaller<CallHierarchyView>(100) {
@Override
protected CallHierarchyView prepare() {
try {
final IViewPart p = page.showView("org.erlide.ui.callhierarchy");
final CallHierarchyView cvh = p.getAdapter(CallHierarchyView.class);
if (cvh == null) {
return null;
}
cvh.setMessage("<searching... project " + ErlangEngine.getInstance().getModelUtilService().getProject(module).getName() + ">");
return cvh;
} catch (final PartInitException e) {
ErlLogger.error("could not open Call hierarchy view: ", e.getMessage());
return null;
}
}
@Override
protected RpcFuture call() throws BackendException {
final RpcFuture result = xrefService.addProject(ErlangEngine.getInstance().getModelUtilService().getProject(module));
return result;
}
@Override
protected void handleResult(final CallHierarchyView context, final RpcFuture result) {
page.activate(context);
try {
context.setRoot(ErlangEngine.getInstance().getModel().findFunction(ref));
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
}
};
ac.run();
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class IndexedErlangValue method getRecordValueString.
private String getRecordValueString(final IErlRecordDef r, final OtpErlangObject o) {
final StringBuilder b = new StringBuilder();
List<IErlElement> children;
try {
children = r.getChildren();
} catch (final ErlModelException e) {
children = IndexedErlangValue.EMPTY_LIST;
}
final OtpErlangTuple t = (OtpErlangTuple) o;
b.append(t.elementAt(0)).append("#{");
final int n = children.size();
if (n > 0) {
for (int i = 0; i < n; i++) {
final IErlRecordField field = (IErlRecordField) children.get(i);
b.append(field.getFieldName()).append('=').append(t.elementAt(i + 1).toString()).append(", ");
}
b.setLength(b.length() - 2);
}
b.append('}');
return b.toString();
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class ErlangLineBreakpoint method resetClauseHead.
protected void resetClauseHead(final int lineNumber, final IResource resource) {
clauseHead = "";
if (resource instanceof IFile) {
final IFile file = (IFile) resource;
final IErlModule m = ErlangEngine.getInstance().getModel().findModule(file);
if (m != null) {
try {
m.open(null);
final IErlElement e = m.getElementAtLine(lineNumber);
if (e instanceof IErlFunctionClause) {
final IErlFunctionClause clause = (IErlFunctionClause) e;
clauseHead = clause.getName() + clause.getHead();
}
} catch (final ErlModelException e1) {
ErlLogger.warn(e1);
}
}
}
}
Aggregations