use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class CompilerPreferencePage method doLinkActivated.
void doLinkActivated(final Link widget) {
if (isProjectPreferencePage()) {
openWorkspacePreferences(null);
} else {
final List<IProject> erlProjects = new ArrayList<>();
final Set<IProject> projectsWithSpecifics = new HashSet<>();
final IErlModel model = ErlangEngine.getInstance().getModel();
try {
for (final IErlProject ep : model.getErlangProjects()) {
final IProject p = ep.getWorkspaceProject();
if (hasProjectSpecificOptions(p)) {
projectsWithSpecifics.add(p);
}
erlProjects.add(p);
}
} catch (final ErlModelException e) {
}
final ProjectSelectionDialog dialog = new ProjectSelectionDialog(getShell(), erlProjects, projectsWithSpecifics);
if (dialog.open() == Window.OK) {
final IProject res = (IProject) dialog.getFirstResult();
openProjectProperties(res);
}
}
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class ErlangAbstractHandler method getTextSelection.
/**
* Provide the text selection that is needed to execute the command. Default
* implementation, extend to Erlang elements selected.
*
* @param document
* text {@link IDocument}
* @param selection
* selection affected by command (extended by extendSelection)
* @return new {@link ITextSelection} with all text up to selection
*/
protected ITextSelection getTextSelection(final IDocument document, final ITextSelection selection, final ITextEditor editor) {
if (editor instanceof ErlangEditor) {
final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) editor;
final IErlModule module = erlangEditor.getModule();
if (module != null) {
final int offset1 = selection.getOffset();
final int offset2 = offset1 + selection.getLength();
try {
final IErlElement e1 = module.getElementAt(offset1);
final IErlElement e2 = module.getElementAt(offset2);
if (e1 instanceof ISourceReference) {
final ISourceReference ref1 = (ISourceReference) e1;
final ISourceRange r1 = ref1.getSourceRange();
final int offset = r1.getOffset();
int length = r1.getLength();
if (e1 == e2) {
final int docLength = document.getLength();
if (offset + length > docLength) {
length = docLength - offset;
}
return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, length));
} else if (e2 == null) {
return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, selection.getLength() + selection.getOffset() - offset));
} else if (e2 instanceof ISourceReference) {
final ISourceReference ref2 = (ISourceReference) e2;
final ISourceRange r2 = ref2.getSourceRange();
return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, r2.getOffset() - offset + r2.getLength()));
}
}
} catch (final ErlModelException e) {
}
}
}
return ErlangAbstractHandler.extendSelectionToWholeLines(document, selection);
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class ErlangExternalEditorInputFactory method createElement.
@Override
public IAdaptable createElement(final IMemento memento) {
// Get the file name.
final String externalModulePath = memento.getString(ErlangExternalEditorInputFactory.TAG_EXTERNAL_MODULE_PATH);
if (externalModulePath == null) {
return null;
}
IErlModule module;
try {
final IErlModel model = ErlangEngine.getInstance().getModel();
module = ErlangEngine.getInstance().getModelUtilService().getModuleFromExternalModulePath(model, externalModulePath);
} catch (final ErlModelException e1) {
return null;
}
if (module == null) {
return null;
}
// Get the file name.
final String uriString = memento.getString(ErlangExternalEditorInputFactory.TAG_URI);
if (uriString == null) {
return null;
}
URI uri;
try {
uri = new URI(uriString);
} catch (final URISyntaxException e) {
return null;
}
try {
return new ErlangExternalEditorInput(EFS.getStore(uri), module);
} catch (final CoreException e) {
return null;
}
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class RemoteFunctionClauseDialog method createDialogArea.
@Override
protected Control createDialogArea(final Composite parent) {
final Composite composite = (Composite) super.createDialogArea(parent);
final Tree functionClausesTree;
final Label label = new Label(composite, SWT.WRAP);
label.setText("Please select the function clause which against should fold!");
final GridData minToksData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
minToksData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(minToksData);
label.setFont(parent.getFont());
functionClausesTree = new Tree(composite, SWT.BORDER);
final GridData treeData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
treeData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
functionClausesTree.setLayoutData(treeData);
try {
final Collection<IErlModule> erlmodules = ErlangEngine.getInstance().getModelUtilService().getProject(GlobalParameters.getWranglerSelection().getErlElement()).getModules();
for (final IErlModule m : erlmodules) {
// must refresh the scanner!
m.open(null);
final TreeItem moduleName = new TreeItem(functionClausesTree, 0);
moduleName.setText(m.getModuleName());
moduleName.setData(m);
final List<IErlFunction> functions = filterFunctions(m.getChildren());
for (final IErlFunction f : functions) {
final TreeItem functionName = new TreeItem(moduleName, 0);
functionName.setText(f.getNameWithArity());
final List<IErlFunctionClause> clauses = filterClauses(f.getChildren());
functionName.setData(f);
for (final IErlFunctionClause c : clauses) {
final TreeItem clauseName = new TreeItem(functionName, 0);
clauseName.setText(String.valueOf(c.getName()));
clauseName.setData(c);
}
}
}
// listen to treeitem selection
functionClausesTree.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
}
// if a function or a function clause is selected, then
// highlight it
// and store the selection
@Override
public void widgetSelected(final SelectionEvent e) {
final TreeItem[] selectedItems = functionClausesTree.getSelection();
if (selectedItems.length > 0) {
final TreeItem treeItem = selectedItems[0];
final Object data = treeItem.getData();
if (data instanceof IErlFunctionClause) {
// enable the ok button
okButton.setEnabled(true);
// highlight
WranglerUtils.highlightSelection((IErlFunctionClause) data);
// store
functionClause = (IErlFunctionClause) data;
} else {
okButton.setEnabled(false);
}
}
}
});
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
applyDialogFont(composite);
return composite;
}
use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.
the class AddRefacHandler method checkType.
// check if the refactoring is elementary or composite
private RefacType checkType(final String callbackModule) {
try {
final IErlModule module = ErlangEngine.getInstance().getModel().findModule(callbackModule);
final ScannerService scanner = module.getScanner();
try {
module.resetAndCacheScannerAndParser(null);
} finally {
scanner.dispose();
}
for (final IErlElement el : module.getChildrenOfKind(ErlElementKind.ATTRIBUTE)) {
final IErlAttribute attr = (IErlAttribute) el;
if ("behaviour".equals(attr.getName()) || "behavior".equals(attr.getName())) {
if (attr.getValue().toString().contains("gen_refac")) {
return RefacType.ELEMENTARY;
} else if (attr.getValue().toString().contains("gen_composite_refac")) {
return RefacType.COMPOSITE;
}
}
}
return null;
} catch (final ErlModelException e) {
return null;
}
}
Aggregations