use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class SimpleCodeInspectionHandler method handleLargeModulesCall.
private void handleLargeModulesCall(final IErlSelection wranglerSelection, final Shell shell) {
CodeInspectionViewsManager.hideView(CodeInspectionViewsManager.CODE_INSPECTION_VIEW, SimpleCodeInspectionHandler.LARGE_MODULES_VIEW_ID);
final InputDialog dialog = new InputDialog(shell, "Lines of a large module", "Lines of a large module:", "", new IntegerInputValidator());
final int ret = dialog.open();
if (ret == Window.CANCEL) {
return;
}
final int lines = Integer.parseInt(dialog.getValue());
final RpcResult res = WranglerBackendManager.getRefactoringBackend().callInspection("large_modules_eclipse", "ixi", lines, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
ArrayList<IErlElement> modules = new ArrayList<>();
try {
final OtpErlangObject obj = res.getValue();
final OtpErlangTuple restuple = (OtpErlangTuple) obj;
final OtpErlangAtom resindicator = (OtpErlangAtom) restuple.elementAt(0);
if ("ok".equals(resindicator.atomValue())) {
final OtpErlangList modList = (OtpErlangList) restuple.elementAt(1);
modules = createErlModuleList(modList);
} else {
final OtpErlangString s = (OtpErlangString) restuple.elementAt(1);
MessageDialog.openError(shell, "Error", s.stringValue());
return;
}
} catch (final Exception e) {
ErlLogger.error(e);
}
if (!modules.isEmpty()) {
CodeInspectionViewsManager.showErlElements("Large modules", modules, SimpleCodeInspectionHandler.LARGE_MODULES_VIEW_ID);
} else {
MessageDialog.openInformation(shell, "No result", "There is no large module with the specified parameter!");
}
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class SimpleCodeInspectionHandler method handleNonTailRecursiveCall.
private void handleNonTailRecursiveCall(final IErlSelection wranglerSelection, final Shell shell) {
CodeInspectionViewsManager.hideView(SimpleCodeInspectionHandler.NON_TAIL_RECURSIVE_VIEW_ID);
try {
final String inFile = "non_tail_recursive_servers_in_file_eclipse";
final String inProject = "non_tail_recursive_servers_in_dirs_eclipse";
final Boolean answer = MessageDialog.openQuestion(shell, "Find non tail recursive servers", "Would you like to run the scan in the whole project?");
String function = "";
RpcResult res = null;
if (!answer) {
function = inFile;
res = WranglerBackendManager.getRefactoringBackend().callInspection(function, "sxi", wranglerSelection.getFilePath(), wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
} else {
function = inProject;
res = WranglerBackendManager.getRefactoringBackend().callInspection(function, "xi", wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
}
final ArrayList<IErlElement> elements = processFunctionResult(shell, res);
if (elements == null) {
return;
}
if (!elements.isEmpty()) {
CodeInspectionViewsManager.showErlElements("Non tail recursive servers", elements, SimpleCodeInspectionHandler.NON_TAIL_RECURSIVE_VIEW_ID);
} else {
MessageDialog.openInformation(shell, "No result", "Could not found any non tail recursive server!");
}
} catch (final Exception e) {
ErlLogger.error(e);
}
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class DefaultErlangFoldingStructureProvider method computeAdditions.
private void computeAdditions(final Collection<? extends IErlElement> elements, final Map<ErlangProjectionAnnotation, Position> map) throws ErlModelException {
if (elements == null) {
return;
}
for (final IErlElement element : elements) {
computeAdditions(element, map);
if (element instanceof IParent) {
final IParent parent = (IParent) element;
computeAdditions(parent.getChildren(), map);
}
}
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class EditorUtility method openInEditor.
/**
* Opens an Erlang editor for an element (IErlElement, IFile, IStorage...)
*
* @return the IEditorPart or null if wrong element type or opening failed
*/
public static IEditorPart openInEditor(final Object inputElement, final boolean activate) throws PartInitException {
final IEditorInput input = EditorUtility.getEditorInput(inputElement);
if (input == null) {
return null;
}
final IEditorPart editorPart = EditorUtility.openInEditor(input, EditorUtility.getEditorID(input, inputElement), activate);
if (editorPart != null && inputElement instanceof IErlElement) {
EditorUtility.revealInEditor(editorPart, (IErlElement) inputElement);
return editorPart;
}
if (inputElement instanceof IFile) {
return EditorUtility.openInEditor((IFile) inputElement, activate);
}
return null;
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class EditorUtility method getEditorInput.
private static IEditorInput getEditorInput(final IErlElement element0) {
IErlElement element = element0;
final IResource resource = element.getResource();
if (resource instanceof IFile) {
IFile file = (IFile) resource;
file = EditorUtility.resolveFile(file);
return new FileEditorInput(file);
}
String filePath = element.getFilePath();
while (filePath == null) {
final IParent parent = element.getParent();
if (parent instanceof IErlElement) {
element = (IErlElement) parent;
filePath = element.getFilePath();
} else {
break;
}
}
if (filePath != null) {
final IPath path = new Path(filePath);
IFileStore fileStore = EFS.getLocalFileSystem().getStore(path.removeLastSegments(1));
fileStore = fileStore.getChild(path.lastSegment());
final IFileInfo fetchInfo = fileStore.fetchInfo();
if (!fetchInfo.isDirectory() && fetchInfo.exists()) {
if (element instanceof IErlModule && element.getParent() instanceof IErlExternal) {
return new ErlangExternalEditorInput(fileStore, (IErlModule) element);
}
return new FileStoreEditorInput(fileStore);
}
}
return null;
}
Aggregations