Search in sources :

Example 1 with ProblemStatus

use of org.talend.core.model.process.Problem.ProblemStatus in project tdi-studio-se by Talend.

the class Problems method computeCompilationUnit.

@SuppressWarnings("restriction")
private static List<Problem> computeCompilationUnit(IFile file, ProblemType type, Item item) throws CoreException {
    ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
    // FIXME, only for standard job first, also for JobLaunchShortcut.launch
    if (itemType == null || !itemType.equals(ERepositoryObjectType.PROCESS)) {
        return Collections.emptyList();
    }
    List<Problem> compilProblems = new ArrayList<Problem>();
    final ICompilationUnit unit = JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(new FileEditorInput(file), false);
    if (unit != null) {
        CompilationUnit ast = unit.reconcile(ASTProvider.SHARED_AST_LEVEL, ICompilationUnit.FORCE_PROBLEM_DETECTION, null, null);
        IProblem[] problems = ast.getProblems();
        if (problems != null) {
            for (IProblem p : problems) {
                String[] arguments = p.getArguments();
                int id = p.getID();
                String message = p.getMessage();
                int sourceLineNumber = p.getSourceLineNumber();
                int sourceStart = p.getSourceStart();
                int sourceEnd = p.getSourceEnd();
                String uniName = null;
                IPath location = file.getLocation();
                if (location != null) {
                    String path = location.toString();
                    uniName = setErrorMark(path, sourceLineNumber);
                }
                ProblemStatus status = ProblemStatus.WARNING;
                if (p.isError()) {
                    status = ProblemStatus.ERROR;
                }
                TalendProblem tp = new TalendProblem(status, item, null, message, sourceLineNumber, uniName, sourceStart, sourceEnd, type);
                compilProblems.add(tp);
            }
        }
    }
    return compilProblems;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPath(org.eclipse.core.runtime.IPath) TalendProblem(org.talend.core.model.process.TalendProblem) ArrayList(java.util.ArrayList) IProblem(org.eclipse.jdt.core.compiler.IProblem) ProblemStatus(org.talend.core.model.process.Problem.ProblemStatus) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Problem(org.talend.core.model.process.Problem) IProblem(org.eclipse.jdt.core.compiler.IProblem) TalendProblem(org.talend.core.model.process.TalendProblem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 2 with ProblemStatus

use of org.talend.core.model.process.Problem.ProblemStatus in project tdi-studio-se by Talend.

the class Problems method addRoutineFile.

/**
     * 
     * ggu Comment method "addRoutineFile".
     * 
     * 
     */
public static List<Information> addRoutineFile(IFile file, ProblemType type, String label, String version, boolean... fromJob) {
    if (file == null || !file.exists()) {
        return Collections.emptyList();
    }
    String uniName = null;
    List<Information> informations = new ArrayList<Information>();
    try {
        IMarker[] markers = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE);
        Problems.clearAllComliationError(label);
        for (IMarker marker : markers) {
            Integer lineNr = (Integer) marker.getAttribute(IMarker.LINE_NUMBER);
            String message = (String) marker.getAttribute(IMarker.MESSAGE);
            Integer severity = (Integer) marker.getAttribute(IMarker.SEVERITY);
            Integer start = (Integer) marker.getAttribute(IMarker.CHAR_START);
            Integer end = (Integer) marker.getAttribute(IMarker.CHAR_END);
            if (lineNr != null && message != null && severity != null && start != null && end != null) {
                Information information = PropertiesFactory.eINSTANCE.createInformation();
                information.setText(message);
                informations.add(information);
                ProblemStatus status = null;
                switch(severity) {
                    case IMarker.SEVERITY_ERROR:
                        status = ProblemStatus.ERROR;
                        information.setLevel(InformationLevel.ERROR_LITERAL);
                        IPath location = file.getLocation();
                        if (location != null) {
                            String path = location.toString();
                            uniName = setErrorMark(path, lineNr);
                        }
                        break;
                    case IMarker.SEVERITY_WARNING:
                        status = ProblemStatus.WARNING;
                        information.setLevel(InformationLevel.WARN_LITERAL);
                        break;
                    case IMarker.SEVERITY_INFO:
                        status = ProblemStatus.INFO;
                        information.setLevel(InformationLevel.INFO_LITERAL);
                        break;
                    default:
                        break;
                }
                if (status != null) {
                    if (status != ProblemStatus.ERROR) {
                        continue;
                    }
                    if ("".equals(uniName) || uniName == null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        uniName = "uniName";
                    }
                    add(status, marker, label, message, lineNr, uniName, start, end, type, version);
                }
            }
        }
        if (fromJob.length > 0 && fromJob[0]) {
            addErrorMark();
        }
    } catch (org.eclipse.core.runtime.CoreException e) {
        ExceptionHandler.process(e);
    }
    return informations;
}
Also used : ProblemStatus(org.talend.core.model.process.Problem.ProblemStatus) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) Information(org.talend.core.model.properties.Information)

