org.eclipse.xtext.validation.CheckType Java Examples

The following examples show how to use org.eclipse.xtext.validation.CheckType. 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 the types of the parameters of the "fires" statement.
 *
 * @param action the signature that contains the "fires" statement.
 */
@Check(CheckType.FAST)
public void checkActionFires(SarlAction action) {
	for (final JvmTypeReference event : action.getFiredEvents()) {
		final LightweightTypeReference ref = toLightweightTypeReference(event);
		if (ref != null && !this.inheritanceHelper.isSarlEvent(ref)) {
			error(MessageFormat.format(
					Messages.SARLValidator_57,
					event.getQualifiedName(),
					Messages.SARLValidator_62,
					this.grammarAccess.getFiresKeyword()),
					event,
					null,
					ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
					INVALID_FIRING_EVENT_TYPE,
					event.getSimpleName());
		}
	}
}
 
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: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check the type of the capacity uses.
 *
 * @param uses the capacity uses.
 */
@Check(CheckType.FAST)
public void checkCapacityTypeForUses(SarlCapacityUses uses) {
	for (final JvmParameterizedTypeReference usedType : uses.getCapacities()) {
		final LightweightTypeReference ref = toLightweightTypeReference(usedType);
		if (ref != null && !this.inheritanceHelper.isSarlCapacity(ref)) {
			error(MessageFormat.format(
					Messages.SARLValidator_57,
					usedType.getQualifiedName(),
					Messages.SARLValidator_58,
					this.grammarAccess.getUsesKeyword()),
					usedType,
					null,
					ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
					INVALID_CAPACITY_TYPE,
					usedType.getSimpleName());
		}
	}
}
 
Example #5
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check if the closure parameters have a valid name.
 *
 * @param closure the closure to test.
 * @see SARLFeatureNameValidator
 */
@Check(CheckType.NORMAL)
public void checkParameterName(XClosure closure) {
	int index = 0;
	for (final JvmFormalParameter param : closure.getDeclaredFormalParameters()) {
		final QualifiedName name = Utils.getQualifiedName(param);
		if (isReallyDisallowedName(name)) {
			error(MessageFormat.format(
					Messages.SARLValidator_41,
					param.getName(), Messages.SARLValidator_14),
					closure,
					XbasePackage.Literals.XCLOSURE__DECLARED_FORMAL_PARAMETERS,
					index,
					VARIABLE_NAME_DISALLOWED);
		} else if (this.grammarAccess.getOccurrenceKeyword().equals(param.getName())) {
			error(MessageFormat.format(
					Messages.SARLValidator_101,
					this.grammarAccess.getOccurrenceKeyword(), Messages.SARLValidator_14),
					closure,
					XbasePackage.Literals.XCLOSURE__DECLARED_FORMAL_PARAMETERS,
					index,
					VARIABLE_NAME_DISALLOWED);
		}
		++index;
	}
}
 
Example #6
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check if the given action has a valid name.
 *
 * @param action the action to test.
 * @see SARLFeatureNameValidator
 */
@Check(CheckType.FAST)
public void checkActionName(SarlAction action) {
	final JvmOperation inferredOperation = this.associations.getDirectlyInferredOperation(action);
	final QualifiedName name = QualifiedName.create(inferredOperation.getQualifiedName('.').split("\\.")); //$NON-NLS-1$
	if (isReallyDisallowedName(name)) {
		final String validName = Utils.fixHiddenMember(action.getName());
		error(MessageFormat.format(
				Messages.SARLValidator_39,
				action.getName()),
				action,
				XTEND_FUNCTION__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				INVALID_MEMBER_NAME,
				validName);
	} else if (!isIgnored(DISCOURAGED_FUNCTION_NAME)
			&& this.featureNames_.isDiscouragedName(name)) {
		warning(MessageFormat.format(
				Messages.SARLValidator_39,
				action.getName()),
				action,
				XTEND_FUNCTION__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				DISCOURAGED_FUNCTION_NAME);
	}
}
 
Example #7
Source File: QuickfixCrossrefTestLanguageValidator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Check(CheckType.FAST)
public void checkBadNames(Main main) {
	Resource res = main.eResource();
	for (Element root : main.getElements()) {
		List<String> fragments = Lists.newArrayList();
		for (Element ele : EcoreUtil2.getAllContentsOfType(root, Element.class)) {
			if ("badname".equals(ele.getName())) {
				fragments.add(res.getURIFragment(ele));
			}
		}
		if (!fragments.isEmpty()) {
			warning(BAD_NAME_IN_SUBELEMENTS, root, QuickfixCrossrefPackage.Literals.ELEMENT__NAME,
					ValidationMessageAcceptor.INSIGNIFICANT_INDEX, BAD_NAME_IN_SUBELEMENTS, Joiner.on(";").join(fragments));
		}
	}
}
 
