List of usage examples for org.eclipse.jdt.core IJavaModelMarker TASK_MARKER
String TASK_MARKER
To view the source code for org.eclipse.jdt.core IJavaModelMarker TASK_MARKER.
Click Source Link
"org.eclipse.jdt.core.task"
). From source file:de.plugins.eclipse.depclipse.testcommons.TestingEnvironment.java
License:Open Source License
/** * Return all problems with the specified element. *//*from w ww. j av a2 s .c o m*/ public IMarker[] getTaskMarkersFor(IPath path) { IResource resource = null; if (path.equals(getWorkspaceRootPath())) { resource = getWorkspace().getRoot(); } else { IProject p = getProject(path); if (p != null && path.equals(p.getFullPath())) { resource = getProject(path.lastSegment()); } else if (path.getFileExtension() == null) { resource = getWorkspace().getRoot().getFolder(path); } else { resource = getWorkspace().getRoot().getFile(path); } } try { if (resource != null) { final IMarker[] markers = resource.findMarkers(IJavaModelMarker.TASK_MARKER, true, IResource.DEPTH_INFINITE); if (markers.length > 1) { Arrays.sort(markers, new Comparator<IMarker>() { public int compare(IMarker o1, IMarker o2) { IMarker marker1 = (IMarker) o1; IMarker marker2 = (IMarker) o2; try { final int start1 = ((Integer) marker1.getAttribute(IMarker.CHAR_START)).intValue(); final int start2 = ((Integer) marker2.getAttribute(IMarker.CHAR_START)).intValue(); return start1 - start2; } catch (CoreException e) { return 0; } } }); } return markers; } } catch (CoreException e) { // ignore } return new IMarker[0]; }
From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java
License:Open Source License
protected void storeTasksFor(SourceFile sourceFile, CategorizedProblem[] tasks) throws CoreException { if (sourceFile == null || tasks == null || tasks.length == 0) return;/*from w w w .jav a 2 s . c o m*/ IResource resource = sourceFile.resource; for (int i = 0, l = tasks.length; i < l; i++) { CategorizedProblem task = tasks[i]; if (task.getID() == IProblem.Task) { IMarker marker = resource.createMarker(IJavaModelMarker.TASK_MARKER); Integer priority = P_NORMAL; String compilerPriority = task.getArguments()[2]; if (JavaCore.COMPILER_TASK_PRIORITY_HIGH.equals(compilerPriority)) priority = P_HIGH; else if (JavaCore.COMPILER_TASK_PRIORITY_LOW.equals(compilerPriority)) priority = P_LOW; String[] attributeNames = JAVA_TASK_MARKER_ATTRIBUTE_NAMES; int standardLength = attributeNames.length; String[] allNames = attributeNames; String[] extraAttributeNames = task.getExtraMarkerAttributeNames(); int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length; if (extraLength > 0) { allNames = new String[standardLength + extraLength]; System.arraycopy(attributeNames, 0, allNames, 0, standardLength); System.arraycopy(extraAttributeNames, 0, allNames, standardLength, extraLength); } Object[] allValues = new Object[allNames.length]; // standard attributes int index = 0; allValues[index++] = task.getMessage(); allValues[index++] = priority; allValues[index++] = new Integer(task.getID()); allValues[index++] = new Integer(task.getSourceStart()); allValues[index++] = new Integer(task.getSourceEnd() + 1); allValues[index++] = new Integer(task.getSourceLineNumber()); allValues[index++] = Boolean.FALSE; allValues[index++] = JavaBuilder.SOURCE_ID; // optional extra attributes if (extraLength > 0) System.arraycopy(task.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength); marker.setAttributes(allNames, allValues); } } }
From source file:net.sf.j2s.core.builder.JavaBuilder.java
License:Open Source License
public static IMarker[] getTasksFor(IResource resource) { try {/* ww w.j a v a2s . c om*/ if (resource != null && resource.exists()) return resource.findMarkers(IJavaModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE); } catch (CoreException e) { // assume there are no tasks } return new IMarker[0]; }
From source file:net.sf.j2s.core.builder.JavaBuilder.java
License:Open Source License
public static void removeTasksFor(IResource resource) { try {/*from ww w . jav a2 s . c o m*/ if (resource != null && resource.exists()) resource.deleteMarkers(IJavaModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE); } catch (CoreException e) { // assume there were no problems } }
From source file:net.sf.j2s.core.builder.JavaBuilder.java
License:Open Source License
public static void removeProblemsAndTasksFor(IResource resource) { try {//from www . java2 s . c om if (resource != null && resource.exists()) { resource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); resource.deleteMarkers(IJavaModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE); // delete managed markers Set markerTypes = JavaModelManager.getJavaModelManager().compilationParticipants .managedMarkerTypes(); if (markerTypes.size() == 0) return; Iterator iterator = markerTypes.iterator(); while (iterator.hasNext()) resource.deleteMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE); } } catch (CoreException e) { // assume there were no problems } }
From source file:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
private void removeProblemsAndTasksFor(IResource resource) { try {//from w w w .j a v a 2 s . c o m if (resource != null && resource.exists()) { resource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); resource.deleteMarkers(IJavaModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE); // now removed markers from compilation participants HashSet<String> managedMarkers = JavaModelManager.getJavaModelManager().compilationParticipants .managedMarkerTypes(); for (String managedMarker : managedMarkers) { resource.deleteMarkers(managedMarker, true, IResource.DEPTH_INFINITE); } } } catch (CoreException e) { } if (resource != null) { AJLog.log(AJLog.BUILDER, "Removed problems and tasks for project " + resource.getName()); //$NON-NLS-1$ } }
From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitProblemFinder.java
License:Open Source License
public static CompilationUnitDeclaration processAJ( // AspectJ Change CompilationUnit unitElement, // AspectJ Change CommentRecorderParser parser, // AspectJ Change WorkingCopyOwner workingCopyOwner, HashMap<String, CategorizedProblem[]> problems, boolean creatingAST, int reconcileFlags, IProgressMonitor monitor) throws JavaModelException { boolean isJavaFileInAJEditor = (reconcileFlags & JAVA_FILE_IN_AJ_EDITOR) != 0; JavaProject project = (JavaProject) unitElement.getJavaProject(); ITDAwareNameEnvironment environment = null; CancelableProblemFactory problemFactory = null; AJCompilationUnitProblemFinder problemFinder = null; // AspectJ Change try {//w ww .j ava 2 s . com // AspectJ Change begin // use an ITDAware environment to ensure that ITDs are included for source types environment = new ITDAwareNameEnvironment(project, workingCopyOwner, monitor); // AspectJ Change end problemFactory = new CancelableProblemFactory(monitor); problemFinder = new AJCompilationUnitProblemFinder( // AspectJ Change environment, getHandlingPolicy(), getCompilerOptions(project.getOptions(true), creatingAST, ((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0)), getRequestor(), problemFactory, unitElement); CompilationUnitDeclaration unit = null; // AspectJ Change begin // the parser should be a SourceElementParser or AJSourceElementParser2. // this ensures that a diet parse can be done, while at the same time // all declarations be reported if (parser != null) { problemFinder.parser = parser; } try { if (problemFinder.parser instanceof SourceElementParser) { unit = ((SourceElementParser) problemFinder.parser).parseCompilationUnit(unitElement, true/* full parse */, monitor); problemFinder.resolve(unit, unitElement, true, // verify methods true, // analyze code true); // generate code } else if (problemFinder.parser instanceof AJSourceElementParser2) { unit = ((AJSourceElementParser2) problemFinder.parser).parseCompilationUnit(unitElement, true/* full parse */, monitor); problemFinder.resolve(unit, unitElement, true, // verify methods true, // analyze code true); // generate code } else { unit = problemFinder.resolve(unitElement, true, // verify methods true, // analyze code true); // generate code } } catch (AbortCompilation e) { problemFinder.handleInternalException(e, unit); } // revert the compilation units that have ITDs in them ((ITDAwareLookupEnvironment) problemFinder.lookupEnvironment).revertCompilationUnits(); // AspectJ Change end CompilationResult unitResult = unit.compilationResult; CategorizedProblem[] unitProblems = unitResult.getProblems(); int length = unitProblems == null ? 0 : unitProblems.length; if (length > 0) { // AspectJ Change begin // filter out spurious problems CategorizedProblem[] categorizedProblems = new CategorizedProblem[length]; System.arraycopy(unitProblems, 0, categorizedProblems, 0, length); categorizedProblems = removeAJNonProblems(categorizedProblems, unitElement, isJavaFileInAJEditor); if (categorizedProblems.length > 0) { problems.put(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, categorizedProblems); } // AspectJ Change end } unitProblems = unitResult.getTasks(); length = unitProblems == null ? 0 : unitProblems.length; if (length > 0) { CategorizedProblem[] categorizedProblems = new CategorizedProblem[length]; System.arraycopy(unitProblems, 0, categorizedProblems, 0, length); problems.put(IJavaModelMarker.TASK_MARKER, categorizedProblems); } if (NameLookup.VERBOSE) { AJLog.log(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " //$NON-NLS-1$ + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ AJLog.log(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " //$NON-NLS-1$ + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$ } return unit; } catch (OperationCanceledException e) { // catch this exception so as to not enter the // catch(RuntimeException e) below throw e; } catch (RuntimeException e) { String message = handleException(unitElement, environment, e); throw new JavaModelException(new RuntimeException(message, e), IJavaModelStatusConstants.COMPILER_FAILURE); } finally { if (environment != null) environment.setMonitor(null); // AJDT 3.6 // don't hold a reference to this // external object if (problemFactory != null) problemFactory.monitor = null; // don't hold a reference to this // external object // NB: unit.cleanUp() is done by caller if (problemFinder != null && !creatingAST) problemFinder.lookupEnvironment.reset(); } }
From source file:org.eclipse.che.jdt.quickfix.ReorgQuickFixTest.java
License:Open Source License
@Test public void testTodoTasks1() throws Exception { IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" // TODO: XXX\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); String str = "TODO: XXX"; AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0); ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task, new String[0], true, IJavaModelMarker.TASK_MARKER); ArrayList proposals = collectCorrections(context, problem); assertNumberOfProposals(proposals, 1); assertCorrectLabels(proposals);//w w w.jav a 2s.c o m CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" }\n"); buf.append("}\n"); assertEqualString(preview, buf.toString()); }
From source file:org.eclipse.che.jdt.quickfix.ReorgQuickFixTest.java
License:Open Source License
@Test public void testTodoTasks2() throws Exception { IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" // Some other text TODO: XXX\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); String str = "TODO: XXX"; AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0); ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task, new String[0], true, IJavaModelMarker.TASK_MARKER); ArrayList proposals = collectCorrections(context, problem); assertNumberOfProposals(proposals, 1); assertCorrectLabels(proposals);/*from w ww. j a va2 s . co m*/ CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" // Some other text \n"); buf.append(" }\n"); buf.append("}\n"); assertEqualString(preview, buf.toString()); }
From source file:org.eclipse.che.jdt.quickfix.ReorgQuickFixTest.java
License:Open Source License
@Test public void testTodoTasks3() throws Exception { IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" /* TODO: XXX */\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); String str = "TODO: XXX"; AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0); ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task, new String[0], true, IJavaModelMarker.TASK_MARKER); ArrayList proposals = collectCorrections(context, problem); assertNumberOfProposals(proposals, 1); assertCorrectLabels(proposals);//from ww w . j av a 2 s . com CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" }\n"); buf.append("}\n"); assertEqualString(preview, buf.toString()); }