org.eclipse.xtext.validation.Issue Java Examples

The following examples show how to use org.eclipse.xtext.validation.Issue. 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 Project: gama   Author: gama-platform   File: Main.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected void runGenerator(final String string) {
	// load the resource
	final ResourceSet set = resourceSetProvider.get();
	final Resource resource = set.getResource(URI.createURI(string, false), true);

	// validate the resource
	final List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
	if (!list.isEmpty()) {
		for (final Issue issue : list) {
			DEBUG.ERR(issue.toString());
		}
		return;
	}

	// configure and start the generator
	fileAccess.setOutputPath("src-gen/");
	generator.doGenerate(resource, fileAccess);

	DEBUG.LOG("Code generation finished.");
}
 
Example #2
Source Project: n4js   Author: eclipse   File: IssueExpectations.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Matches the expectations in the added issues matchers against the given issues.
 *
 * @param issues
 *            the issues to match the expectations against
 * @param messages
 *            if this parameter is not <code>null</code>, this method will add an explanatory message for each
 *            mismatch
 * @return <code>true</code> if and only if every expectation was matched against an issue
 */
public boolean matchesAllExpectations(Collection<Issue> issues, List<String> messages) {
	Collection<Issue> issueCopy = new LinkedList<>(issues);
	Collection<IssueMatcher> matcherCopy = new LinkedList<>(issueMatchers);

	performMatching(issueCopy, matcherCopy, messages);
	if (inverted) {
		if (matcherCopy.isEmpty()) {
			explainExpectations(issueMatchers, messages, inverted);
			return false;
		}
	} else {
		if (!matcherCopy.isEmpty()) {
			explainExpectations(matcherCopy, messages, inverted);
			return false;
		}
	}
	return false;
}
 
Example #3
Source Project: xtext-xtend   Author: eclipse   File: XtendQuickfixProvider.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Fix(IssueCodes.MISSING_OVERRIDE)
public void fixMissingOverride(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.accept(issue, "Change 'def' to 'override'", "Marks this function as 'override'", "fix_indent.gif",
			new ISemanticModification() {
				@Override
				public void apply(EObject element, IModificationContext context) throws Exception {
					replaceKeyword(grammarAccess.getMethodModifierAccess().findKeywords("def").get(0), "override", element,
							context.getXtextDocument());
					if (element instanceof XtendFunction) {
						XtendFunction function = (XtendFunction) element;
						for (XAnnotation anno : Lists.reverse(function.getAnnotations())) {
							if (anno != null && anno.getAnnotationType() != null && Override.class.getName().equals(anno.getAnnotationType().getIdentifier())) {
								ICompositeNode node = NodeModelUtils.findActualNodeFor(anno);
								context.getXtextDocument().replace(node.getOffset(), node.getLength(), "");
							}
						}
					}
				}
			});
}
 
Example #4
Source Project: dsl-devkit   Author: dsldevkit   File: FormatQuickfixProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Semantic quickfix removing the override flag for a rule.
 *
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(FormatJavaValidator.OVERRIDE_ILLEGAL_CODE)
public void removeOverride(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, "Remove override", "Remove override.", null, new IModification() {
    @Override
    public void apply(final IModificationContext context) throws BadLocationException {
      context.getXtextDocument().modify(new IUnitOfWork<Void, XtextResource>() {
        @Override
        public java.lang.Void exec(final XtextResource state) {
          Rule rule = (Rule) state.getEObject(issue.getUriToProblem().fragment());
          rule.setOverride(false);
          return null;
        }
      });
    }
  });
}
 
