Java Code Examples for org.eclipse.xtext.validation.CheckType#FAST

The following examples show how to use org.eclipse.xtext.validation.CheckType#FAST . 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: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check if the given parameter has a valid name.
 *
 * @param parameter the parameter to test.
 * @see SARLFeatureNameValidator
 */
@Check(CheckType.FAST)
public void checkParameterName(SarlFormalParameter parameter) {
	final JvmFormalParameter inferredParam = this.associations.getJvmParameter(parameter);
	final QualifiedName name = Utils.getQualifiedName(inferredParam);
	if (isReallyDisallowedName(name)) {
		error(MessageFormat.format(
				Messages.SARLValidator_41,
				parameter.getName(), Messages.SARLValidator_14),
				parameter,
				XtendPackage.Literals.XTEND_PARAMETER__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				VARIABLE_NAME_DISALLOWED);
	} else if (this.grammarAccess.getOccurrenceKeyword().equals(parameter.getName())) {
		error(MessageFormat.format(
				Messages.SARLValidator_101,
				this.grammarAccess.getOccurrenceKeyword(), Messages.SARLValidator_14),
				parameter,
				XtendPackage.Literals.XTEND_PARAMETER__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				VARIABLE_NAME_DISALLOWED);
	}
}
 
Example 2
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check if the parameter of the bahavior unit is an event.
 *
 * @param behaviorUnit the behavior unit to test.
 */
@Check(CheckType.FAST)
public void checkBehaviorUnitEventType(SarlBehaviorUnit behaviorUnit) {
	final JvmTypeReference event = behaviorUnit.getName();
	final LightweightTypeReference ref = toLightweightTypeReference(event);
	if (ref == null || !this.inheritanceHelper.isSarlEvent(ref)) {
		error(MessageFormat.format(
				Messages.SARLValidator_75,
				event.getQualifiedName(),
				Messages.SARLValidator_62,
				this.grammarAccess.getOnKeyword()),
				event,
				null,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				TYPE_BOUNDS_MISMATCH);
	}
}
 
Example 3
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check if the supertype of the given skill is a subtype of Skill.
 *
 * @param skill the type to test.
 */
@Check(CheckType.FAST)
public void checkSuperType(SarlSkill skill) {
	final int nbSuperTypes = checkSuperTypes(
			skill,
			SARL_SKILL__EXTENDS,
			Utils.singletonList(skill.getExtends()),
			Skill.class,
			false);
	checkImplementedTypes(
			skill,
			SARL_SKILL__IMPLEMENTS,
			skill.getImplements(),
			Capacity.class,
			nbSuperTypes > 0 ? 0 : 1,
					true);
}
 
Example 4
Source File: LibraryChecksCheckImpl.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * cacheDoesntWorkGreeting.
 */
