本文整理汇总了C#中CstNode.SafeParent方法的典型用法代码示例。如果您正苦于以下问题:C# CstNode.SafeParent方法的具体用法?C# CstNode.SafeParent怎么用?C# CstNode.SafeParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CstNode
的用法示例。
在下文中一共展示了CstNode.SafeParent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProtectedIsAcceptedUsingOracle
public override bool ProtectedIsAcceptedUsingOracle(CstNode node) {
var p = node.Parent;
var pp = p.Parent;
var isPar = p.SafeName() == "parExpression";
var isStmt = pp.SafeName() == "statement";
if (isStmt && isPar && pp.FirstChild.SafeTokenText() == "if") {
return true;
}
if (isStmt && isPar && pp.FirstChild.SafeTokenText() == "while") {
return true;
}
if (isStmt && isPar && pp.FirstChild.SafeTokenText() == "do") {
return true;
}
if (p.SafeName() == "forstatement"
&& p.Children().Count(e2 => e2.TokenText == ";") >= 2) {
return true;
}
{
var primary = node.SafeParent().SafeParent().SafeParent().SafeParent();
if (primary.SafeName() != "primary") {
return false;
}
//if (primary.Elements().All(e2 => e2.TokenText() != "Preconditions")) {
// return false;
//}
if (primary.Children().All(e2 => e2.TokenText != "checkArgument")) {
return false;
}
//if (primary.NthElementOrDefault(0).SafeTokenText() != "Preconditions") {
// return false;
//}
//if (primary.NthElementOrDefault(2).SafeTokenText() != "checkArgument") {
// return false;
//}
if (node.PrevsFromFirst().Any()) {
return false;
}
return true;
}
}
示例2: ProtectedIsAcceptedUsingOracle
public override bool ProtectedIsAcceptedUsingOracle(CstNode node) {
var pName = node.SafeParent().FirstChild.Name;
if (pName == "If") {
return node.TokenText.ToLower() != "true";
}
if (pName == "While") {
return node.TokenText.ToLower() != "true";
}
if (pName == "Do") {
return node.TokenText.ToLower() != "true";
}
if (pName == "Switch") {
return true;
}
if (node.Name == "casestatement" || node.Name == "defaultcase") {
return true;
}
if (node.SafeParent().Name == "commaList"
&& node.SafeParent().SafeParent().Name == "forCondition"
&& !node.NextsFromSelf().Any()) {
return node.TokenText.ToLower() != "true";
}
if (node.SafeParent().Name == "commaList"
&& node.SafeParent().SafeParent().Name == "simpleStatement"
&& node.SafeParent().SafeParent().FirstChild.Name == "Echo"
&& node.Prev == null) {
return node.TokenText.ToLower() != "true";
}
return false;
}
示例3: ProtectedIsAcceptedUsingOracle
//public override IEnumerable<SelectedFragment> RejectingFragments {
// get {
// return new[] {
// new SelectedFragment(13, @"for (; true;)", "true"),
// new SelectedFragment(@"while (true) {", "true"),
// new SelectedFragment(@"} while (true)", "true"),
// new SelectedFragment(@"if (true) {", "true"),
// new SelectedFragment(16, @"if (true) {", "true")
// };
// }
//}
public override bool ProtectedIsAcceptedUsingOracle(CstNode node) {
var parentName = node.Parent.SafeName();
if (parentName == "ifStatement") {
return node.TokenText != "true";
}
if (parentName == "whileStatement") {
return node.TokenText != "true";
}
if (parentName == "doWhileStatement") {
return node.TokenText != "true";
}
if (parentName == "forStatement"
&& node.Prev == node.Parent.Children().First(e2 => e2.TokenText == ";")) {
return node.TokenText != "true";
}
if (parentName == "switchStatement") {
return true;
}
if (node.Name == "caseClause" || node.Name == "defaultClause") {
return true;
}
var p = node.SafeParent().SafeParent();
if (p.SafeName() == "callExpression" && p.FirstChild.TokenText == "console.log" &&
p.Child("arguments").Child("assignmentExpression") == node) {
return node.TokenText != "true";
}
return false;
}
示例4: ProtectedIsAcceptedUsingOracle
public override bool ProtectedIsAcceptedUsingOracle(CstNode node) {
var ppp = node.SafeParent().SafeParent().SafeParent();
var pppp = ppp.SafeParent();
if (pppp.SafeName() == "functioncall" && ppp.Prev != null
&& ppp.Prev.TokenText == "print") {
return true;
}
return false;
}