Example #5
Source Project: xsemantics   Author: eclipse   File: GeneratorForTests.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public List<Issue> runGenerator(String string, ResourceSet set) {
	// load the resource
	Resource resource = set.getResource(URI.createURI(string), true);

	// validate the resource
	List<Issue> issues = validator.validate(resource, CheckMode.ALL,
			CancelIndicator.NullImpl);
	if (!issues.isEmpty()) {
		for (Issue issue : issues) {
			System.err.println(issue);
		}
		if (GeneratorUtils.hasErrors(issues))
			return issues;
	}

	fileAccess.setOutputPath(outputPath);
	generator.doGenerate(resource, fileAccess);

	System.out.println("Code generation finished.");

	return issues;
}
 
Example #6
Source Project: xtext-eclipse   Author: eclipse   File: AddMarkersOperation.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
	if (!resource.exists())
		return;
	if (deleteMarkers) {
		for (String markerId : getMarkerIds()) {
			resource.deleteMarkers(markerId, true, IResource.DEPTH_INFINITE);
		}
		deleteAnnotations(); // delete annotations set by Xtext validator independently from resource markers
	}
	if (!issues.isEmpty()) {
		// update
		for (Issue issue : issues) {
			if (monitor.isCanceled())
				throw new InterruptedException();
			markerCreator.createMarker(issue, resource, markerTypeProvider.getMarkerType(issue));
		}
	}
}
 