@Check(CheckType.FAST)
public void cacheDoesntWorkGreeting(final Greeting it) {
  String _qualifiedCatalogName = this.getQualifiedCatalogName();
  final String key = (_qualifiedCatalogName + ".testValue");
  try {
    Boolean _boolean = new Boolean(true);
    LibraryChecksCheckImpl.this.cache.<Boolean>put(it, key, _boolean);
    final Boolean value = LibraryChecksCheckImpl.this.cache.<Boolean>get(it, key);
    if (((value == null) || (!(value).booleanValue()))) {
      // Issue diagnostic
      libraryChecksCatalog.accept(getMessageAcceptor(), //
        it, // context EObject
        null, // EStructuralFeature
        libraryChecksCatalog.getCacheDoesntWorkMessage(("Could not read value from cache: " + value)), // Message
        libraryChecksCatalog.getCacheDoesntWorkSeverityKind(it), // Severity 
        ValidationMessageAcceptor.INSIGNIFICANT_INDEX, // Marker index
        LibraryChecksIssueCodes.CACHE_DOESNT_WORK // Issue code & data
      );
    }
  } catch (final Throwable _t) {
    if (_t instanceof Throwable) {
      final Throwable t = (Throwable)_t;
      String _message = t.getMessage();
      String _plus = ("Exception in cache access: " + _message);
      // Issue diagnostic
      libraryChecksCatalog.accept(getMessageAcceptor(), //
        it, // context EObject
        null, // EStructuralFeature
        libraryChecksCatalog.getCacheDoesntWorkMessage(_plus), // Message
        libraryChecksCatalog.getCacheDoesntWorkSeverityKind(it), // Severity 
        ValidationMessageAcceptor.INSIGNIFICANT_INDEX, // Marker index
        LibraryChecksIssueCodes.CACHE_DOESNT_WORK // Issue code & data
      );
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example 5
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that a quick fix name starts with an upper-case character.
 *
 * @param quickFix
 *          the quick fix
 */
@Check(CheckType.FAST)
public void checkQuickFixFirstUpperName(final QuickFix quickFix) {
  if (!Character.isUpperCase(quickFix.getName().charAt(0))) {
    error(NAME_SHOULD_START_WITH_A_CAPITAL, ValidPackage.Literals.QUICK_FIX__NAME, QUICK_FIX_FIRST_UPPER_NAME);
  }

}
 
Example 6
Source File: SARLValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Check if the supertype of the given event is a subtype of Event.
 *
 * @param event the type to test.
 */
@Check(CheckType.FAST)
public void checkSuperType(SarlEvent event) {
	checkSuperTypes(
			event,
			SARL_EVENT__EXTENDS,
			Utils.singletonList(event.getExtends()),
			Event.class,
			false);
}
 
Example 7
Source File: ResourceValidator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Check(CheckType.FAST)
public void checkSyntaxErrors(Statechart sc) {
	if (!(sc.eResource() instanceof AbstractSCTResource)) {
		return;
	}
	AbstractSCTResource resource = (AbstractSCTResource) sc.eResource();
	for (Map.Entry<SpecificationElement, Collection<Diagnostic>> entry : resource.getSyntaxDiagnostics().asMap()
			.entrySet()) {
		for (Diagnostic diag : entry.getValue()) {
			if (entry.getKey().eResource() != null)
				error(diag.getMessage(), entry.getKey(), null, -1);
		}
	}
}
 
Example 8
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that the description of a category ends with a dot.
 *
 * @param category
 *          the category
 */
@Check(CheckType.FAST)
public void checkCategoryDescriptionEndsWithDot(final Category category) {
  guard(category.getDescription() != null);
  if (!category.getDescription().endsWith(DOT)) {
    warning(DESCRIPTION_SHOULD_END_WITH_A_DOT, ValidPackage.Literals.CATEGORY__DESCRIPTION, CATEGORY_DESCRIPTION_ENDS_WITH_DOT);
  }
}
 
Example 9
Source File: LibraryChecksCheckImpl.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * checkCatalogIsActiveGreeting.
 */
@Check(CheckType.FAST)
public void checkCatalogIsActiveGreeting(final Greeting it) {// Issue diagnostic
  libraryChecksCatalog.accept(getMessageAcceptor(), //
    it, // context EObject
    null, // EStructuralFeature
    libraryChecksCatalog.getCheckCatalogIsActiveMessage(), // Message
    libraryChecksCatalog.getCheckCatalogIsActiveSeverityKind(it), // Severity 
    ValidationMessageAcceptor.INSIGNIFICANT_INDEX, // Marker index
    LibraryChecksIssueCodes.CHECK_CATALOG_IS_ACTIVE // Issue code & data
  );
}
 
Example 10
Source File: MarkerTypes.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static CheckType toCheckType(String markerType) {
	if (FAST_VALIDATION.equals(markerType))
		return CheckType.FAST;
	if (NORMAL_VALIDATION.equals(markerType))
		return CheckType.NORMAL;
	if (EXPENSIVE_VALIDATION.equals(markerType))
		return CheckType.EXPENSIVE;
	// default
	return CheckType.FAST;
}
 
Example 11
Source File: LanguageAwareMarkerTypeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CheckType getCheckType(String markerType) {
	if (fastValidationMarker.equals(markerType)) {
		return CheckType.FAST;
	}
	if (normalValidationMarker.equals(markerType)) {
		return CheckType.NORMAL;
	}
	if (expensiveValidationMarker.equals(markerType)) {
		return CheckType.EXPENSIVE;
	}
	return super.getCheckType(markerType);
}
 
Example 12
Source File: SARLValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Check if the supertype of the given behavior is a subtype of Behavior.
 *
 * @param behavior the type to test.
 */
@Check(CheckType.FAST)
public void checkSuperType(SarlBehavior behavior) {
	checkSuperTypes(
			behavior,
			SARL_BEHAVIOR__EXTENDS,
			Utils.singletonList(behavior.getExtends()),
			Behavior.class,
			false);
}
 
Example 13
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that a description is defined for the category.
 *
 * @param category
 *          the category
 */
@Check(CheckType.FAST)
public void checkCategoryDescription(final Category category) {
  // TODO[BAS] are descriptions really optional?
  if (category.getDescription() != null && category.getDescription().length() == 0) {
    warning(DESCRIPTION_SHOULD_NOT_BE_EMPTY, ValidPackage.Literals.CATEGORY__DESCRIPTION, CATEGORY_DESCRIPTION);
  }

}
 
Example 14
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that the label of a rule doesn't end with a dot.
 *
 * @param rule
 *          the rule
 */
@Check(CheckType.FAST)
public void checkRuleLabelEndsWithDot(final Rule rule) {
  guard(rule.getLabel().length() > 0);
  if (rule.getLabel().endsWith(DOT)) {
    warning(LABEL_SHOULD_NOT_END_WITH_A_DOT, ValidPackage.Literals.RULE__LABEL, RULE_LABEL_ENDS_WITH_DOT);
  }
}
 
Example 15
Source File: LibraryChecksCheckImpl.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * formalParametersGreeting.
 */
@Check(CheckType.FAST)
public void formalParametersGreeting(final Greeting context) {
  formalParametersImpl.runGreeting(context);
}
 
Example 16
Source File: FinalStateValidator.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Check(CheckType.FAST)
public void checkFinalStateTransitionsNoOut(FinalState finalState) {
	if ((finalState.getOutgoingTransitions().size() > 0)) {
		warning(FINAL_STATE_TRANSITIONS_NO_OUT_MSG, finalState, null, -1, FINAL_STATE_TRANSITIONS_NO_OUT_CODE);
	}
}
 
Example 17
Source File: ExitValidator.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Check(CheckType.FAST)
public void checkExtitTransitionsNoOut(Exit exit) {
	if (exit.getOutgoingTransitions().size() > 0) {
		error(EXIT_TRANSITIONS_NO_OUT_MSG, exit, null, -1, EXIT_TRANSITIONS_NO_OUT_CODE);
	}
}
 
Example 18
Source File: EntryValidator.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Check(CheckType.FAST)
public void checkEntryTransitionsNoInIfInitial(Entry entry) {
	if (entry.getIncomingTransitions().size() > 0 && entry.getKind().equals(EntryKind.INITIAL)) {
		warning(ENTRY_TRANSITIONS_NO_IN_IF_INITIAL_MSG, entry, null, -1, ENTRY_TRANSITIONS_NO_IN_IF_INITIAL_CODE);
	}
}
 
Example 19
Source File: QuickfixCrossrefTestLanguageValidator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Check(CheckType.FAST)
public void checkNameUppercase(Element ele) {
	if (ele.getName().startsWith("lowercase")) {
		warning(LOWERCASE, ele, QuickfixCrossrefPackage.Literals.ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, LOWERCASE);
	}
}
 
Example 20
Source File: ExitValidator.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Check(CheckType.FAST)
public void checkExitTransitionsMustHaveNIn(Exit exit) {
	if (exit.getIncomingTransitions().size() == 0) {
		error(EXIT_TRANSITIONS_MUST_HAVE_N_IN_MSG, exit, null, -1, EXIT_TRANSITIONS_MUST_HAVE_N_IN_CODE);
	}
}