Java Code Examples for org.eclipse.xtext.validation.Issue#getUriToProblem()

The following examples show how to use org.eclipse.xtext.validation.Issue#getUriToProblem() . 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: LSPIssue.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Copy constructor
 */
public LSPIssue(Issue copyFrom) {
	this();
	if (copyFrom.getOffset() != null)
		this.setOffset(copyFrom.getOffset());
	if (copyFrom.getLength() != null)
		this.setLength(copyFrom.getLength());
	if (copyFrom.getColumn() != null)
		this.setColumn(copyFrom.getColumn());
	if (copyFrom.getLineNumber() != null)
		this.setLineNumber(copyFrom.getLineNumber());
	if (copyFrom.getCode() != null)
		this.setCode(copyFrom.getCode());
	if (copyFrom.getMessage() != null)
		this.setMessage(copyFrom.getMessage());
	if (copyFrom.getUriToProblem() != null)
		this.setUriToProblem(copyFrom.getUriToProblem());
	if (copyFrom.getSeverity() != null)
		this.setSeverity(copyFrom.getSeverity());
	if (copyFrom.getType() != null)
		this.setType(copyFrom.getType());
	if (copyFrom.getData() != null)
		this.setData(copyFrom.getData());
}
 
Example 2
Source File: ElementIssueProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public void attachData(Resource resource) {
	if (findDataAdapter(resource) != null) {
		return;
	}
	List<Issue> issues = collectIssues(resource);
	Data adapter = new Data();
	for (Issue issue : issues) {
		URI uriToProblem = issue.getUriToProblem();
		if (uriToProblem != null && uriToProblem.trimFragment().equals(resource.getURI())) {
			EObject erroneousElement = resource.getEObject(uriToProblem.fragment());
			adapter.addIssue(erroneousElement, issue);
			for(EObject jvmElement: associations.getJvmElements(erroneousElement)) {
				adapter.addIssue(jvmElement, issue);
			}
		}
	}
	resource.eAdapters().add(adapter);
}
 
Example 3
Source File: MarkerCreator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.0
 */
protected void setMarkerAttributes(Issue issue, IResource resource, IMarker marker) throws CoreException {
	String lineNR = "";
	if (issue.getLineNumber() != null) {
		lineNR = "line: " + issue.getLineNumber() + " ";
	}
	marker.setAttribute(IMarker.LOCATION, lineNR + resource.getFullPath().toString());
	marker.setAttribute(Issue.CODE_KEY, issue.getCode());		
	marker.setAttribute(IMarker.SEVERITY, getSeverity(issue));
	marker.setAttribute(IMarker.CHAR_START, issue.getOffset());
	if(issue.getOffset() != null && issue.getLength() != null)
		marker.setAttribute(IMarker.CHAR_END, issue.getOffset()+issue.getLength());
	marker.setAttribute(IMarker.LINE_NUMBER, issue.getLineNumber());
	marker.setAttribute(Issue.COLUMN_KEY, issue.getColumn());
	marker.setAttribute(IMarker.MESSAGE, issue.getMessage());

	if (issue.getUriToProblem()!=null) 
		marker.setAttribute(Issue.URI_KEY, issue.getUriToProblem().toString());
	if(issue.getData() != null && issue.getData().length > 0) {
		marker.setAttribute(Issue.DATA_KEY, Strings.pack(issue.getData()));
	}
	if (resolutionProvider != null && resolutionProvider.hasResolutionFor(issue.getCode())) {
		marker.setAttribute(FIXABLE_KEY, true);
	}
}
 
Example 4
Source File: ValidationTestHelper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.8
 */
protected StringBuilder doGetIssuesAsString(Resource resource, final Iterable<Issue> issues, StringBuilder result) {
	for (Issue issue : issues) {
		URI uri = issue.getUriToProblem();
		result.append(issue.getSeverity());
		result.append(" (");
		result.append(issue.getCode());
		result.append(") '");
		result.append(issue.getMessage());
		result.append("'");
		if (uri != null) {
			EObject eObject = resource.getResourceSet().getEObject(uri, true);
			result.append(" on ");
			result.append(eObject.eClass().getName());
		}
		result.append(", offset " + issue.getOffset() + ", length " + issue.getLength());
		result.append("\n");
	}
	return result;
}
 
Example 5
Source File: ValidationTestHelper.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected StringBuilder doGetIssuesAsString(Resource resource, final Iterable<Issue> issues, StringBuilder result) {
	for (Issue issue : issues) {
		URI uri = issue.getUriToProblem();
		result.append(issue.getSeverity());
		result.append(" (");
		result.append(issue.getCode());
		result.append(") '");
		result.append(issue.getMessage());
		result.append("'");
		if (uri != null) {
			EObject eObject = resource.getResourceSet().getEObject(uri, true);
			result.append(" on ");
			result.append(eObject.eClass().getName());
		}
		result.append(", offset " + issue.getOffset() + ", length " + issue.getLength());
		result.append("\n");
	}
	return result;
}
 