Example #8
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check if the given field has a valid name.
 *
 * @param field the field to test.
 * @see SARLFeatureNameValidator
 */
@Check(CheckType.FAST)
public void checkFieldName(SarlField field) {
	final JvmField inferredField = this.associations.getJvmField(field);
	final QualifiedName name = Utils.getQualifiedName(inferredField);
	if (isReallyDisallowedName(name)) {
		final String validName = Utils.fixHiddenMember(field.getName());
		error(MessageFormat.format(
				Messages.SARLValidator_41,
				field.getName(), Messages.SARLValidator_100),
				field,
				XTEND_FIELD__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				VARIABLE_NAME_DISALLOWED,
				validName);
	} else if (this.grammarAccess.getOccurrenceKeyword().equals(field.getName())) {
		error(MessageFormat.format(
				Messages.SARLValidator_101,
				this.grammarAccess.getOccurrenceKeyword(), Messages.SARLValidator_100),
				field,
				XTEND_FIELD__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				VARIABLE_NAME_DISALLOWED);
	}
}
 
Example #9
Source File: SynchronizationValidator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Check(CheckType.FAST)
public void checkSynchronizationTransitionsRequireMultipleInOrMultipleOut(Synchronization sync) {
	int in = sync.getIncomingTransitions().size();
	int out = sync.getOutgoingTransitions().size();
	if (in < 2 && out < 2) {
		error(SYNCHRONIZATION_TRANSITIONS_REQUIRE_MULTIPLE_IN_OR_MULTIPLE_OUT_MSG, sync, null, -1,
				SYNCHRONIZATION_TRANSITIONS_REQUIRE_MULTIPLE_IN_OR_MULTIPLE_OUT_CODE);
	}
}
 
Example #10
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 category doesn't end with a dot.
 *
 * @param category
 *          the category
 */
@Check(CheckType.FAST)
public void checkCategoryLabelEndsWithDot(final Category category) {
  guard(category.getLabel().length() > 0);
  if (category.getLabel().endsWith(DOT)) {
    warning(LABEL_SHOULD_NOT_END_WITH_A_DOT, ValidPackage.Literals.CATEGORY__LABEL, CATEGORY_LABEL_ENDS_WITH_DOT);
  }
}
 
Example #11
Source File: TypesJavaValidator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Check(CheckType.FAST)
public void checkOptionalArgumentsAreLast(Operation op) {
	boolean foundOptional = false;
	for (Parameter p : op.getParameters()) {
		if (foundOptional && !p.isOptional()) {
			error(ERROR_OPTIONAL_MUST_BE_LAST_MSG, p, null, ERROR_OPTIONAL_MUST_BE_LAST_CODE);
		}
		if (p.isOptional()) {
			foundOptional = true;
		}
	}
}
 
Example #12
Source File: ErrorToDiagnoticTranslator.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private CheckType getType(final CheckMode mode) {
	if (mode == CheckMode.FAST_ONLY) {
		return CheckType.FAST;
	} else if (mode == CheckMode.EXPENSIVE_ONLY) {
		return CheckType.EXPENSIVE;
	} else if (mode == CheckMode.ALL) {
		return CheckType.FAST;
	} else if (mode == CheckMode.NORMAL_AND_FAST) {
		return CheckType.FAST;
	} else if (mode == CheckMode.NORMAL_ONLY) {
		return CheckType.NORMAL;
	} else {
		return CheckType.FAST;
	}
}
 
Example #13
Source File: SCTMarkerTypeProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CheckType getCheckType(String markerType) {
	if (SCTMarkerType.FAST_VALIDATION.equals(markerType))
		return CheckType.FAST;
	if (SCTMarkerType.NORMAL_VALIDATION.equals(markerType))
		return CheckType.NORMAL;
	if (SCTMarkerType.EXPENSIVE_VALIDATION.equals(markerType))
		return CheckType.EXPENSIVE;
	// default
	return CheckType.FAST;
}
 
Example #14
Source File: SARLValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Check if the supertype of the given capacity is a subtype of Capacity.
 *
 * @param capacity the type to test.
 */
