Search in sources :

Example 1 with DetailedProblem

use of org.talend.designer.core.ui.editor.DetailedProblem in project tdi-studio-se by Talend.

the class JavaCodeProblemsChecker method processDetailedProblems.

/**
     * DOC amaumont Comment method "processDetailedProblems".
     * 
     * @param list
     * @return
     */
private ArrayList<Problem> processDetailedProblems(List<DetailedProblem> list) {
    ArrayList<Problem> problems = null;
    if (list != null) {
        problems = new ArrayList<Problem>();
        for (DetailedProblem problemWithLine : list) {
            Problem talendProblem = new Problem();
            talendProblem.setDescription(//$NON-NLS-1$
            Messages.getString(//$NON-NLS-1$
            "JavaCodeProblemsChecker.processDetailError", new Object[] { problemWithLine.getSource(), problemWithLine.getJdtProblem().getMessage() }));
            talendProblem.setStatus(Problem.ProblemStatus.ERROR);
            talendProblem.setKey(problemWithLine.getKey());
            problems.add(talendProblem);
        }
    }
    return problems;
}
Also used : DetailedProblem(org.talend.designer.core.ui.editor.DetailedProblem) DetailedProblem(org.talend.designer.core.ui.editor.DetailedProblem) Problem(org.talend.core.model.process.Problem) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 2 with DetailedProblem

use of org.talend.designer.core.ui.editor.DetailedProblem in project tdi-studio-se by Talend.

the class JavaCodeProblemsChecker method retrieveDetailedProblems.

/**
     * DOC amaumont Comment method "retrieveDetailedProblems".
     * 
     * @return
     */
private List<DetailedProblem> retrieveDetailedProblems(final IAloneProcessNodeConfigurer nodeConfigurer) {
    final ArrayList<DetailedProblem> iproblems = new ArrayList<DetailedProblem>();
    final IWorkbench workbench = PlatformUI.getWorkbench();
    Display display = workbench.getDisplay();
    if (display != null) {
        display.syncExec(new Runnable() {

            public void run() {
                IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
                IEditorPart editorPart = page.getActiveEditor();
                if (editorPart instanceof AbstractMultiPageTalendEditor) {
                    AbstractMultiPageTalendEditor multiPageTalendEditor = ((AbstractMultiPageTalendEditor) editorPart);
                    AbstractTalendEditor talendEditor = multiPageTalendEditor.getTalendEditor();
                    TalendJavaEditor codeEditor = (TalendJavaEditor) multiPageTalendEditor.getCodeEditor();
                    org.eclipse.jdt.core.ICompilationUnit compilationUnit = (org.eclipse.jdt.core.ICompilationUnit) codeEditor.getUnit();
                    IProcess process = talendEditor.getProcess();
                    if (AbstractProcessProvider.isExtensionProcessForJoblet(process)) {
                        // joblet
                        return;
                    }
                    String selectedNodeName = multiPageTalendEditor.getSelectedNodeName();
                    if (selectedNodeName == null) {
                        return;
                    }
                    String uniqueNodeName = null;
                    boolean found = false;
                    List<? extends INode> generatingNodes = process.getGeneratingNodes();
                    int generatingNodesListSize = generatingNodes.size();
                    for (int i = 0; i < generatingNodesListSize; i++) {
                        INode node = generatingNodes.get(i);
                        /* startsWith method used in case of virtual component such as 'tMap_1_TMAP_OUT' */
                        if (node.getUniqueName().equals(selectedNodeName) || node.getUniqueName().startsWith(selectedNodeName + "_")) {
                            //$NON-NLS-1$
                            uniqueNodeName = node.getUniqueName();
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        // in case the component doesn't exist
                        return;
                    }
                    final String code = retrieveCode(process, uniqueNodeName, nodeConfigurer);
                    // System.out.println(code);
                    // create requestor for accumulating discovered problems
                    MyProblemRequestor problemRequestor = new MyProblemRequestor(code, iproblems, selectedNodeName);
                    // use working copy to hold source with error
                    org.eclipse.jdt.core.ICompilationUnit workingCopy = null;
                    try {
                        JavaProcessorUtilities.computeLibrariesPath(process.getNeededModules(false), process);
                        try {
                            WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {
                            };
                            workingCopy = ((org.eclipse.jdt.core.ICompilationUnit) compilationUnit).getWorkingCopy(workingCopyOwner, problemRequestor, null);
                            problemRequestor.setReportProblems(true);
                            ((IOpenable) workingCopy).getBuffer().setContents(code);
                            ((org.eclipse.jdt.core.ICompilationUnit) workingCopy).reconcile(ICompilationUnit.NO_AST, true, null, null);
                            problemRequestor.setReportProblems(false);
                        } finally {
                            if (workingCopy != null) {
                                workingCopy.discardWorkingCopy();
                            }
                        }
                    } catch (JavaModelException e) {
                        ExceptionHandler.process(e);
                    } catch (CoreException e) {
                        ExceptionHandler.process(e);
                    }
                }
            }
        });
    }
    return iproblems;
}
Also used : INode(org.talend.core.model.process.INode) IOpenable(org.eclipse.jdt.core.IOpenable) JavaModelException(org.eclipse.jdt.core.JavaModelException) TalendJavaEditor(org.talend.designer.core.ui.editor.TalendJavaEditor) ArrayList(java.util.ArrayList) DetailedProblem(org.talend.designer.core.ui.editor.DetailedProblem) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) ArrayList(java.util.ArrayList) List(java.util.List) IProcess(org.talend.core.model.process.IProcess) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Display(org.eclipse.swt.widgets.Display)

Aggregations

DetailedProblem (org.talend.designer.core.ui.editor.DetailedProblem)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IOpenable (org.eclipse.jdt.core.IOpenable)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 WorkingCopyOwner (org.eclipse.jdt.core.WorkingCopyOwner)1 IProblem (org.eclipse.jdt.core.compiler.IProblem)1 Display (org.eclipse.swt.widgets.Display)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 INode (org.talend.core.model.process.INode)1 IProcess (org.talend.core.model.process.IProcess)1 Problem (org.talend.core.model.process.Problem)1 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)1 AbstractTalendEditor (org.talend.designer.core.ui.editor.AbstractTalendEditor)1 TalendJavaEditor (org.talend.designer.core.ui.editor.TalendJavaEditor)1