Search in sources :

Example 61 with IMarker

use of org.eclipse.core.resources.IMarker in project ow by vtst.

the class ErrorManagerGeneratingProblemMarkers method println.

@Override
public void println(CheckLevel level, JSError error) {
    IResource file = getResource(error.sourceName);
    if (file == null)
        return;
    try {
        IMarker marker = file.createMarker(getMarkerType());
        marker.setAttribute(IMarker.SEVERITY, checkLevelToSeverity(level));
        marker.setAttribute(IMarker.MESSAGE, error.description);
        marker.setAttribute(IMarker.LINE_NUMBER, error.lineNumber);
        marker.setAttribute(IMarker.LOCATION, error.sourceName);
    // error.getCharno() for the char number in the line
    } catch (CoreException e) {
        e.printStackTrace();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource)

Example 62 with IMarker

use of org.eclipse.core.resources.IMarker in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonQuickAssistProcessor method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    List<IMarker> markers;
    try {
        markers = getMarkersFor(invocationContext.getSourceViewer(), invocationContext.getOffset());
    } catch (BadLocationException e) {
        errorMessage = e.getMessage();
        return new ICompletionProposal[0];
    }
    List<ICompletionProposal> result = Lists.newArrayList();
    for (IMarker marker : markers) {
        for (IMarkerResolution markerResolution : quickFixer.getResolutions(marker)) {
            result.add(new MarkerResolutionProposal(marker, markerResolution, invocationContext.getSourceViewer()));
        }
    }
    return result.toArray(new ICompletionProposal[0]);
}
Also used : IMarkerResolution(org.eclipse.ui.IMarkerResolution) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IMarker(org.eclipse.core.resources.IMarker) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 63 with IMarker

use of org.eclipse.core.resources.IMarker 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 64 with IMarker

use of org.eclipse.core.resources.IMarker 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 65 with IMarker

use of org.eclipse.core.resources.IMarker in project tdi-studio-se by Talend.

the class JobErrorsChecker method checkLastGenerationHasCompilationError.

public static void checkLastGenerationHasCompilationError(boolean updateProblemsView) throws ProcessorException {
    if (updateProblemsView && CommonsPlugin.isHeadless()) {
        updateProblemsView = false;
    }
    boolean hasError = false;
    boolean isJob = true;
    Item item = null;
    final IProxyRepositoryFactory proxyRepositoryFactory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    final ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
    Integer line = null;
    String errorMessage = null;
    try {
        for (JobInfo jobInfo : LastGenerationInfo.getInstance().getLastGeneratedjobs()) {
            if (jobInfo.isTestContainer()) {
                continue;
            }
            item = null;
            List<IRepositoryViewObject> allVersions = proxyRepositoryFactory.getAllVersion(jobInfo.getJobId());
            for (IRepositoryViewObject repositoryObject2 : allVersions) {
                Property property2 = repositoryObject2.getProperty();
                if (jobInfo.getJobVersion().equals(property2.getVersion())) {
                    item = property2.getItem();
                    break;
                }
            }
            if (item == null) {
                continue;
            }
            IFile file = synchronizer.getFile(item);
            if (file == null) {
                return;
            }
            // check other java files related to the job . example : spark job will generate several java file for
            // one job
            final IResource[] members = file.getParent().members();
            for (IResource member : members) {
                if (member instanceof IFile && "java".equals(member.getFileExtension())) {
                    IMarker[] markers = ((IFile) member).findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE);
                    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) {
                            switch(severity) {
                                case IMarker.SEVERITY_ERROR:
                                    hasError = true;
                                    line = lineNr;
                                    errorMessage = message;
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
            if (updateProblemsView) {
                Problems.addRoutineFile(file, ProblemType.JOB, item.getProperty().getLabel(), item.getProperty().getVersion(), true);
            }
            if (hasError) {
                break;
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    if (hasError && item != null) {
        if (isJob) {
            throw new ProcessorException(//$NON-NLS-1$
            Messages.getString("JobErrorsChecker_compile_errors") + " " + '\n' + Messages.getString("JobErrorsChecker_compile_error_message", item.getProperty().getLabel()) + //$NON-NLS-1$
            '\n' + Messages.getString("JobErrorsChecker_compile_error_line") + ':' + ' ' + line + //$NON-NLS-1$
            '\n' + Messages.getString("JobErrorsChecker_compile_error_detailmessage") + ':' + ' ' + errorMessage + //$NON-NLS-1$
            '\n' + //$NON-NLS-1$
            Messages.getString("JobErrorsChecker_compile_error_jvmmessage"));
        } else {
            throw new ProcessorException(//$NON-NLS-1$
            Messages.getString("CamelJobErrorsChecker_compile_errors") + " " + '\n' + Messages.getString("JobErrorsChecker_compile_error_message", item.getProperty().getLabel()) + //$NON-NLS-1$
            '\n' + Messages.getString("JobErrorsChecker_compile_error_line") + ':' + ' ' + line + //$NON-NLS-1$
            '\n' + Messages.getString("JobErrorsChecker_compile_error_detailmessage") + ':' + ' ' + errorMessage + //$NON-NLS-1$
            '\n' + //$NON-NLS-1$
            Messages.getString("JobErrorsChecker_compile_error_jvmmessage"));
        }
    }
    // if no error for job, check codes.
    checkRoutinesCompilationError();
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException) Item(org.talend.core.model.properties.Item) JobInfo(org.talend.core.model.process.JobInfo) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IMarker(org.eclipse.core.resources.IMarker) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IResource(org.eclipse.core.resources.IResource)

Aggregations

IMarker (org.eclipse.core.resources.IMarker)115 CoreException (org.eclipse.core.runtime.CoreException)31 Test (org.junit.Test)31 IFile (org.eclipse.core.resources.IFile)23 IResource (org.eclipse.core.resources.IResource)16 ArrayList (java.util.ArrayList)15 IProject (org.eclipse.core.resources.IProject)8 IPath (org.eclipse.core.runtime.IPath)8 Position (org.eclipse.jface.text.Position)8 Annotation (org.eclipse.jface.text.source.Annotation)7 Matchers.anyString (org.mockito.Matchers.anyString)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Rule (net.sourceforge.pmd.Rule)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 BadLocationException (org.eclipse.jface.text.BadLocationException)6 RuleViolation (net.sourceforge.pmd.RuleViolation)5 JavaLanguageModule (net.sourceforge.pmd.lang.java.JavaLanguageModule)5 IDocument (org.eclipse.jface.text.IDocument)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5