Example #7
Source Project: xtext-xtend   Author: eclipse   File: QuickfixTestBuilder.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public QuickfixTestBuilder create(final String fileName, final String model) {
  try {
    QuickfixTestBuilder _xblockexpression = null;
    {
      final String positionMarker = this.getPositionMarker(model);
      final IFile file = this._workbenchTestHelper.createFile(fileName, model.replace(positionMarker, ""));
      this.editor = this.openEditorSafely(file);
      final IXtextDocument document = this.editor.getDocument();
      Assert.assertNotNull("Error getting document from editor", document);
      final IUnitOfWork<List<Issue>, XtextResource> _function = (XtextResource it) -> {
        return this.issues = this._iResourceValidator.validate(it, CheckMode.NORMAL_AND_FAST, CancelIndicator.NullImpl);
      };
      document.<List<Issue>>readOnly(_function);
      this.caretOffset = model.indexOf(positionMarker);
      _xblockexpression = this;
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #8
Source Project: n4js   Author: eclipse   File: N4JSPackageJsonQuickfixProviderExtension.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/** Changes the project type to {@link ProjectType#VALIDATION} */
@Fix(IssueCodes.OUTPUT_AND_SOURCES_FOLDER_NESTING)
public void changeProjectTypeToValidation(Issue issue, IssueResolutionAcceptor acceptor) {
	String validationPT = ProjectType.VALIDATION.getName().toLowerCase();
	String title = "Change project type to '" + validationPT + "'";
	String descr = "The project type '" + validationPT
			+ "' does not generate code. Hence, output and source folders can be nested.";

	accept(acceptor, issue, title, descr, null, new N4Modification() {
		@Override
		public Collection<? extends IChange> computeChanges(IModificationContext context, IMarker marker,
				int offset, int length, EObject element) throws Exception {

			Resource resource = element.eResource();
			ProjectDescription prjDescr = EcoreUtil2.getContainerOfType(element, ProjectDescription.class);
			Collection<IChange> changes = new LinkedList<>();
			changes.add(PackageJsonChangeProvider.setProjectType(resource, ProjectType.VALIDATION, prjDescr));
			return changes;
		}

		@Override
		public boolean supportsMultiApply() {
			return false;
		}
	});
}
 
Example #9
Source Project: dsl-devkit   Author: dsldevkit   File: CheckConfigurationStoreService.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the project if an associated instance can be found for given context object.
 * <p>
 * This is the default implementation. Only platform URI-based schemas are supported. Other implementations may overwrite {@link #getProject()}.
 * </p>
 *
 * @param context
 *          the context object, potentially contained by an IProject
 */
protected void setProject(final Object context) {
  if (context instanceof IProject) {
    this.project = (IProject) context;
  } else if (context instanceof IFile) {
    this.project = ((IFile) context).getProject();
  } else {
    URI uri = null;
    if (context instanceof EObject && ((EObject) context).eResource() != null) {
      uri = ((EObject) context).eResource().getURI();
    }
    if (context instanceof Issue) {
      uri = ((Issue) context).getUriToProblem();
    }
    if (uri != null && uri.isPlatform()) {
      final IFile file = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(uri.toPlatformString(true));
      this.project = file.getProject();
    }
  }
}
 
Example #10
Source Project: dsl-devkit   Author: dsldevkit   File: CheckQuickfixProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes the guard statement occurring at offending position.
 *
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.GUARDS_COME_FIRST)
@SuppressWarnings("unchecked")
public void removeGuardStatement(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, Messages.CheckQuickfixProvider_REMOVE_GUARD_LABEL, Messages.CheckQuickfixProvider_REMOVE_GUARD_DESCN, NO_IMAGE, new ISemanticModification() {
    @Override
    public void apply(final EObject element, final IModificationContext context) {
      final XGuardExpression guard = EcoreUtil2.getContainerOfType(element, XGuardExpression.class);
      if (guard != null && guard.eContainingFeature().isMany()) {
        EList<? extends EObject> holder = (EList<? extends EObject>) guard.eContainer().eGet(guard.eContainingFeature());
        if (holder != null && holder.contains(guard)) {
          holder.remove(guard);
        }
      }
    }
  });
}
 
Example #11
Source Project: xtext-core   Author: eclipse   File: ProjectManager.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void initialize(ProjectDescription description, IProjectConfig projectConfig,
		Procedure2<? super URI, ? super Iterable<Issue>> acceptor,
		IExternalContentSupport.IExternalContentProvider openedDocumentsContentProvider,
		Provider<Map<String, ResourceDescriptionsData>> indexProvider, CancelIndicator cancelIndicator) {
	this.projectDescription = description;
	this.projectConfig = projectConfig;
	this.baseDir = projectConfig.getPath();
	this.issueAcceptor = acceptor;
	this.openedDocumentsContentProvider = openedDocumentsContentProvider;
	this.indexProvider = indexProvider;
}
 
Example #12
Source Project: xtext-eclipse   Author: eclipse   File: ValidationTestHelper.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.8
 */
protected Iterable<Issue> matchIssues(final Resource resource, final EClass objectType, final String code,
		final int offset, final int length, final Severity severity, final List<Issue> validate,
		final String... messageParts) {
	// keep the original impl of #matchIssues(EObject, ..) in the call graph  
	List<EObject> contents = resource.getContents();
	if (contents.size() > 1) {
		return matchIssues(contents.get(0), objectType, code, offset, length, severity, validate, messageParts);
	}
	return doMatchIssues(resource, objectType, code, offset, length, severity, validate, messageParts);
}
 
Example #13
Source Project: n4js   Author: eclipse   File: N4JSValidationTestHelper.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Asserts the given model to not have any issues except the ones specified by the exception issue codes parameter.
 *
 * @param model
 *            The model
 * @param exceptionIssueCodes
 *            Issue codes which should be ignored
 */
public void assertNoIssuesExcept(EObject model, String... exceptionIssueCodes) {
	Resource resource = model.eResource();
	final List<Issue> issues = validate(resource);

	if (removeIssuesWithCode(issues, exceptionIssueCodes).size() > 0) {
		fail("Expected no issues, but got :" + getIssuesAsString(resource, issues, new StringBuilder()));
	}
}
 
Example #14
Source Project: solidity-ide   Author: Yakindu   File: ReferenceExamplesTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void parseReferenceFile() throws Exception {
	String content = new String(Files.readAllBytes(path));
	SolidityModel model = parseHelper.parse(content, URI.createFileURI(path.toAbsolutePath().toString()), set);
	Assert.assertNotNull("Could not load model " + path, model);
	Iterable<Issue> issues = Iterables.filter(validationHelper.validate(model), new Predicate<Issue>() {
		@Override
		public boolean apply(Issue input) {
			return Severity.ERROR == input.getSeverity();
		}
	});
	if (!isEmpty(issues))
		fail("Errors in resource: " + path + ": " + issues);

}
 
Example #15
Source Project: gef   Author: eclipse   File: DotQuickfixProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void provideQuickfixesForInvalidStyleItem(Issue issue,
		IssueResolutionAcceptor acceptor) {

	String[] issueData = issue.getData();

	String invalidValue = issueData[1];
	DotAttributes.Context attributeContext = DotAttributes.Context
			.valueOf(issueData[2]);
	switch (attributeContext) {
	case GRAPH:
	case SUBGRAPH:
	case CLUSTER:
		provideQuickfixesForMultipleAttributeValue(invalidValue,
				ClusterStyle.VALUES, "graph style", //$NON-NLS-1$
				issue, acceptor);
		break;
	case NODE:
		provideQuickfixesForMultipleAttributeValue(invalidValue,
				NodeStyle.VALUES, "node style", //$NON-NLS-1$
				issue, acceptor);
		break;
	case EDGE:
		provideQuickfixesForMultipleAttributeValue(invalidValue,
				EdgeStyle.VALUES, "edge style", //$NON-NLS-1$
				issue, acceptor);
		break;
	default:
		break;
	}
}
 
Example #16
Source Project: sarl   Author: sarl   File: SarlBatchCompiler.java    License: 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 #17
Source Project: xtext-core   Author: eclipse   File: ReducedXtextResourceValidatorTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGrammarLinkingErrors() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test.Lang with org.eclipse.xtext.common.Trminals");
  _builder.newLine();
  _builder.append("import \'http://test\' as test");
  _builder.newLine();
  _builder.append("Root returns test::Foo : name=\'foo\';");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final List<Issue> issues = this.resourceValidator.validate(this.getErroneousResource(grammarAsString), CheckMode.NORMAL_AND_FAST, CancelIndicator.NullImpl);
  Assert.assertEquals(issues.toString(), 1, issues.size());
  Assert.assertTrue(issues.toString(), IterableExtensions.<Issue>head(issues).getMessage().contains("Trminals"));
}
 
Example #18
Source Project: gef   Author: eclipse   File: DotHtmlLabelQuickfixProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Fix(DotHtmlLabelValidator.HTML_ATTRIBUTE_INVALID_ATTRIBUTE_NAME)
public void fixInvalidAttributeName(final Issue issue,
		IssueResolutionAcceptor acceptor) {
	String[] issueData = issue.getData();
	String tagName = issueData[2];
	String invalidAttribute = issueData[3];

	Set<String> validAttributes = DotHtmlLabelHelper.getValidAttributes()
			.get(tagName.toUpperCase());

	List<String> validAttributesSorted = new ArrayList<>(validAttributes);
	Collections.sort(validAttributesSorted);

	for (String validAttribute : validAttributesSorted) {
		String label = "Change to '" + validAttribute + "'."; //$NON-NLS-1$ //$NON-NLS-2$
		String description = "Change '" //$NON-NLS-1$
				+ invalidAttribute + "' to '" + validAttribute + "'."; //$NON-NLS-1$ //$NON-NLS-2$
		acceptor.accept(issue, label, description, null,
				new ISemanticModification() {

					@Override
					public void apply(EObject element,
							IModificationContext context) throws Exception {
						if (element instanceof HtmlAttr) {
							HtmlAttr htmlAttr = (HtmlAttr) element;
							htmlAttr.setName(validAttribute);
						}
					}
				});
	}
}
 
Example #19
Source Project: xtext-extras   Author: eclipse   File: TypeConformanceValidatorTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNullToPrimitiveInNestedIf() throws Exception {
	String expressionAsString = "{ var boolean b = if (Boolean.TRUE) if (Boolean.TRUE) null else '' b.toString }";
	XExpression xExpression = expression(expressionAsString, false);
	List<Issue> issues = helper.validate(xExpression);
	assertEquals(issues.toString(), 2, issues.size());
}
 
Example #20
Source Project: gef   Author: eclipse   File: DotQuickfixProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Fix(DotAttributes.COLORSCHEME__GCNE)
public void fixColorschemeAttributeValue(final Issue issue,
		IssueResolutionAcceptor acceptor) {
	// TODO: use "graph colorscheme", "node colorscheme", "edge colorscheme"
	// as suffix.
	String invalidValue = issue.getData()[0];
	provideQuickfixes(invalidValue, DotColors.getColorSchemes(),
			"colorscheme", //$NON-NLS-1$
			issue, acceptor);
}
 
Example #21
Source Project: xtext-xtend   Author: eclipse   File: XtendQuickfixProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.CONFLICTING_DEFAULT_METHODS)
public void overrideDefaultMethod(final Issue issue, IssueResolutionAcceptor acceptor) {
	if (issue.getData() != null) {
		for (String data : issue.getData()) {
			int separatorIndex = data.indexOf('|');
			if (separatorIndex > 0) {
				String interfaceName = data.substring(0, separatorIndex);
				String uri = data.substring(separatorIndex + 1);
				doOverrideMethods(issue, acceptor, "Override conflicting method of type " + interfaceName,
						new String[] {uri});
			}
		}
	}
}
 
