Skip to content

Commit

Permalink
add superclass properties to schema (#432)
Browse files Browse the repository at this point in the history
* add superclass properties to schema
* disable Haxe4 failures
  • Loading branch information
AlexHaxe authored Jun 6, 2018
1 parent da3bf91 commit 8e3676c
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ matrix:
- haxelib install hxargs 3.0.2
- haxelib install munit
- sed -i 's/:3.3.0//' buildGlobal.hxml
allow_failures:
- haxe: development

2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## dev branch / next version (2.x.x)

- Added JSON schemas for `checkstyle.json` and `checkstyle-exclude.json` file formats [#431](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/431)
- Added JSON schemas for `checkstyle.json` and `checkstyle-exclude.json` file formats [#431](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/431) + [#432](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/432)

## version 2.4.0 (2018-06-02)

Expand Down
10 changes: 5 additions & 5 deletions checkstyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,13 @@
},
{
"props": {
"spaceIfCondition": true,
"spaceIfCondition": "should",
"spaceAroundBinop": true,
"spaceForLoop": true,
"spaceForLoop": "should",
"ignoreRangeOperator": true,
"spaceWhileLoop": true,
"spaceCatch": true,
"spaceSwitchCase": true,
"spaceWhileLoop": "should",
"spaceCatch": "should",
"spaceSwitchCase": "should",
"noSpaceAroundUnop": true
},
"type": "Spacing"
Expand Down
159 changes: 151 additions & 8 deletions resources/checkstyle-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,21 @@
"props": {
"type": "object",
"properties": {
"tokens": {
"items": {
"type": "string"
},
"type": "array",
"propertyOrder": 0
},
"option": {
"enum": [
"eol",
"nl"
],
"type": "string",
"propertyOrder": 1
},
"severity": {
"enum": [
"INFO",
Expand All @@ -413,7 +428,7 @@
"IGNORE"
],
"type": "string",
"propertyOrder": 0
"propertyOrder": 2
}
},
"additionalProperties": false
Expand All @@ -433,6 +448,28 @@
"props": {
"type": "object",
"properties": {
"ignoreExtern": {
"type": "boolean",
"propertyOrder": 2
},
"format": {
"type": "string",
"propertyOrder": 0
},
"tokens": {
"items": {
"anyOf": [
"PUBLIC",
"PRIVATE",
"STATIC",
"NOTSTATIC",
"INLINE",
"NOTINLINE"
]
},
"type": "array",
"propertyOrder": 1
},
"severity": {
"enum": [
"INFO",
Expand All @@ -441,7 +478,7 @@
"IGNORE"
],
"type": "string",
"propertyOrder": 0
"propertyOrder": 3
}
},
"additionalProperties": false
Expand Down Expand Up @@ -541,6 +578,28 @@
"props": {
"type": "object",
"properties": {
"ignoreExtern": {
"type": "boolean",
"propertyOrder": 2
},
"format": {
"type": "string",
"propertyOrder": 0
},
"tokens": {
"items": {
"anyOf": [
"PUBLIC",
"PRIVATE",
"ENUM",
"CLASS",
"ABSTRACT",
"TYPEDEF"
]
},
"type": "array",
"propertyOrder": 1
},
"severity": {
"enum": [
"INFO",
Expand All @@ -549,7 +608,7 @@
"IGNORE"
],
"type": "string",
"propertyOrder": 0
"propertyOrder": 3
}
},
"additionalProperties": false
Expand Down Expand Up @@ -857,6 +916,21 @@
"props": {
"type": "object",
"properties": {
"ignoreExtern": {
"type": "boolean",
"propertyOrder": 2
},
"format": {
"type": "string",
"propertyOrder": 0
},
"tokens": {
"items": {
"type": "string"
},
"type": "array",
"propertyOrder": 1
},
"severity": {
"enum": [
"INFO",
Expand All @@ -865,7 +939,7 @@
"IGNORE"
],
"type": "string",
"propertyOrder": 0
"propertyOrder": 3
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1963,6 +2037,24 @@
"props": {
"type": "object",
"properties": {
"ignoreExtern": {
"type": "boolean",
"propertyOrder": 2
},
"format": {
"type": "string",
"propertyOrder": 0
},
"tokens": {
"items": {
"anyOf": [
"INLINE",
"NOTINLINE"
]
},
"type": "array",
"propertyOrder": 1
},
"severity": {
"enum": [
"INFO",
Expand All @@ -1971,7 +2063,7 @@
"IGNORE"
],
"type": "string",
"propertyOrder": 0
"propertyOrder": 3
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2327,6 +2419,21 @@
"props": {
"type": "object",
"properties": {
"ignoreExtern": {
"type": "boolean",
"propertyOrder": 2
},
"format": {
"type": "string",
"propertyOrder": 0
},
"tokens": {
"items": {
"type": "string"
},
"type": "array",
"propertyOrder": 1
},
"severity": {
"enum": [
"INFO",
Expand All @@ -2335,7 +2442,7 @@
"IGNORE"
],
"type": "string",
"propertyOrder": 0
"propertyOrder": 3
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2451,6 +2558,27 @@
"props": {
"type": "object",
"properties": {
"ignoreExtern": {
"type": "boolean",
"propertyOrder": 2
},
"format": {
"type": "string",
"propertyOrder": 0
},
"tokens": {
"items": {
"anyOf": [
"INTERFACE",
"CLASS",
"ENUM",
"ABSTRACT",
"TYPEDEF"
]
},
"type": "array",
"propertyOrder": 1
},
"severity": {
"enum": [
"INFO",
Expand All @@ -2459,7 +2587,7 @@
"IGNORE"
],
"type": "string",
"propertyOrder": 0
"propertyOrder": 3
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2836,6 +2964,21 @@
"props": {
"type": "object",
"properties": {
"tokens": {
"items": {
"type": "string"
},
"type": "array",
"propertyOrder": 0
},
"option": {
"enum": [
"eol",
"nl"
],
"type": "string",
"propertyOrder": 1
},
"severity": {
"enum": [
"INFO",
Expand All @@ -2844,7 +2987,7 @@
"IGNORE"
],
"type": "string",
"propertyOrder": 0
"propertyOrder": 2
}
},
"additionalProperties": false
Expand Down
62 changes: 47 additions & 15 deletions schema/CheckstyleSchemaGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ class CheckstyleSchemaGenerator {
case "ExcludeConfig.version":
fields.push({field: "minimum", expr: macro 1});
fields.push({field: "maximum", expr: macro 1});
case "ConstantName.tokens.items":
makeAnyOfAbstract(fields, "checkstyle.checks.naming.ConstantNameCheck.ConstantNameCheckToken", pos);
case "LocalVariableName.tokens.items":
fields.push({field: "type", expr: macro "string"});
case "MemberName.tokens.items":
makeAnyOfAbstract(fields, "checkstyle.checks.naming.MemberNameCheck.MemberNameCheckToken", pos);
case "MethodName.tokens.items":
makeAnyOfAbstract(fields, "checkstyle.checks.naming.MethodNameCheck.MethodNameCheckToken", pos);
case "ParameterName.tokens.items":
fields.push({field: "type", expr: macro "string"});
case "TypeName.tokens.items":
makeAnyOfAbstract(fields, "checkstyle.checks.naming.TypeNameCheck.TypeNameCheckToken", pos);

default:
}
}
Expand Down Expand Up @@ -104,23 +117,12 @@ class CheckstyleSchemaGenerator {
if (!refs.exists(name)) {
refs[name] = null;
var classFields:Array<ObjectDeclField> = [];
var fieldOrder:Int = 0;
for (field in fields.get()) {
switch (field.kind) {
case FVar(_):
if (field.isPublic) {
classFields.push ({
field: field.name,
expr: JsonSchemaGenerator.genSchema(field.type, typeName + "." + name, pos, null, refs, fieldOrder, null)
});
fieldOrder++;
}
default:
}
}
addSuperClassFields(typeName, classFields, cl.superClass, pos, refs);
addClassFields(typeName, classFields, fields.get(), pos, refs);
classFields.push({
field: "severity",
expr: JsonSchemaGenerator.genSchema(Context.getType("checkstyle.SeverityLevel"), typeName + ".severity", pos, null, refs, fieldOrder, null)
expr: JsonSchemaGenerator.genSchema(Context.getType("checkstyle.SeverityLevel"),
typeName + ".severity", pos, null, refs, classFields.length, null)
});

var props = SchemaUtils.makeObject(SchemaUtils.makeObjectDecl(classFields, -1, pos), null, [], -1, pos);
Expand All @@ -141,5 +143,35 @@ class CheckstyleSchemaGenerator {
}
throw new Error("Cannot generate Json schema for type " + type, pos); // + type.toString(), pos);
}

static function addClassFields(typeName:String, classFields:Array<ObjectDeclField>, fields:Array<ClassField>, pos:Position, refs:DynamicAccess<Expr>) {
for (field in fields) {
switch (field.kind) {
case FVar(_):
if (field.isPublic) {
classFields.push ({
field: field.name,
expr: JsonSchemaGenerator.genSchema(field.type, typeName + "." + field.name, pos, null, refs, classFields.length, checkstyleFieldsCallback)
});
}
default:
}
}
}

static function addSuperClassFields(typeName:String,
classFields:Array<ObjectDeclField>,
superClass:Null<{t:Ref<ClassType>, params:Array<Type>}>,
pos:Position,
refs:DynamicAccess<Expr>) {
if (superClass == null) return;
if (superClass.t.get().name == "Check") return;
addClassFields(typeName, classFields, superClass.t.get().fields.get(), pos, refs);
}

static function makeAnyOfAbstract(fields:Array<ObjectDeclField>, type:String, pos:Position) {
var values:Expr = JsonSchemaGenerator.getAbstractEnumValues(macro $p{type.split(".")});
fields.push({field: "anyOf", expr: values});
}
#end
}
Loading

0 comments on commit 8e3676c

Please sign in to comment.