-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ontology qualifier hierarchy (#58)
- Loading branch information
Showing
10 changed files
with
231 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package ontology; | ||
|
||
import checkers.inference.InferenceValidator; | ||
import checkers.inference.InferenceVisitor; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import javax.lang.model.element.AnnotationMirror; | ||
import javax.tools.Diagnostic; | ||
import ontology.qual.Ontology; | ||
import ontology.qual.OntologyValue; | ||
import ontology.util.OntologyUtils; | ||
import org.checkerframework.common.basetype.BaseTypeChecker; | ||
import org.checkerframework.framework.source.DiagMessage; | ||
import org.checkerframework.framework.type.AnnotatedTypeFactory; | ||
import org.checkerframework.framework.type.AnnotatedTypeMirror; | ||
import org.checkerframework.framework.type.QualifierHierarchy; | ||
|
||
/** | ||
* This class checks the well-formedness of ontology values used inside an {@link Ontology} | ||
* annotation. The current rules include: 1. If the type is TOP, BOTTOM, or POLY, the annotation | ||
* shouldn't contain other values (e.g., @Ontology({POLY, FORCE_3D}) is invalid). | ||
*/ | ||
public class OntologyTypeValidator extends InferenceValidator { | ||
public OntologyTypeValidator( | ||
BaseTypeChecker checker, | ||
InferenceVisitor<?, ?> visitor, | ||
AnnotatedTypeFactory atypeFactory) { | ||
super(checker, visitor, atypeFactory); | ||
} | ||
|
||
@Override | ||
protected List<DiagMessage> isTopLevelValidType( | ||
QualifierHierarchy qualifierHierarchy, AnnotatedTypeMirror type) { | ||
List<DiagMessage> errorMsgs = | ||
new ArrayList<>(super.isTopLevelValidType(qualifierHierarchy, type)); | ||
|
||
AnnotationMirror am = type.getAnnotation(Ontology.class); | ||
if (am != null) { | ||
Set<OntologyValue> values = OntologyUtils.getOntologyValuesSet(am); | ||
if (values.size() > 1) { | ||
if (values.contains(OntologyValue.POLY) | ||
|| values.contains(OntologyValue.TOP) | ||
|| values.contains(OntologyValue.BOTTOM)) { | ||
// Should only have one ontology value when the type is one of {POLY, TOP, | ||
// BOTTOM} | ||
errorMsgs.add( | ||
new DiagMessage( | ||
Diagnostic.Kind.ERROR, | ||
"type.invalid.conflicting.elements", | ||
am, | ||
type)); | ||
} | ||
} | ||
} | ||
|
||
return errorMsgs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type.invalid.conflicting.elements=invalid type: conflicting elements in annotation %s of type "%s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.