Example #22
Source Project: sarl   Author: sarl   File: ProtectKeywordModification.java    License: Apache License 2.0 5 votes vote down vote up
/** Create the quick fix if needed.
 *
 * @param provider the quick fix provider.
 * @param issue the issue to fix.
 * @param acceptor the quick fix acceptor.
 */
public static void accept(SARLQuickfixProvider provider, Issue issue, IssueResolutionAcceptor acceptor) {
	final String[] data = issue.getData();
	if (data != null && data.length > 1 && !Strings.isEmpty(data[0]) && !Strings.isEmpty(data[1])) {
		final ProtectKeywordModification modification = new ProtectKeywordModification(data[0], data[1]);
		modification.setIssue(issue);
		modification.setTools(provider);
		acceptor.accept(issue,
				MessageFormat.format(Messages.ProtectKeywordModification_0, data[1]),
				MessageFormat.format(Messages.ProtectKeywordModification_1, data[1]),
				JavaPluginImages.IMG_CORRECTION_RENAME,
				modification,
				IProposalRelevance.RENAME_REFACTORING_QUICK_FIX);
	}
}
 
Example #23
Source Project: n4js   Author: eclipse   File: N4JSResourceValidator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private static Issue createFileIssue(Resource res, String message, String issueCode) {
	final Issue.IssueImpl issue = new Issue.IssueImpl();
	issue.setCode(issueCode);
	issue.setSeverity(IssueCodes.getDefaultSeverity(issueCode));
	issue.setMessage(message);
	issue.setUriToProblem(res.getURI());
	issue.setType(CheckType.FAST); // using CheckType.FAST is important to get proper marker update behavior in ...
	// ... the editor between persisted and dirty states!
	issue.setOffset(0);
	issue.setLength(0);
	issue.setLineNumber(0);
	issue.setColumn(0);
	return issue;
}
 