Example 3 with ProblemStatus

use of org.talend.core.model.process.Problem.ProblemStatus in project tdi-studio-se by Talend.

the class Problems method addJobRoutineFile.

public static List<Information> addJobRoutineFile(IFile file, ProblemType type, Item item, boolean... fromJob) {
    if (file == null || !file.exists()) {
        return Collections.emptyList();
    }
    String uniName = null;
    List<Information> informations = new ArrayList<Information>();
    try {
        Set<IMarker> fullMarker = new HashSet<IMarker>();
        IMarker[] markers = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE);
        if (markers != null) {
            fullMarker.addAll(Arrays.asList(markers));
        }
        // remove old
        Problems.clearAllComliationError(item.getProperty().getLabel());
        for (IMarker marker : fullMarker) {
            Integer lineNr = (Integer) marker.getAttribute(IMarker.LINE_NUMBER);
            String message = (String) marker.getAttribute(IMarker.MESSAGE);
            Integer severity = (Integer) marker.getAttribute(IMarker.SEVERITY);
            Integer start = (Integer) marker.getAttribute(IMarker.CHAR_START);
            Integer end = (Integer) marker.getAttribute(IMarker.CHAR_END);
            if (lineNr != null && message != null && severity != null && start != null && end != null) {
                Information information = PropertiesFactory.eINSTANCE.createInformation();
                information.setText(message);
                informations.add(information);
                ProblemStatus status = null;
                switch(severity) {
                    case IMarker.SEVERITY_ERROR:
                        status = ProblemStatus.ERROR;
                        information.setLevel(InformationLevel.ERROR_LITERAL);
                        IPath location = file.getLocation();
                        if (location != null) {
                            String path = location.toString();
                            uniName = setErrorMark(path, lineNr);
                        }
                        break;
                    case IMarker.SEVERITY_WARNING:
                        status = ProblemStatus.WARNING;
                        information.setLevel(InformationLevel.WARN_LITERAL);
                        break;
                    case IMarker.SEVERITY_INFO:
                        status = ProblemStatus.INFO;
                        information.setLevel(InformationLevel.INFO_LITERAL);
                        break;
                    default:
                        break;
                }
                if (status != null) {
                    if (status != ProblemStatus.ERROR) {
                        continue;
                    }
                    if ("".equals(uniName) || uniName == null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        uniName = "uniName";
                    }
                    add(status, marker, item, message, lineNr, uniName, start, end, type);
                }
            }
        }
        // TalendProcessJavaProject.buildModules for buildWholeCodeProject (about line 324)
        if (!buildWholeProject) {
            addAll(computeCompilationUnit(file, type, item));
        }
        if (fromJob.length > 0 && fromJob[0]) {
            addErrorMark();
        }
    } catch (org.eclipse.core.runtime.CoreException e) {
        ExceptionHandler.process(e);
    }
    return informations;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) Information(org.talend.core.model.properties.Information) ProblemStatus(org.talend.core.model.process.Problem.ProblemStatus) IMarker(org.eclipse.core.resources.IMarker) HashSet(java.util.HashSet)