@Check(CheckType.FAST)
public void checkSuperTypes(SarlCapacity capacity) {
	checkSuperTypes(
			capacity,
			SARL_CAPACITY__EXTENDS,
			capacity.getExtends(),
			Capacity.class,
			false);
}
 
Example #15
Source File: SARLValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Check if the call is forbidden.
 *
 * <p>One example of a forbidden feature is {@link System#exit(int)}.
 *
 * @param expression the expression.
 */
@Check(CheckType.FAST)
public void checkForbiddenCalls(XAbstractFeatureCall expression) {
	if (this.featureCallValidator.isDisallowedCall(expression)) {
		error(
				MessageFormat.format(
						Messages.SARLValidator_36,
						expression.getFeature().getIdentifier()),
				expression,
				null,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				FORBIDDEN_REFERENCE);
	}
}
 
Example #16
Source File: SARLValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Check if the call is discouraged.
 *
 * <p>One example of a discouraged feature is {@link System#err}.
 *
 * @param expression the expression.
 */
@Check(CheckType.FAST)
public void checkDiscouragedCalls(XAbstractFeatureCall expression) {
	if (!isIgnored(DISCOURAGED_REFERENCE)
			&& this.featureCallValidator.isDiscouragedCall(expression)) {
		addIssue(
				MessageFormat.format(Messages.SARLValidator_37,
						expression.getConcreteSyntaxFeatureName()),
				expression,
				DISCOURAGED_REFERENCE);
	}
}
 
Example #17
Source File: SynchronizationValidator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Check(CheckType.FAST)
public void checkSynchronizationTransitionsRequireNOut(Synchronization sync) {
	if (sync.getOutgoingTransitions().size() == 0) {
		error(SYNCHRONIZATION_TRANSITIONS_REQUIRE_N_OUT_MSG, sync, null, -1,
				SYNCHRONIZATION_TRANSITIONS_REQUIRE_N_OUT_CODE);
	}
}
 
Example #18
Source File: ResourceValidator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Check(CheckType.FAST)
public void checkUnresolvableProxies(Statechart sc) {
	if (!(sc.eResource() instanceof AbstractSCTResource)) {
		return;
	}
	AbstractSCTResource resource = (AbstractSCTResource) sc.eResource();
	for (Map.Entry<SpecificationElement, Collection<Diagnostic>> entry : resource.getLinkingDiagnostics().asMap()
			.entrySet()) {
		for (Diagnostic diag : entry.getValue()) {
			if (entry.getKey().eResource() != null)
				error(diag.getMessage(), entry.getKey(), null, -1);
		}
	}
}
 
Example #19
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 rule ends with a dot.
 *
 * @param rule
 *          the rule
 */
@Check(CheckType.FAST)
public void checkRuleDescriptionEndsWithDot(final Rule rule) {
  guard(rule.getDescription() != null);
  if (!rule.getDescription().endsWith(DOT)) {
    warning(DESCRIPTION_SHOULD_END_WITH_A_DOT, ValidPackage.Literals.RULE__DESCRIPTION, RULE_DESCRIPTION_ENDS_WITH_DOT);
  }
}
 
Example #20
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 #21
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that, for each context type, the name of a context is unique inside a model.
 *
 * @param validModel
 *          the valid model
 */
@Check(CheckType.FAST)
public void checkUniqueNativeContextName(final ValidModel validModel) {

  // for each name store the element of its first occurrence
  final Map<String, NativeContext> firstOccurrenceOfName = new HashMap<String, NativeContext>();
  // the set of duplicate names
  final Set<String> duplicateNames = new HashSet<String>();

  for (final Category category : validModel.getCategories()) {
    for (final Rule rule : category.getRules()) {
      if (rule instanceof NativeRule) {
        for (final NativeContext context : ((NativeRule) rule).getContexts()) {
          final String name = getName(context);
          // if the name already occurred we have a duplicate name and hence an error
          final NativeContext firstContext = firstOccurrenceOfName.get(name);
          if (firstContext != null && firstContext.getContextType() == context.getContextType()) {
            duplicateNames.add(name);
            // note the second parameter t
            // it is essential difference to the first example
            error("Name " + name
                + " must be unique for a given context type (introduce an \"as\" clause)", context, ValidPackage.Literals.NATIVE_CONTEXT__GIVEN_NAME, UNIQUE_NATIVE_CONTEXT_NAME);
          } else {
            // otherwise store the name as first occurrence
            firstOccurrenceOfName.put(name, context);
          }
        }
      }
    }
  }

  // now create the error for the first occurrence of a duplicate name
  for (final String duplicate : duplicateNames) {
    error("Name " + duplicate
        + " must be unique for a given context (introduce an \"as\" clause)", firstOccurrenceOfName.get(duplicate), ValidPackage.Literals.NATIVE_CONTEXT__GIVEN_NAME, UNIQUE_NATIVE_CONTEXT_NAME);
  }

}
 
Example #22
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 rule.
 *
 * @param rule
 *          the rule
 */
@Check(CheckType.FAST)
public void checkCheckDescriptionRule(final Rule rule) {
  if (rule.getDescription() == null || rule.getDescription().length() == 0) {
    warning(DESCRIPTION_SHOULD_NOT_BE_EMPTY, ValidPackage.Literals.RULE__DESCRIPTION, CHECK_DESCRIPTION_RULE);
  }
}
 
Example #23
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 #24
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that a label is defined for the rule.
 *
 * @param rule
 *          the rule
 */
@Check(CheckType.FAST)
public void checkRuleLabel(final Rule rule) {
  if (rule.getLabel().length() == 0) {
    error(LABEL_SHALL_NOT_BE_EMPTY, ValidPackage.Literals.RULE__LABEL, RULE_LABEL);
  }

}
 
Example #25
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that a label is defined for the category.
 *
 * @param category
 *          the category
 */
@Check(CheckType.FAST)
public void checkCategoryLabel(final Category category) {
  if (category.getLabel().length() == 0) {
    error(LABEL_SHALL_NOT_BE_EMPTY, ValidPackage.Literals.CATEGORY__LABEL, CATEGORY_LABEL);
  }
}
 
Example #26
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that the native context type has no feature if a marker type is present.
 *
 * @param nativeContext
 *          the native context
 */
@Check(CheckType.FAST)
public void checkNativeContextContextFeature(final NativeContext nativeContext) {
  guard(nativeContext.getContextFeature() != null);
  if (nativeContext.getMarkerType() != null) {
    error(CONTEXT_FEATURE_CANNOT_BE_SPECIFIED_IF_A_MARKER_TYPE_IS_GIVEN, ValidPackage.Literals.CONTEXT__CONTEXT_FEATURE, NATIVE_CONTEXT_CONTEXT_FEATURE);
  }
}
 
Example #27
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that a category has at least one rule.
 *
 * @param category
 *          the category
 */
@Check(CheckType.FAST)
public void checkCategoryEmpty(final Category category) {
  if (category.getRules().isEmpty()) {
    warning(CATEGORY_SHOULD_CONTAIN_AT_LEAST_ONE_RULE, null, CATEGORY_EMPTY);
  }
}
 
Example #28
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that a native context name starts with an upper-case character.
 *
 * @param nativeContext
 *          the native context
 */
@Check(CheckType.FAST)
public void checkNativeContextFirstUpperName(final NativeContext nativeContext) {
  if (nativeContext.isNamed() && !Character.isUpperCase(nativeContext.getGivenName().charAt(0))) {
    error(NAME_SHOULD_START_WITH_A_CAPITAL, ValidPackage.Literals.NATIVE_CONTEXT__GIVEN_NAME, NATIVE_CONTEXT_FIRST_UPPER_NAME);
  }

}
 
Example #29
Source File: ValidJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check that a category name starts with an upper-case character.
 *
 * @param category
 *          the category
 */
@Check(CheckType.FAST)
public void checkCategoryFirstUpperName(final Category category) {
  if (!Character.isUpperCase(category.getName().charAt(0))) {
    error(NAME_SHOULD_START_WITH_A_CAPITAL, ValidPackage.Literals.CATEGORY__NAME, CATEGORY_FIRST_UPPER_NAME);
  }

}
 
Example #30
Source File: ExtraLanguageValidatorSupport.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Check the rules for the activated extra languages.
 *
 * @param currentObject the current object to test.
 */
@Check(CheckType.NORMAL)
public void checkExtraLanguageRules(EObject currentObject) {
	final List<AbstractExtraLanguageValidator> validators = this.validatorProvider.getValidators(
			currentObject.eResource());
	if (!validators.isEmpty()) {
		for (final AbstractExtraLanguageValidator validator : validators) {
			final ValidationMessageAcceptor acceptor = getMessageAcceptor();
			final StateAccess stateAccess = setMessageAcceptor(acceptor);
			validator.validate(stateAccess, acceptor);
		}
	}
}