Example #24
Source Project: n4js   Author: eclipse   File: IssueMatcher.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a list of explanations for each mismatched property matcher for the given issue.
 *
 * @param issue
 *            the issue to match against
 * @return a list of explanations
 */
public List<String> explainMismatch(Issue issue) {
	Objects.requireNonNull(issue);

	List<String> result = new LinkedList<>();
	for (IssuePropertyMatcher propertyMatcher : propertyMatchers) {
		if (!propertyMatcher.matches(issue))
			result.add(propertyMatcher.getMessage(issue));
	}
	return result;
}
 
Example #25
Source Project: xtext-eclipse   Author: eclipse   File: WorkbenchMarkerResolutionAdapter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public IssueResolution resolution(IMarker marker) {
	if (!marker.exists()) {
		return null;
	}
	Issue issue = issueUtil.createIssue(marker);
	List<IssueResolution> resolutions = resolutionsGenerator.getResolutionProvider().getResolutions(issue);
	Optional<IssueResolution> issueResolution = resolutions.stream()
			.filter(resolution -> isSameResolution(resolution, primaryResolution)).findFirst();
	if (!issueResolution.isPresent()) {
		LOG.warn("Resolution missing for " + issue.getCode());
		return null;
	}
	return issueResolution.get();
}
 
Example #26
Source Project: n4js   Author: eclipse   File: IssueExpectations.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void explainIssues(Collection<Issue> unmatchedIssues, List<String> messages, boolean expected) {
	if (messages != null) {
		for (Issue issue : unmatchedIssues) {
			messages.add((expected ? "Expected issue: " : "Unexpected issue: ") + issue);
		}
	}
}
 