Example 4 with ProblemStatus

use of org.talend.core.model.process.Problem.ProblemStatus in project tdi-studio-se by Talend.

the class ProblemsManager method checkProblemsForTableEntry.

public boolean checkProblemsForTableEntry(ITableEntry tableEntry, boolean forceRefreshData, boolean checkLookupProblem) {
    if (!mapperManager.isCheckSyntaxEnabled()) {
        return false;
    }
    if (forceRefreshData) {
        mapperManager.getAbstractMapComponent().restoreMapperModelFromInternalData();
        checkProblems();
    }
    String expression = tableEntry.getExpression();
    List<Problem> problems = null;
    if (expression == null || EMPTY_STRING.equals(expression.trim())) {
        problems = null;
    } else {
        // System.out.println("check=" + expression);
        if (codeLanguage == ECodeLanguage.PERL) {
            problems = codeChecker.checkProblemsForExpression(expression);
        } else if (codeLanguage == ECodeLanguage.JAVA) {
            PROBLEM_KEY_FIELD problemKeyField = JavaGenerationManager.PROBLEM_KEY_FIELD.METADATA_COLUMN;
            String entryName = tableEntry.getName();
            if (tableEntry instanceof FilterTableEntry || tableEntry instanceof ExpressionFilterEntry) {
                problemKeyField = JavaGenerationManager.PROBLEM_KEY_FIELD.FILTER;
                entryName = null;
            }
            problems = checkJavaProblemsForEntry(problemKeyField, tableEntry.getParent().getName(), entryName, forceRefreshData);
        }
        if (problems != null) {
            for (Iterator iter = problems.iterator(); iter.hasNext(); ) {
                Problem problem = (Problem) iter.next();
                ProblemStatus status = problem.getStatus();
                if (status != ProblemStatus.ERROR) {
                    iter.remove();
                }
            }
        } else {
            problems = null;
        }
    }
    if (problems != null) {
        if (problems.size() == 0) {
            tableEntry.setProblems(null);
        } else {
            hasProblems = true;
            tableEntry.setProblems(problems);
        }
    } else {
        tableEntry.setProblems(problems);
    }
    // check problem for M/R process , only needed if modify lookup expressions
    if (checkLookupProblem) {
        checkLookupExpressionProblem();
    }
    // no need to update again
    TableViewerCreator tableViewerCreator = mapperManager.retrieveTableViewerCreator(tableEntry);
    DataMapTableView retrieveDataMapTableView = mapperManager.retrieveDataMapTableView(tableEntry);
    mapperManager.getUiManager().applyActivatedCellEditors(tableViewerCreator);
    return problems != null;
}
Also used : ProblemStatus(org.talend.core.model.process.Problem.ProblemStatus) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) FilterTableEntry(org.talend.designer.mapper.model.tableentry.FilterTableEntry) Iterator(java.util.Iterator) Problem(org.talend.core.model.process.Problem) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry) PROBLEM_KEY_FIELD(org.talend.designer.mapper.language.generation.JavaGenerationManager.PROBLEM_KEY_FIELD)

Aggregations

ProblemStatus (org.talend.core.model.process.Problem.ProblemStatus)4 ArrayList (java.util.ArrayList)3 IPath (org.eclipse.core.runtime.IPath)3 IMarker (org.eclipse.core.resources.IMarker)2 CoreException (org.eclipse.core.runtime.CoreException)2 Problem (org.talend.core.model.process.Problem)2 Information (org.talend.core.model.properties.Information)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IProblem (org.eclipse.jdt.core.compiler.IProblem)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)1 TalendProblem (org.talend.core.model.process.TalendProblem)1 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)1 PROBLEM_KEY_FIELD (org.talend.designer.mapper.language.generation.JavaGenerationManager.PROBLEM_KEY_FIELD)1 ExpressionFilterEntry (org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry)1 FilterTableEntry (org.talend.designer.mapper.model.tableentry.FilterTableEntry)1 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)1