本文整理汇总了Java中org.eclipse.xtext.validation.Check类的典型用法代码示例。如果您正苦于以下问题:Java Check类的具体用法?Java Check怎么用?Java Check使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Check类属于org.eclipse.xtext.validation包,在下文中一共展示了Check类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkVariableStatement
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
/**
* general top-level test: - invalid statements for StaticPolyfillModules. Constraints 140 (restrictions on
* static-polyfilling) IDE-1735
*/
@Check
public void checkVariableStatement(Statement statement) {
EObject con = statement.eContainer();
if (con instanceof Script) { // top-level elements will be checked only.
Script script = (Script) con;
if (!isContainedInStaticPolyfillModule(script)) {
return;
}
// FunctionDeclarations have finer grained check in own validator.
if (statement instanceof FunctionDeclaration)
return;
// it is a static polyfill module
addIssue(getMessageForPOLY_STATIC_POLYFILL_MODULE_ONLY_FILLING_CLASSES(), statement,
POLY_STATIC_POLYFILL_MODULE_ONLY_FILLING_CLASSES);
}
}
示例2: checkN4TypeDeclaration
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
/**
* Constraints 3 and 4.2
*/
@Check
public void checkN4TypeDeclaration(N4TypeDeclaration n4TypeDeclaration) {
if (isNotChecked(n4TypeDeclaration)) {
return;
}
// quick exit:
if (Character.isUpperCase(n4TypeDeclaration.getName().charAt(0))) {
return;
}
if (holdsTypeNameNotIndistinguishable(n4TypeDeclaration, "getter/setter", GETTER_SETTER) //
&& holdsTypeNameNotIndistinguishable(n4TypeDeclaration, "access modifier", ACCESS_MODIFIERS) //
&& holdsTypeNameNotIndistinguishable(n4TypeDeclaration, "boolean literal", BOOLEAN_LITERALS) //
&& holdsTypeNameNotIndistinguishable(n4TypeDeclaration, "base type", BASE_TYPES) //
&& holdsTypeNameNotIndistinguishable(n4TypeDeclaration, "keyword",
languageHelper.getECMAKeywords())
&& holdsDoesNotStartWithLowerCaseLetter(n4TypeDeclaration)) {
// error messages are created with in constraint validation
}
}
示例3: checkN4MemberDeclaration
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
/**
* Constraints 4.1
*/
@Check
public void checkN4MemberDeclaration(N4MemberDeclaration n4Member) {
if (isNotChecked(n4Member)) {
return;
}
if (
// IDEBUG-304 allow member names to be keywords
// holdsNameMayNotBeConfusedWith(n4Member, "keyword", KEYWORDS) //
// &&
holdsDoesNotEqualWithConstructor(n4Member) //
&& holdsNameMayNotBeConfusedWith(n4Member, "future reserved word", FUTURE_RESERVED_WORDS) //
&& holdsNameMayNotBeConfusedWith(n4Member, "boolean literal", BOOLEAN_LITERALS) //
&& //
(!(n4Member instanceof Variable) // avoid redundant checks
&& holdsDoesNotStartWithUpperCaseLetter(n4Member) //
&& holdsNoTypeNameOrNameEqualsType(n4Member) //
&& holdsDoesNotContainDiscouragedCharacter(n4Member) //
&& holdsNameMayNotBeConfusedWith(n4Member, "access modifier", ACCESS_MODIFIERS) //
)) {
// error messages are created with in constraint validation
}
}
示例4: checkVariable
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
/**
* Constraints 4.3
*/
@Check
public void checkVariable(Variable variable) {
if (isNotChecked(variable)) {
return;
}
if (holdsDoesNotStartWithDollarSign(variable) //
&& holdsDoesNotEqualWithConstructor(variable) //
&& holdsStartWithLowercaseLetter(variable) //
&& holdsNameMayNotBeConfusedWith(variable, "access modifier", ACCESS_MODIFIERS) //
&& holdsNoTypeNameOrNameEqualsType(variable) //
&& holdsDoesNotContainDiscouragedCharacter(variable)) {
// error messages are created with in constraint validation
}
}
示例5: checkFecha
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
@Check
public void checkFecha(final Restaurante restaurante) {
try {
SimpleDateFormat formateadorFecha = new SimpleDateFormat("dd-MM-yyyy");
Date fechaDada = formateadorFecha.parse(restaurante.getFecha());
Calendar fechaActual = Calendar.getInstance();
Date _time = fechaActual.getTime();
boolean _greaterThan = (fechaDada.compareTo(_time) > 0);
if (_greaterThan) {
this.error("La fecha tiene que ser igual o menor que la actual",
RestaurantePackage.Literals.RESTAURANTE__FECHA, RestauranteValidator.FECHA_INVALIDA);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例6: checkOverlap
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
/**
* Check that there is no overlap between the fields exported by a class and its parents.
*
* @param context
* model to check
*/
@Check
public void checkOverlap(final ExportModel context) {
UniquenessJavaValidationHelper<Attribute> helper = new UniquenessJavaValidationHelper<Attribute>(NameFunctions.fromFeature(ExportPackage.Literals.ATTRIBUTE__ATTRIBUTE), getMessageAcceptor());
for (Export export : context.getExports()) {
for (Export candidate : context.getExports()) {
if (export.getType() != candidate.getType() && candidate.getType().isSuperTypeOf(export.getType())) {
for (Attribute attribute : helper.findDuplicates(Iterables.concat(export.getAttributes(), candidate.getAttributes()))) {
if (attribute.eContainer() == export) {
error("Overlap duplicate found: " + attribute.getAttribute().getName(), attribute, ExportPackage.Literals.ATTRIBUTE__ATTRIBUTE, null);
}
}
}
}
}
}
示例7: checkCheckNamesAreUnique
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
/**
* Checks that Check names are unique. A Check name may only occur once in a Check Catalog.
*
* @param catalog
* the check catalog
*/
@Check
public void checkCheckNamesAreUnique(final CheckCatalog catalog) {
Function<com.avaloq.tools.ddk.check.check.Check, QualifiedName> function = new Function<com.avaloq.tools.ddk.check.check.Check, QualifiedName>() {
@Override
public QualifiedName apply(final com.avaloq.tools.ddk.check.check.Check from) {
return QualifiedName.create(from.getName()); // no need to create a fully qualified name with check catalog here, it is only used for
// comparing check instances
}
};
UniquenessJavaValidationHelper<com.avaloq.tools.ddk.check.check.Check> helper = //
new UniquenessJavaValidationHelper<com.avaloq.tools.ddk.check.check.Check>(function, getMessageAcceptor()) {
@Override
public String getMessage(final com.avaloq.tools.ddk.check.check.Check duplicate) {
return NLS.bind("Duplicate Check name: {0}", duplicate.getName()); //$NON-NLS-1$
}
};
final Iterable<com.avaloq.tools.ddk.check.check.Check> allChecksWithName = Iterables.filter(catalog.getAllChecks(), new Predicate<com.avaloq.tools.ddk.check.check.Check>() {
@Override
public boolean apply(final com.avaloq.tools.ddk.check.check.Check input) {
return input.getName() != null;
}
});
helper.errorOnDuplicates(allChecksWithName, locationInFileProvider::getIdentifierFeature, IssueCodes.DUPLICATE_CHECK);
}
示例8: checkTypeParameterNotUsedInStaticContext
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
@Check
public void checkTypeParameterNotUsedInStaticContext(JvmTypeReference ref) {
if(ref.getType() instanceof JvmTypeParameter) {
JvmTypeParameter typeParameter = (JvmTypeParameter) ref.getType();
if (!(typeParameter.getDeclarator() instanceof JvmOperation) || !isTypeParameterOfClosureImpl(ref)) {
EObject currentParent = logicalContainerProvider.getNearestLogicalContainer(ref);
while(currentParent != null) {
if(currentParent == typeParameter.eContainer())
return;
else if(isStaticContext(currentParent))
error("Cannot make a static reference to the non-static type " + typeParameter.getName(),
ref, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, -1, STATIC_ACCESS_TO_INSTANCE_MEMBER);
currentParent = currentParent.eContainer();
}
}
}
}
示例9: checkFingerprintInterfaceDefined
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
/**
* Checks that the interface referenced by a fingerprint is defined.
*
* @param context
* export to check
*/
@Check
public void checkFingerprintInterfaceDefined(final Export context) {
if (context.isFingerprint() || context.isResourceFingerprint()) {
ExportModel model = EObjectUtil.eContainer(context, ExportModel.class);
Interface match = null;
for (Interface iface : model.getInterfaces()) {
if (iface.getType().isSuperTypeOf(context.getType())) {
match = iface;
break;
}
}
if (match == null) {
error("No matching interface specification declared", context.isFingerprint() ? ExportPackage.Literals.EXPORT__FINGERPRINT
: ExportPackage.Literals.EXPORT__RESOURCE_FINGERPRINT);
}
}
}
示例10: checkIllegalOverride
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
/**
* Checks that no rule declares override when there is no corresponding inherited rule.
*
* @param model
* the model
*/
@Check
public void checkIllegalOverride(final FormatConfiguration model) {
Iterable<Rule> overrideRules = Iterables.filter(model.getRules(), IS_OVERRIDE);
Iterable<Rule> overrideableRules = Lists.newArrayList();
FormatConfiguration extendedModel = model.getExtendedFormatConfiguration();
if (extendedModel != null && !extendedModel.eIsProxy()) {
overrideableRules = collectRules(extendedModel);
}
Map<AbstractRule, GrammarRule> overrideableAbstractRuleMap = Maps.newHashMap();
for (GrammarRule rule : Iterables.filter(overrideableRules, GrammarRule.class)) {
overrideableAbstractRuleMap.put(TARGET_RULE.apply(rule), rule);
}
// Check GrammarRules
for (GrammarRule overrideRule : Iterables.filter(overrideRules, GrammarRule.class)) {
if (!overrideableAbstractRuleMap.containsKey(TARGET_RULE.apply(overrideRule))) {
error(OVERRIDE_ILLEGAL_MESSAGE, overrideRule, FormatPackage.Literals.GRAMMAR_RULE__TARGET_RULE, OVERRIDE_ILLEGAL_CODE);
}
}
// Check WildcardRule
if (!Iterables.isEmpty(Iterables.filter(overrideRules, WildcardRule.class)) && Iterables.isEmpty(Iterables.filter(overrideableRules, WildcardRule.class))) {
error(OVERRIDE_ILLEGAL_MESSAGE, Iterables.filter(overrideRules, WildcardRule.class).iterator().next(), null, OVERRIDE_ILLEGAL_CODE);
}
}
示例11: checkNullSafeFeatureCallWithPrimitives
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
@Check
void checkNullSafeFeatureCallWithPrimitives(XMemberFeatureCall featureCall) {
if (featureCall.isNullSafe()) {
if (getActualType(featureCall.getMemberCallTarget()).isPrimitive()) {
error("Cannot use null-safe feature call on primitive receiver", featureCall,
Literals.XMEMBER_FEATURE_CALL__NULL_SAFE, NULL_SAFE_FEATURE_CALL_ON_PRIMITIVE);
return;
}
LightweightTypeReference type = getActualType(featureCall);
if (type.isPrimitive() && isValueExpectedRecursive(featureCall)) {
addIssue("Null-safe call of primitive-valued feature " + featureCall.getConcreteSyntaxFeatureName()
+ ", default value "+ getDefaultValue(type) +" will be used",
featureCall, NULL_SAFE_FEATURE_CALL_OF_PRIMITIVE_VALUED_FEATURE);
}
}
}
示例12: checkDefaultSeverityInRange
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
/**
* Checks that the default severity is within given severity range. There must not be a conflict such
* that the severity range defines severities do not contain the default.
* <p>
* Note that this check works even if {@link #checkSeverityRangeOrder(com.avaloq.tools.ddk.check.check.Check)} is violated.
* </p>
*
* @param check
* the check
*/
@Check
public void checkDefaultSeverityInRange(final com.avaloq.tools.ddk.check.check.Check check) {
if (check.getSeverityRange() == null) {
return; // only applicable if both range and default severity given
}
final SeverityRange range = check.getSeverityRange();
final SeverityKind minSeverity = SeverityKind.get(Math.min(range.getMinSeverity().getValue(), range.getMaxSeverity().getValue()));
final SeverityKind maxSeverity = SeverityKind.get(Math.max(range.getMinSeverity().getValue(), range.getMaxSeverity().getValue()));
if (check.getDefaultSeverity().compareTo(minSeverity) < 0 || check.getDefaultSeverity().compareTo(maxSeverity) > 0) {
List<String> issueCodes = Lists.newArrayList();
SeverityKind temp = minSeverity;
while (temp != null && temp.compareTo(maxSeverity) <= 0) {
issueCodes.add(temp.getName());
temp = SeverityKind.get(temp.getValue() + 1);
}
String[] codes = issueCodes.toArray(new String[issueCodes.size()]);
error(Messages.CheckJavaValidator_DEFAULT_SEVERITY_NOT_IN_RANGE, check, CheckPackage.Literals.CHECK__DEFAULT_SEVERITY, IssueCodes.DEFAULT_SEVERITY_NOT_IN_RANGE, issueCodes.isEmpty()
? null // NOPMD
: codes);
}
}
示例13: checkTypeGuardsOrder
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
@Check
public void checkTypeGuardsOrder(XSwitchExpression expression) {
if (isIgnored(IssueCodes.UNREACHABLE_CASE)) {
return;
}
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
List<LightweightTypeReference> previousTypeReferences = new ArrayList<LightweightTypeReference>();
for (XCasePart casePart : expression.getCases()) {
JvmTypeReference typeGuard = casePart.getTypeGuard();
if (typeGuard == null) {
continue;
}
LightweightTypeReference actualType = owner.toLightweightTypeReference(typeGuard);
if (actualType == null) {
continue;
}
if (isHandled(actualType, previousTypeReferences)) {
addIssue("Unreachable code: The case can never match. It is already handled by a previous condition.", typeGuard, IssueCodes.UNREACHABLE_CASE);
continue;
}
if (casePart.getCase() == null) {
previousTypeReferences.add(actualType);
}
}
}
示例14: checkTypeGuardsOrderWithGenerics
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
@Check
public void checkTypeGuardsOrderWithGenerics(XSwitchExpression expression) {
if (isIgnored(IssueCodes.UNREACHABLE_CASE)) {
return;
}
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
List<LightweightTypeReference> previousTypeReferences = new ArrayList<LightweightTypeReference>();
for (XCasePart casePart : expression.getCases()) {
JvmTypeReference typeGuard = casePart.getTypeGuard();
if (typeGuard == null) {
continue;
}
LightweightTypeReference typeReference = owner.toLightweightTypeReference(typeGuard);
LightweightTypeReference actualType = typeReference.getRawTypeReference();
if (actualType == null || typeReference == actualType) {
continue;
}
if (isHandled(actualType, previousTypeReferences)) {
addIssue("Unreachable code: The case can never match. It is already handled by a previous condition (with the same type erasure).", typeGuard, IssueCodes.UNREACHABLE_CASE);
continue;
}
if (casePart.getCase() == null) {
previousTypeReferences.add(actualType);
}
}
}
示例15: checkCatchClausesOrder
import org.eclipse.xtext.validation.Check; //导入依赖的package包/类
@Check
public void checkCatchClausesOrder(XTryCatchFinallyExpression expression) {
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
List<LightweightTypeReference> previousTypeReferences = new ArrayList<LightweightTypeReference>();
for (XCatchClause catchClause : expression.getCatchClauses()) {
LightweightTypeReference actualTypeReference = owner.toLightweightTypeReference(catchClause.getDeclaredParam().getParameterType());
if (actualTypeReference == null) {
continue;
}
if (isHandled(actualTypeReference, previousTypeReferences)) {
error("Unreachable code: The catch block can never match. It is already handled by a previous condition.", catchClause.getDeclaredParam().getParameterType(), null, IssueCodes.UNREACHABLE_CATCH_BLOCK);
continue;
}
previousTypeReferences.add(actualTypeReference);
}
}