org.eclipse.jdt.core.IJavaModelMarker Java Examples

The following examples show how to use org.eclipse.jdt.core.IJavaModelMarker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static Diagnostic toDiagnostic(IDocument document, IMarker marker, boolean isDiagnosticTagSupported) {
	if (marker == null || !marker.exists()) {
		return null;
	}
	Diagnostic d = new Diagnostic();
	d.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
	d.setMessage(marker.getAttribute(IMarker.MESSAGE, ""));
	int problemId = marker.getAttribute(IJavaModelMarker.ID, 0);
	d.setCode(String.valueOf(problemId));
	d.setSeverity(convertSeverity(marker.getAttribute(IMarker.SEVERITY, -1)));
	d.setRange(convertRange(document, marker));
	if (isDiagnosticTagSupported) {
		d.setTags(DiagnosticsHandler.getDiagnosticTag(problemId));
	}
	return d;
}
 
Example #2
Source File: ProblemMarkerBuilder.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * addMarker Method that adds a Marker to a File, which can then be displayed as an error/warning in the IDE.
 *
 * @param file the IResource of the File to which the Marker is added
 * @param message the message the Marker is supposed to display
 * @param lineNumber the Line to which the Marker is supposed to be added
 * @param start the number of the start character for the Marker
 * @param end the number of the end character for the Marker
 */
private void addMarker(final IResource file, final String message, int lineNumber, final int start, final int end) {
	try {
		final IMarker marker = file.createMarker(Constants.MARKER_TYPE);
		marker.setAttribute(IMarker.MESSAGE, message);
		marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
		if (lineNumber == -1) {
			lineNumber = 1;
		}
		marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
		marker.setAttribute(IMarker.CHAR_START, start);
		marker.setAttribute(IMarker.CHAR_END, end);
		// IJavaModelMarker is important for the Quickfix Processor to work
		// correctly
		marker.setAttribute(IJavaModelMarker.ID, Constants.JDT_PROBLEM_ID);
	}
	catch (final CoreException e) {}
}
 
Example #3
Source File: JavaMarkerAnnotation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public int getId() {
		IMarker marker= getMarker();
		if (marker == null  || !marker.exists())
			return -1;

		if (isProblem())
			return marker.getAttribute(IJavaModelMarker.ID, -1);

//		if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
//			try {
//				if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
//					return IProblem.Task;
//				}
//			} catch (CoreException e) {
//				JavaPlugin.log(e); // should no happen, we test for marker.exists
//			}
//		}

		return -1;
	}
 
Example #4
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
static boolean noErrorsAtLocation(IProblemLocation[] locations) {
	if (locations != null) {
		for (int i= 0; i < locations.length; i++) {
			IProblemLocation location= locations[i];
			if (location.isError()) {
				if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(location.getMarkerType())
						&& JavaCore.getOptionForConfigurableSeverity(location.getProblemId()) != null) {
					// continue (only drop out for severe (non-optional) errors)
				} else {
					return false;
				}
			}
		}
	}
	return true;
}
 
Example #5
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean containsQuickFixableRenameLocal(IProblemLocation[] locations) {
	if (locations != null) {
		for (int i= 0; i < locations.length; i++) {
			IProblemLocation location= locations[i];
			if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(location.getMarkerType())) {
				switch (location.getProblemId()) {
					case IProblem.LocalVariableHidingLocalVariable:
					case IProblem.LocalVariableHidingField:
					case IProblem.FieldHidingLocalVariable:
					case IProblem.FieldHidingField:
					case IProblem.ArgumentHidingLocalVariable:
					case IProblem.ArgumentHidingField:
						return true;
				}
			}
		}
	}
	return false;
}
 