Example 6
Source File: SarlBatchCompiler.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create a message for the issue.
 *
 * @param issue the issue.
 * @return the message.
 */
protected String createIssueMessage(Issue issue) {
	final IssueMessageFormatter formatter = getIssueMessageFormatter();
	final org.eclipse.emf.common.util.URI uriToProblem = issue.getUriToProblem();
	if (formatter != null) {
		final String message = formatter.format(issue, uriToProblem);
		if (message != null) {
			return message;
		}
	}
	if (uriToProblem != null) {
		final org.eclipse.emf.common.util.URI resourceUri = uriToProblem.trimFragment();
		return MessageFormat.format(Messages.SarlBatchCompiler_4,
				issue.getSeverity(), resourceUri.lastSegment(),
				resourceUri.isFile() ? resourceUri.toFileString() : "", //$NON-NLS-1$
						issue.getLineNumber(), issue.getColumn(), issue.getCode(), issue.getMessage());
	}
	return MessageFormat.format(Messages.SarlBatchCompiler_5,
			issue.getSeverity(), issue.getLineNumber(), issue.getColumn(), issue.getCode(), issue.getMessage());
}
 
Example 7
Source File: TestIssues.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies the string representation of issues.
 *
 * @param model the parsed model.
 * @param issues the issues.
 * @param result the result.
 * @return {@code result}.
 */
public static StringBuilder getIssuesAsString(EObject model, Iterable<Issue> issues, StringBuilder result) {
	for(Issue issue : issues) {
		final URI uri = issue.getUriToProblem();
		result.append(issue.getSeverity());
		result.append(" (");
		result.append(issue.getCode());
		result.append(") '");
		result.append(issue.getMessage());
		result.append("'");
		if (uri != null) {
			EObject eObject = model.eResource().getResourceSet().getEObject(uri, true);
			result.append(" on ");
			result.append(eObject.eClass().getName());
		}
		result.append("\n");
	}
	return result;
}
 
Example 8
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.WRONG_FILE)
public void fixWrongFileRenameClass(final Issue issue, final IssueResolutionAcceptor acceptor) {
	URI uri = issue.getUriToProblem();
	String className = uri.trimFileExtension().lastSegment();
	String label = String.format("Rename class to '%s'", className);
	acceptor.accept(issue, label, label, null, (element, context) -> {
		context.getXtextDocument().modify(resource -> {
			IRenameElementContext renameContext = renameContextFactory.createRenameElementContext(element, null,
					new TextSelection(context.getXtextDocument(), issue.getOffset(), issue.getLength()), resource);
			final ProcessorBasedRefactoring refactoring = renameRefactoringProvider.getRenameRefactoring(renameContext);
			((RenameElementProcessor) refactoring.getProcessor()).setNewName(className);
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, monitor -> {
				try {
					if (!refactoring.checkFinalConditions(monitor).isOK())
						return;
					Change change = refactoring.createChange(monitor);
					change.initializeValidationData(monitor);
					PerformChangeOperation performChangeOperation = new PerformChangeOperation(change);
					performChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), refactoring.getName());
					performChangeOperation.setSchedulingRule(ResourcesPlugin.getWorkspace().getRoot());
					performChangeOperation.run(monitor);
				} catch (CoreException e) {
					logger.error(e);
				}
			});
			return null;
		});
	});
}
 
Example 9
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private StringBuilder createIssueMessage(Issue issue) {
	StringBuilder issueBuilder = new StringBuilder("\n");
	issueBuilder.append(issue.getSeverity()).append(": \t");
	URI uriToProblem = issue.getUriToProblem();
	if (uriToProblem != null) {
		URI resourceUri = uriToProblem.trimFragment();
		issueBuilder.append(resourceUri.lastSegment()).append(" - ");
		if (resourceUri.isFile()) {
			issueBuilder.append(resourceUri.toFileString());
		}
	}
	issueBuilder.append("\n").append(issue.getLineNumber()).append(": ").append(issue.getMessage());
	return issueBuilder;
}
 
