inline Location into the shared implementation of InlineExpectationsTest

This commit is contained in:
erik-krogh
2022-12-22 11:09:43 +01:00
parent 08e9d3391f
commit b3dd50bc36
9 changed files with 172 additions and 164 deletions

View File

@@ -6,41 +6,35 @@
private import java as J
private import codeql.util.test.InlineExpectationsTest
private module Impl implements InlineExpectationsTestSig {
/**
* A class representing line comments in Java, which is simply Javadoc restricted
* to EOL comments, with an extra accessor used by the InlineExpectations core code
*/
abstract class ExpectationComment extends J::Top {
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
abstract string getContents();
}
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
JavadocExpectationComment() { isEolComment(this) }
override string getContents() { result = this.getChild(0).toString() }
}
private class KtExpectationComment extends J::KtComment, ExpectationComment {
KtExpectationComment() { this.isEolComment() }
override string getContents() { result = this.getText().suffix(2).trim() }
}
private class XmlExpectationComment extends ExpectationComment instanceof J::XmlComment {
override string getContents() { result = this.(J::XmlComment).getText().trim() }
override Location getLocation() { result = this.(J::XmlComment).getLocation() }
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
this.(J::XmlComment).hasLocationInfo(path, sl, sc, el, ec)
}
override string toString() { result = this.(J::XmlComment).toString() }
}
class Location = J::Location;
/**
* A class representing line comments in Java, which is simply Javadoc restricted
* to EOL comments, with an extra accessor used by the InlineExpectations core code
*/
abstract private class ExpectationComment extends J::Top {
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
abstract string getContents();
}
import Make<Impl>
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
JavadocExpectationComment() { isEolComment(this) }
override string getContents() { result = this.getChild(0).toString() }
}
private class KtExpectationComment extends J::KtComment, ExpectationComment {
KtExpectationComment() { this.isEolComment() }
override string getContents() { result = this.getText().suffix(2).trim() }
}
private class XmlExpectationComment extends ExpectationComment instanceof J::XmlComment {
override string getContents() { result = this.(J::XmlComment).getText().trim() }
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
this.(J::XmlComment).hasLocationInfo(path, sl, sc, el, ec)
}
override string toString() { result = this.(J::XmlComment).toString() }
}
import Make<ExpectationComment>