Example #27
Source Project: xtext-eclipse   Author: eclipse   File: XtextGrammarQuickfixProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Fix(INVALID_METAMODEL_NAME)
public void fixInvalidMetaModelName(final Issue issue, IssueResolutionAcceptor acceptor) {
	final String metaModelName = issue.getData()[0];
	acceptor.accept(issue, "Fix metamodel name '" + metaModelName + "'", "Fix metamodel name '" + metaModelName
			+ "'", NULL_QUICKFIX_IMAGE, new IModification() {
		@Override
		public void apply(IModificationContext context) throws Exception {
			context.getXtextDocument().replace(issue.getOffset(), issue.getLength(), Strings.toFirstLower(metaModelName));
		}
	});
}
 
Example #28
Source Project: n4js   Author: eclipse   File: StringPropertyMatcher.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean matches(Issue issue) {
	String actualValue = safeGetValue(getActualValue.apply(issue));
	switch (mode) {
	case StartsWith:
		return actualValue.startsWith(expectedPattern);
	case EndsWith:
		return actualValue.endsWith(expectedPattern);
	case Equals:
		return actualValue.equals(expectedPattern);
	}

	// This should never happen lest we extended the enum without adding a case above!
	throw new IllegalStateException("Unknown string property matching mode: " + mode);
}
 
Example #29
Source Project: xtext-eclipse   Author: eclipse   File: IssueUtil.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public Issue getIssueFromAnnotation(Annotation annotation) {
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation xtextAnnotation = (XtextAnnotation) annotation;
		return xtextAnnotation.getIssue();
	} else if(annotation instanceof MarkerAnnotation) {
		MarkerAnnotation markerAnnotation = (MarkerAnnotation)annotation;
		return createIssue(markerAnnotation.getMarker());
	} else
		return null;
}
 
Example #30
Source Project: xtext-xtend   Author: eclipse   File: CreateXtendTypeQuickfixes.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void newLocalXtendAnnotationQuickfix(String typeName, XtextResource resource, Issue issue,
		IssueResolutionAcceptor issueResolutionAcceptor) {
	EObject eObject = resource.getEObject(issue.getUriToProblem().fragment());
	XtendTypeDeclaration xtendType = getAnnotationTarget(eObject);
	if(xtendType != null) {
		JvmDeclaredType inferredType = associations.getInferredType(xtendType);
		if(inferredType != null) {
			AbstractAnnotationBuilder annotationBuilder = codeBuilderFactory.createAnnotationBuilder(inferredType);
			annotationBuilder.setAnnotationName(typeName);
			annotationBuilder.setVisibility(JvmVisibility.PUBLIC);
			annotationBuilder.setContext(xtendType);
			codeBuilderQuickfix.addQuickfix(annotationBuilder, "Create local Xtend annotation '@" + typeName + "'", issue, issueResolutionAcceptor);
		}
	}
}