Example 10
Source File: SarlBatchCompiler.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("checkstyle:npathcomplexity")
public int compare(Issue issue1, Issue issue2) {
	if (issue1 == issue2) {
		return 0;
	}
	if (issue1 == null) {
		return -1;
	}
	if (issue2 == null) {
		return 1;
	}
	final org.eclipse.emf.common.util.URI u1 = issue1.getUriToProblem();
	final org.eclipse.emf.common.util.URI u2 = issue2.getUriToProblem();
	int cmp = 0;
	if (u1 != u2 && u1 != null && u2 != null) {
		cmp = u1.toFileString().compareTo(u2.toFileString());
	}
	if (cmp != 0) {
		return cmp;
	}
	cmp = compareSafe(issue1.getLineNumber(), issue2.getLineNumber());
	if (cmp != 0) {
		return cmp;
	}
	cmp = compareSafe(issue1.getColumn(), issue2.getColumn());
	if (cmp != 0) {
		return cmp;
	}
	cmp = compareSafe(issue1.getSeverity(), issue2.getSeverity());
	if (cmp != 0) {
		return cmp;
	}
	cmp = compareSafe(issue1.getMessage(), issue2.getMessage());
	if (cmp != 0) {
		return cmp;
	}
	return Integer.compare(System.identityHashCode(issue1), System.identityHashCode(issue2));
}
 
Example 11
Source File: N4JSPackageJsonQuickfixProviderExtension.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/** Installs a specific npm */
@Fix(IssueCodes.NON_EXISTING_PROJECT)
@Fix(IssueCodes.NO_MATCHING_VERSION)
@Fix(IssueCodes.MISSING_YARN_WORKSPACE)
public void installMissingNPM(Issue issue, IssueResolutionAcceptor acceptor) {
	final String[] userData = issue.getData();
	final String packageName = userData[0];
	final String versionRequirement = userData[1];
	final String msgAtVersion = Strings.isNullOrEmpty(versionRequirement) ? "" : "@" + versionRequirement;
	final String label = "Install npm package " + packageName + msgAtVersion;
	final String description = "Calls npm/yarn to install the missing npm package into the workspace.";
	final String errMsg = "Error while uninstalling npm dependency: '" + packageName + "'.";

	N4Modification modification = new N4Modification() {
		@Override
		public Collection<? extends IChange> computeChanges(IModificationContext context, final IMarker marker,
				int offset, int length, EObject element) throws Exception {

			Function<IProgressMonitor, IStatus> registerFunction = new Function<>() {
				@Override
				public IStatus apply(IProgressMonitor monitor) {
					final URI uri = issue.getUriToProblem();
					final IN4JSProject containingProject = n4jsCore.findProject(uri).orNull();
					if (containingProject == null) {
						return statusHelper.createError("cannot find containing project");
					}
					FileURI targetLocation = containingProject.getLocation().toFileURI();
					Map<N4JSProjectName, NPMVersionRequirement> installedNpms = new HashMap<>();
					NPMVersionRequirement versionReq = semverHelper.parse(versionRequirement);
					N4JSProjectName typesafePackageName = new N4JSProjectName(packageName);
					installedNpms.put(typesafePackageName, versionReq);
					return libraryManager.installNPM(typesafePackageName, versionRequirement, targetLocation,
							monitor);
				}
			};
			wrapWithMonitor(label, errMsg, registerFunction);
			return Collections.emptyList();
		}
	};

	accept(acceptor, issue, label, description, null, modification);
}
 
Example 12
Source File: IssueResolutionAcceptor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void accept(Issue issue, String label, String description, String image, ISemanticModification semanticModification) {
	IModification modificationWrapper = new SemanticModificationWrapper(issue.getUriToProblem(), semanticModification);
	issueResolutions.add(new IssueResolution(label, description, image, modificationContextFactory.createModificationContext(issue),
			modificationWrapper));
}
 
Example 13
Source File: IssueResolutionAcceptor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.4
 */
public void accept(Issue issue, String label, String description, String image, ISemanticModification semanticModification, int relevance) {
	IModification modificationWrapper = new SemanticModificationWrapper(issue.getUriToProblem(), semanticModification);
	issueResolutions.add(new IssueResolution(label, description, image, modificationContextFactory.createModificationContext(issue),
			modificationWrapper, relevance));
}
 
Example 14
Source File: CoreIssueResolutionAcceptor.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
public void accept(final Issue issue, final String label, final String description, final String image, final ICoreSemanticModification semanticModification) {
  CoreSemanticModificationWrapper modificationWrapper = new CoreSemanticModificationWrapper(issue.getUriToProblem(), semanticModification);
  issueResolutions.add(new CoreIssueResolution(label, description, image, modificationContextFactory.createModificationContext(issue), modificationWrapper));
}
 
Example 15
Source File: IssueMatcher.java    From n4js with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a builder for an issue's URI.
 *
 * @see Issue#getUriToProblem()
 *
 * @return an instance of {@link URIPropertyMatcher} that can be used to specify the actual expectation
 */
public URIPropertyMatcherBuilder uri() {
	return new URIPropertyMatcherBuilder(this, "URI", (Issue issue) -> issue.getUriToProblem());
}