/* * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { ErlBrowserInformationControlInput input = null; if (fInfoControl != null) { input = (ErlBrowserInformationControlInput) fInfoControl.getInput(); fInfoControl.notifyDelayedInputChange(null); fInfoControl.dispose(); } else if (edocView != null) { input = edocView.getInput(); } if (input != null) { // TODO: add hover location to editor navigation history? try { final Object element = input.getInputElement(); if (element instanceof IErlElement) { EditorUtility.openElementInEditor(element, true); } else if (element instanceof OpenResult) { final OpenResult or = (OpenResult) element; try { final AbstractErlangEditor editor = input.getEditor(); new OpenUtils().openOpenResult(editor, editor.getModule(), -1, null, or, null); } catch (final Exception e) { ErlLogger.error(e); } } } catch (final PartInitException e) { ErlLogger.error(e); } } }
@Override public void moduleLoaded( final IBackend backend, final IProject project, final String moduleName) { try { final ErlangDebugTarget erlangDebugTarget = debugTargetOfBackend(backend.getOtpRpc()); if (erlangDebugTarget != null && erlangDebugTarget.getInterpretedModules().contains(moduleName)) { if (isModuleRunningInInterpreter(erlangDebugTarget, backend.getOtpRpc(), moduleName)) { abortContinueDialog(erlangDebugTarget); } else { final ILaunchConfiguration launchConfiguration = erlangDebugTarget.getLaunch().getLaunchConfiguration(); final EnumSet<ErlDebugFlags> debugFlags = ErlDebugFlags.makeSet( launchConfiguration.getAttribute( ErlRuntimeAttributes.DEBUG_FLAGS, ErlDebugFlags.getFlag(ErlDebugFlags.DEFAULT_DEBUG_FLAGS))); final boolean distributed = debugFlags.contains(ErlDebugFlags.DISTRIBUTED_DEBUG); erlangDebugTarget.interpret(project, moduleName, distributed, true); } } } catch (final CoreException e) { ErlLogger.error(e); } }
@Override protected void terminated() { ErlLogger.debug("ErtsProcess terminated: %s", getLabel()); try { getLaunch().terminate(); } catch (final DebugException e) { ErlLogger.error(e); } super.terminated(); }
public static String getFilteredStackTrace(final Throwable t, final boolean shouldFilter) { try { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); writeCleanStackTrace(t, pw, shouldFilter); return sw.getBuffer().toString(); } catch (final Exception e) { ErlLogger.error(e); return e.toString(); } }
/** * Run code inspection function, and shows the result in the workbench * * @param viewtTitle title of the view * @param noResultMessage if there is no result, this message will be displayed * @param tmpFile temp .dot file * @param functionName function to call * @param signature parameters signature * @param parameters function parameters */ protected void runInspection( final String viewtTitle, final String secondaryID, final String noResultMessage, final File tmpFile, final String functionName, final String signature, final Object... parameters) { try { CodeInspectionViewsManager.hideView(CodeInspectionViewsManager.GRAPH_VIEW, secondaryID); final Boolean b = WranglerBackendManager.getRefactoringBackend() .callSimpleInspection(functionName, signature, parameters); if (b) { final FileInputStream fis = new FileInputStream(tmpFile); try { if (fis.available() > 0) { final Image img = GraphViz.load(fis, "png", new Point(0, 0)); CodeInspectionViewsManager.showDotImage(img, viewtTitle, secondaryID, tmpFile); } else { MessageDialog.openInformation( GlobalParameters.getEditor().getSite().getShell(), viewtTitle, noResultMessage); } } finally { fis.close(); } } else { MessageDialog.openError( GlobalParameters.getEditor().getSite().getShell(), "Internal error", "Internal error occured. Please report it!"); } } catch (final IOException e) { ErlLogger.error(e); } catch (final CoreException e) { ErlLogger.error(e); } catch (final Exception e) { ErlLogger.error(e); } }
/** Hide the duplicates view. */ public static void closeDuplicatesView() { final IWorkbench workbench = PlatformUI.getWorkbench(); final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); IViewPart view; try { view = window.getActivePage().showView(duplicatedView); window.getActivePage().hideView(view); } catch (final PartInitException e) { ErlLogger.error(e); } }
/* * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { final BrowserInformationControlInput input = fInfoControl.getInput(); fInfoControl.notifyDelayedInputChange(null); fInfoControl.dispose(); try { final EdocView view = (EdocView) ErlideUIPlugin.getActivePage().showView(EdocView.ID); // TODO view.setInput(infoInput); view.setText(input.getHtml()); } catch (final PartInitException e) { ErlLogger.error(e); } }
/** Shows the duplicates view. */ public static void showDuplicatesView() { final IWorkbench workbench = PlatformUI.getWorkbench(); final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); try { @SuppressWarnings("unused") final IViewPart view = window.getActivePage().showView(duplicatedView); } catch (final PartInitException e) { ErlLogger.error(e); } }
private Process startRuntimeProcess(final RuntimeData rtData) { final String[] cmds = rtData.getCmdLine(); final File workingDirectory = new File(rtData.getWorkingDir()); try { ErlLogger.debug( "START node :> " + Arrays.toString(cmds) + " *** " + workingDirectory.getCanonicalPath()); } catch (final IOException e1) { ErlLogger.error("START ERROR node :> " + e1.getMessage()); } final ProcessBuilder builder = new ProcessBuilder(cmds); builder.directory(workingDirectory); setEnvironment(rtData, builder); try { final Process aProcess = builder.start(); return aProcess; } catch (final IOException e) { ErlLogger.error("Could not create runtime: %s", Arrays.toString(cmds)); ErlLogger.error(e); return null; } }
private Template indentTemplatePattern(final Template template, final boolean indentFrom0) { String pattern = template.getPattern(); final String whiteSpacePrefix = indentFrom0 ? "" : getWhiteSpacePrefix(); try { pattern = IndentAction.indentLines(0, 0, pattern, true, whiteSpacePrefix); } catch (final RpcException e) { ErlLogger.error(e); } return new Template( template.getName(), template.getDescription(), template.getContextTypeId(), pattern, template.isAutoInsertable()); }
private String getWhiteSpacePrefix() { final int start = getStart(); final IDocument document = getDocument(); int line; try { line = document.getLineOfOffset(start); final int lineStart = document.getLineOffset(line); for (int i = 0; lineStart + i <= start; ++i) { final char c = document.getChar(lineStart + i); if (c != ' ' && c != '\t') { return document.get(lineStart, i); } } } catch (final BadLocationException e) { ErlLogger.error(e); } return ""; }
public static String loadPreviewContentFromFile(final Class<?> clazz, final String filename) { String line; final String separator = System.getProperty("line.separator"); // $NON-NLS-1$ final StringBuilder buffer = new StringBuilder(512); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(clazz.getResourceAsStream(filename))); while ((line = reader.readLine()) != null) { buffer.append(line); buffer.append(separator); } } catch (final IOException io) { ErlLogger.error(io); } finally { if (reader != null) { try { reader.close(); } catch (final IOException e) { } } } return buffer.toString(); }
@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! if ( /* !m.isStructureKnown() */ true) { // FIXME: not permitted operation 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; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final String actionId = event.getCommand().getId(); PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .getActiveEditor() .setFocus(); try { GlobalParameters.setSelection( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection()); } catch (final WranglerException e1) { MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", e1.getMessage()); return null; } try { final File tmpFile = File.createTempFile("wrangler_graph_", ".dot"); tmpFile.deleteOnExit(); final IErlSelection wranglerSelection = GlobalParameters.getWranglerSelection(); if (actionId.equals("org.erlide.wrangler.refactoring.codeinspection.cyclicdependencies")) { final Boolean answer = MessageDialog.openQuestion( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Labels", "Label edges with function names called?"); runInspection( "Cyclic module dependency", CYCLYC_VIEW_ID, "There is no cyclic dependent modules in the project!", tmpFile, "cyclic_dependent_modules", "ssx", tmpFile.getAbsolutePath(), wranglerSelection.getSearchPath(), new OtpErlangBoolean(answer)); } else if (actionId.equals( "org.erlide.wrangler.refactoring.codeinspection.generatefunctioncallgraph")) { runInspection( "Function callgraph", FUNCTION_CALL_GRAPH_VIEW_ID, "There is no dependent functions in the module!", tmpFile, "gen_function_callgraph", "sss", tmpFile.getAbsolutePath(), wranglerSelection.getFilePath(), wranglerSelection.getSearchPath()); } else if (actionId.equals( "org.erlide.wrangler.refactoring.codeinspection.generatemodulegraph")) { final Boolean answer = MessageDialog.openQuestion( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Labels", "Label edges with function names called?"); runInspection( "Module dependency graph", MODULE_GRAPH_VIEW_ID, "There is no dependent modules in the project!", tmpFile, "gen_module_graph", "ssx", tmpFile.getAbsolutePath(), wranglerSelection.getSearchPath(), new OtpErlangBoolean(answer)); } else if (actionId.equals( "org.erlide.wrangler.refactoring.codeinspection.improperdependecies")) { runInspection( "Improper module dependencies", IMPROPER_DEPENDECIES_VIEW_ID, "There is no improper module dependecies!", tmpFile, "improper_inter_module_calls", "ss", tmpFile.getAbsolutePath(), wranglerSelection.getSearchPath()); } } catch (final Exception e) { ErlLogger.error(e); } return event; }