Example #6
Source File: ContributedProcessorDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Set<String> getHandledMarkerTypes(IConfigurationElement element) {
	HashSet<String> map= new HashSet<String>(7);
	IConfigurationElement[] children= element.getChildren(HANDLED_MARKER_TYPES);
	for (int i= 0; i < children.length; i++) {
		IConfigurationElement[] types= children[i].getChildren(MARKER_TYPE);
		for (int k= 0; k < types.length; k++) {
			String attribute= types[k].getAttribute(ID);
			if (attribute != null) {
				map.add(attribute);
			}
		}
	}
	if (map.isEmpty()) {
		map.add(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
		map.add(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER);
		map.add(IJavaModelMarker.TASK_MARKER);
	}
	return map;
}
 
Example #7
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static Diagnostic toDiagnostic(Range range, IMarker marker, boolean isDiagnosticTagSupported) {
	if (marker == null || !marker.exists()) {
		return null;
	}
	Diagnostic d = new Diagnostic();
	d.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
	String message = marker.getAttribute(IMarker.MESSAGE, "");
	if (Messages.ProjectConfigurationUpdateRequired.equals(message)) {
		message = PROJECT_CONFIGURATION_IS_NOT_UP_TO_DATE_WITH_POM_XML;
	}
	d.setMessage(message);
	d.setSeverity(convertSeverity(marker.getAttribute(IMarker.SEVERITY, -1)));
	int problemId = marker.getAttribute(IJavaModelMarker.ID, 0);
	d.setCode(String.valueOf(problemId));
	if (isDiagnosticTagSupported) {
		d.setTags(DiagnosticsHandler.getDiagnosticTag(problemId));
	}
	d.setRange(range);
	return d;
}
 
Example #8
Source File: CorrectionMarkerResolutionGenerator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IProblemLocation createFromMarker(IMarker marker, ICompilationUnit cu) {
	try {
		int id= marker.getAttribute(IJavaModelMarker.ID, -1);
		int start= marker.getAttribute(IMarker.CHAR_START, -1);
		int end= marker.getAttribute(IMarker.CHAR_END, -1);
		int severity= marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
		String[] arguments= CorrectionEngine.getProblemArguments(marker);
		String markerType= marker.getType();
		if (cu != null && id != -1 && start != -1 && end != -1 && arguments != null) {
			boolean isError= (severity == IMarker.SEVERITY_ERROR);
			return new ProblemLocation(start, end - start, id, arguments, isError, markerType);
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example #9
Source File: BuildWorkspaceHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static String convertMarker(IMarker marker) {
	StringBuilder builder = new StringBuilder();
	String message = marker.getAttribute(IMarker.MESSAGE, "<no message>");
	String code = String.valueOf(marker.getAttribute(IJavaModelMarker.ID, 0));
	builder.append(" message: ").append(message).append(";");
	builder.append(" code: ").append(code).append(";");
	IResource resource = marker.getResource();
	if (resource != null) {
		builder.append(" resource: ").append(resource.getLocation()).append(";");
	}
	int line = marker.getAttribute(IMarker.LINE_NUMBER, -1);
	if (line > 0) {
		builder.append(" line: ").append(line);
	}
	return builder.toString();
}
 
Example #10
Source File: RequestorWrapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see ICodeSnippetRequestor
 */
public void acceptProblem(CategorizedProblem problem, char[] fragmentSource, int fragmentKind) {
	try {
		IMarker marker = ResourcesPlugin.getWorkspace().getRoot().createMarker(IJavaModelMarker.TRANSIENT_PROBLEM);
		marker.setAttribute(IJavaModelMarker.ID, problem.getID());
		marker.setAttribute(IMarker.CHAR_START, problem.getSourceStart());
		marker.setAttribute(IMarker.CHAR_END, problem.getSourceEnd() + 1);
		marker.setAttribute(IMarker.LINE_NUMBER, problem.getSourceLineNumber());
		//marker.setAttribute(IMarker.LOCATION, "#" + problem.getSourceLineNumber());
		marker.setAttribute(IMarker.MESSAGE, problem.getMessage());
		marker.setAttribute(IMarker.SEVERITY, (problem.isWarning() ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_ERROR));
		marker.setAttribute(IMarker.SOURCE_ID, JavaBuilder.SOURCE_ID);
		this.requestor.acceptProblem(marker, new String(fragmentSource), fragmentKind);
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example #11
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public IMarker getCycleMarker(){
	try {
		if (this.project.isAccessible()) {
			IMarker[] markers = this.project.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
			for (int i = 0, length = markers.length; i < length; i++) {
				IMarker marker = markers[i];
				String cycleAttr = (String)marker.getAttribute(IJavaModelMarker.CYCLE_DETECTED);
				if (cycleAttr != null && cycleAttr.equals("true")){ //$NON-NLS-1$
					return marker;
				}
			}
		}
	} catch (CoreException e) {
		// could not get markers: return null
	}
	return null;
}
 
Example #12
Source File: ASTReader.java    From JDeodorant with MIT License 6 votes vote down vote up
private List<IMarker> buildProject(IJavaProject iJavaProject, IProgressMonitor pm) {
	ArrayList<IMarker> result = new ArrayList<IMarker>();
	try {
		IProject project = iJavaProject.getProject();
		project.refreshLocal(IResource.DEPTH_INFINITE, pm);	
		project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, pm);
		IMarker[] markers = null;
		markers = project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
		for (IMarker marker: markers) {
			Integer severityType = (Integer) marker.getAttribute(IMarker.SEVERITY);
			if (severityType.intValue() == IMarker.SEVERITY_ERROR) {
				result.add(marker);
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return result;
}
 
Example #13
Source File: UserLibraryMarkerResolutionGenerator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean hasResolutions(IMarker marker) {
	int id= marker.getAttribute(IJavaModelMarker.ID, -1);
	if (id == IJavaModelStatusConstants.CP_CONTAINER_PATH_UNBOUND
			|| id == IJavaModelStatusConstants.CP_VARIABLE_PATH_UNBOUND
			|| id == IJavaModelStatusConstants.INVALID_CP_CONTAINER_ENTRY
			|| id == IJavaModelStatusConstants.DEPRECATED_VARIABLE
			|| id == IJavaModelStatusConstants.INVALID_CLASSPATH) {
		return true;
	}
	return false;
}
 
Example #14
Source File: JarFileExportOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tells whether the given resource (or its children) have compile errors.
 * The method acts on the current build state and does not recompile.
 *
 * @param resource the resource to check for errors
 * @return <code>true</code> if the resource (and its children) are error free
 * @throws CoreException import org.eclipse.core.runtime.CoreException if there's a marker problem
 */
private boolean hasCompileWarnings(IResource resource) throws CoreException {
	IMarker[] problemMarkers= resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
	for (int i= 0; i < problemMarkers.length; i++) {
		if (problemMarkers[i].getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_WARNING)
			return true;
	}
	return false;
}
 
Example #15
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Remove all markers denoting classpath problems
 */ //TODO (philippe) should improve to use a bitmask instead of booleans (CYCLE, FORMAT, VALID)
protected void flushClasspathProblemMarkers(boolean flushCycleMarkers, boolean flushClasspathFormatMarkers, boolean flushOverlappingOutputMarkers) {
	try {
		if (this.project.isAccessible()) {
			IMarker[] markers = this.project.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
			for (int i = 0, length = markers.length; i < length; i++) {
				IMarker marker = markers[i];
				if (flushCycleMarkers && flushClasspathFormatMarkers && flushOverlappingOutputMarkers) {
					marker.delete();
				} else {
					String cycleAttr = (String)marker.getAttribute(IJavaModelMarker.CYCLE_DETECTED);
					String classpathFileFormatAttr =  (String)marker.getAttribute(IJavaModelMarker.CLASSPATH_FILE_FORMAT);
					String overlappingOutputAttr = (String) marker.getAttribute(IJavaModelMarker.OUTPUT_OVERLAPPING_SOURCE);
					if ((flushCycleMarkers == (cycleAttr != null && cycleAttr.equals("true"))) //$NON-NLS-1$
						&& (flushOverlappingOutputMarkers == (overlappingOutputAttr != null && overlappingOutputAttr.equals("true"))) //$NON-NLS-1$
						&& (flushClasspathFormatMarkers == (classpathFileFormatAttr != null && classpathFileFormatAttr.equals("true")))){ //$NON-NLS-1$
						marker.delete();
					}
				}
			}
		}
	} catch (CoreException e) {
		// could not flush markers: not much we can do
		if (JavaModelManager.VERBOSE) {
			e.printStackTrace();
		}
	}
}
 
Example #16
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean containsMatchingProblem(IProblemLocation[] locations, int problemId) {
	if (locations != null) {
		for (int i= 0; i < locations.length; i++) {
			IProblemLocation location= locations[i];
			if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(location.getMarkerType())
					&& location.getProblemId() == problemId) {
				return true;
			}
		}
	}
	return false;
}
 
Example #17
Source File: ProblemLocation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ProblemLocation(IProblem problem) {
	fId= problem.getID();
	fArguments= problem.getArguments();
	fOffset= problem.getSourceStart();
	fLength= problem.getSourceEnd() - fOffset + 1;
	fIsError= problem.isError();
	fMarkerType= problem instanceof CategorizedProblem ? ((CategorizedProblem) problem).getMarkerType() : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER;
}
 
Example #18
Source File: ProblemLocation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ProblemLocation(int offset, int length, IJavaAnnotation annotation) {
	fId= annotation.getId();
	String[] arguments= annotation.getArguments();
	fArguments= arguments != null ? arguments : new String[0];
	fOffset= offset;
	fLength= length;
	fIsError= JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotation.getType());

	String markerType= annotation.getMarkerType();
	fMarkerType= markerType != null ? markerType : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER;
}
 
Example #19
Source File: ProjectUtils.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public static void buildProject(final IProject project) throws Exception {
    try {
        project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
        project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
    } catch (Exception e) {
        throw new Exception("Could not build project", e); // $NLX-ProjectUtils.Couldnotbuildproject-1$
    }

    IMarker[] markers = project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
    if (markers.length > 0) {
        throw new Exception("Plug-in project did not compile. Ensure that the Class and JAR files are correct."); // $NLX-ProjectUtils.PluginprojectdidnotcompileEnsuret-1$
    }
}
 
Example #20
Source File: JavaMarkerAnnotation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tells whether the given marker can be treated as a Java annotation
 * which will later be update by JDT Core problems.
 *
 * @param marker the marker
 * @return <code>true</code> if the marker can be treated as a Java annotation
 * @since 3.3.2
 */
static final boolean isJavaAnnotation(IMarker marker) {
	// Performance
	String markerType= MarkerUtilities.getMarkerType(marker);
	if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType) ||
			IJavaModelMarker.TASK_MARKER.equals(markerType) ||
			IJavaModelMarker.TRANSIENT_PROBLEM.equals(markerType) ||
		IJavaModelMarker.BUILDPATH_PROBLEM_MARKER.equals(markerType))
		return true;


	return MarkerUtilities.isMarkerType(marker, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
}
 
Example #21
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getErrorTicksFromMarkers(IResource res, int depth, ISourceReference sourceElement) throws CoreException {
	if (res == null || !res.isAccessible()) {
		return 0;
	}
	int severity= 0;
	if (sourceElement == null) {
		if (res instanceof IProject) {
			severity= res.findMaxProblemSeverity(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
			if (severity == IMarker.SEVERITY_ERROR) {
				return ERRORTICK_BUILDPATH_ERROR;
			}
			severity= res.findMaxProblemSeverity(JavaRuntime.JRE_CONTAINER_MARKER, true, IResource.DEPTH_ZERO);
			if (severity == IMarker.SEVERITY_ERROR) {
				return ERRORTICK_BUILDPATH_ERROR;
			}
		}
		severity= res.findMaxProblemSeverity(IMarker.PROBLEM, true, depth);
	} else {
		IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth);
		if (markers != null && markers.length > 0) {
			for (int i= 0; i < markers.length && (severity != IMarker.SEVERITY_ERROR); i++) {
				IMarker curr= markers[i];
				if (isMarkerInRange(curr, sourceElement)) {
					int val= curr.getAttribute(IMarker.SEVERITY, -1);
					if (val == IMarker.SEVERITY_WARNING || val == IMarker.SEVERITY_ERROR) {
						severity= val;
					}
				}
			}
		}
	}
	if (severity == IMarker.SEVERITY_ERROR) {
		return ERRORTICK_ERROR;
	} else if (severity == IMarker.SEVERITY_WARNING) {
		return ERRORTICK_WARNING;
	}
	return 0;
}
 
Example #22
Source File: DerivedResourceMarkerCopier.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private Set<IMarker> findJavaProblemMarker(IFile javaFile, int maxSeverity) throws CoreException {
	Set<IMarker> problems = newHashSet();
	for (IMarker marker : javaFile.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
			IResource.DEPTH_ZERO)) {
		if (MarkerUtilities.getSeverity(marker) >= maxSeverity) {
			problems.add(marker);
		}
	}
	return problems;
}
 
Example #23
Source File: RefactorProposalUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean containsMatchingProblem(IProblemLocationCore[] locations, int problemId) {
	if (locations != null) {
		for (IProblemLocationCore location : locations) {
			if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(location.getMarkerType()) && location.getProblemId() == problemId) {
				return true;
			}
		}
	}
	return false;
}
 
Example #24
Source File: RefactorProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
static boolean noErrorsAtLocation(IProblemLocationCore[] locations) {
	if (locations != null) {
		for (int i = 0; i < locations.length; i++) {
			IProblemLocationCore location = locations[i];
			if (location.isError()) {
				if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(location.getMarkerType()) && JavaCore.getOptionForConfigurableSeverity(location.getProblemId()) != null) {
					// continue (only drop out for severe (non-optional) errors)
				} else {
					return false;
				}
			}
		}
	}
	return true;
}
 
Example #25
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private List<IMarker> getProblemMarkers(IProgressMonitor monitor) throws CoreException {
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	List<IMarker> markers = new ArrayList<>();
	for (IProject project : projects) {
		if (monitor != null && monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		if (JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(project)) {
			continue;
		}
		IMarker[] allMarkers = project.findMarkers(null, true, IResource.DEPTH_INFINITE);
		for (IMarker marker : allMarkers) {
			if (!marker.exists() || CheckMissingNaturesListener.MARKER_TYPE.equals(marker.getType())) {
				continue;
			}
			if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(marker.getType()) || IJavaModelMarker.TASK_MARKER.equals(marker.getType())) {
				markers.add(marker);
				continue;
			}
			IResource resource = marker.getResource();
			if (project.equals(resource) || projectsManager.isBuildFile(resource)) {
				markers.add(marker);
			}
		}
	}
	return markers;
}
 
Example #26
Source File: CodeActionHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static IProblemLocationCore[] getProblemLocationCores(ICompilationUnit unit, List<Diagnostic> diagnostics) {
	IProblemLocationCore[] locations = new IProblemLocationCore[diagnostics.size()];
	for (int i = 0; i < diagnostics.size(); i++) {
		Diagnostic diagnostic = diagnostics.get(i);
		int problemId = getProblemId(diagnostic);
		int start = DiagnosticsHelper.getStartOffset(unit, diagnostic.getRange());
		int end = DiagnosticsHelper.getEndOffset(unit, diagnostic.getRange());
		boolean isError = diagnostic.getSeverity() == DiagnosticSeverity.Error;
		locations[i] = new ProblemLocationCore(start, end - start, problemId, new String[0], isError, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
	}
	return locations;
}
 
Example #27
Source File: AbstractJavaGeneratorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public IMarker[] generateAndCompile(Statechart statechart) throws Exception {
	GeneratorEntry entry = createGeneratorEntry(statechart.getName(), SRC_GEN);
	entry.setElementRef(statechart);
	IProject targetProject = getProject(entry);
	targetProject.delete(true, new NullProgressMonitor());
	targetProject = getProject(entry);
	if (!targetProject.exists()) {
		targetProject.create(new NullProgressMonitor());
		targetProject.open(new NullProgressMonitor());
	}
	IGeneratorEntryExecutor executor = new EclipseContextGeneratorExecutorLookup() {
		protected Module getContextModule() {
			return Modules.override(super.getContextModule()).with(new Module() {
				@Override
				public void configure(Binder binder) {
					binder.bind(IConsoleLogger.class).to(TestLogger.class);
				}
			});
		};
	}.createExecutor(entry, "yakindu::java");
	executor.execute(entry);
	targetProject.refreshLocal(IResource.DEPTH_INFINITE, null);
	targetProject.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
	targetProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
	IMarker[] markers = targetProject.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
			IResource.DEPTH_INFINITE);
	return markers;
}
 
Example #28
Source File: JReFrameworkerBuilder.java    From JReFrameworker with MIT License 5 votes vote down vote up
protected void clean(IProgressMonitor monitor) throws CoreException {
		// reset the incremental builder and purge files and build state from the project
		JReFrameworkerProject jrefProject = getJReFrameworkerProject();
		if(jrefProject != null){
			monitor.beginTask("Cleaning: " + jrefProject.getProject().getName(), 1);
			if(JReFrameworkerPreferences.isVerboseLoggingEnabled()) Log.info("Cleaning: " + jrefProject.getProject().getName());
			
			incrementalBuilder = new IncrementalBuilder(jrefProject);
			
			// clear the Java compiler error markers (these will be fixed and restored if they remain after building phases)
//			jrefProject.getProject().deleteMarkers(JavaCore.ERROR, true, IProject.DEPTH_INFINITE);
			jrefProject.getProject().deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IProject.DEPTH_INFINITE);

			jrefProject.disableJavaBuilder();
			try {
				jrefProject.clean();
				jrefProject.restoreOriginalClasspathEntries(); 
			} catch (Exception e) {
				Log.error("Error cleaning " + jrefProject.getProject().getName(), e);
			}
			jrefProject.enableJavaBuilder();
			
			this.forgetLastBuiltState();
			jrefProject.refresh();
			
			monitor.worked(1);
		} else {
			Log.warning(getProject().getName() + " is not a valid JReFrameworker project!");
		}
	}
 
Example #29
Source File: BuilderUtils.java    From JReFrameworker with MIT License 5 votes vote down vote up
/**
 * Returns true if the compilation unit has severe problem markers
 * 
 * Reference: https://www.ibm.com/support/knowledgecenter/en/SS4JCV_7.5.5/org.eclipse.jdt.doc.isv/guide/jdt_api_compile.htm
 * @param compilationUnit
 * @return
 * @throws CoreException
 */
public static final boolean hasSevereProblems(ICompilationUnit compilationUnit) throws CoreException {
	IResource javaSourceFile = compilationUnit.getUnderlyingResource();
	IMarker[] markers = javaSourceFile.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
	ArrayList<IMarker> severeErrorMarkers = new ArrayList<IMarker>();
	for (IMarker marker : markers) {
		Integer severityType = (Integer) marker.getAttribute(IMarker.SEVERITY);
		if (severityType.intValue() == IMarker.SEVERITY_ERROR){
			severeErrorMarkers.add(marker);
		}
	}
	return !severeErrorMarkers.isEmpty();
}
 
Example #30
Source File: JavaMarkerResolutionGenerator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public IMarkerResolution[] getResolutions(IMarker marker) {
  if (!hasResolutions(marker)) {
    return NO_RESOLUTIONS;
  }

  ICompilationUnit cu = getCompilationUnit(marker);
  if (cu != null) {
    IEditorInput input = new FileEditorInput(
        (IFile) cu.getPrimary().getResource());
    if (input != null) {
      int offset = marker.getAttribute(IMarker.CHAR_START, -1);
      int length = marker.getAttribute(IMarker.CHAR_END, -1) - offset;
      int problemId = marker.getAttribute(IJavaModelMarker.ID, -1);
      boolean isError = (marker.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR);
      String[] arguments = CorrectionEngine.getProblemArguments(marker);

      IProblemLocation location = new ProblemLocation(offset, length,
          problemId, arguments, isError, null);
      IInvocationContext context = new AssistContext(cu, offset, length);

      IJavaCompletionProposal[] proposals = new IJavaCompletionProposal[0];

      try {
        proposals = getCorrections(context, new IProblemLocation[] {location});
      } catch (CoreException e) {
        CorePluginLog.logError(e);
      }

      int nProposals = proposals.length;
      IMarkerResolution[] resolutions = new IMarkerResolution[nProposals];
      for (int i = 0; i < nProposals; i++) {
        resolutions[i] = new QuickFixCompletionProposalWrapper(cu, offset,
            length, proposals[i]);
      }
      return resolutions;
    }
  }

  return NO_RESOLUTIONS;
}