Skip to content

Commit

Permalink
enable string patterns and args for class name, extensions, implement…
Browse files Browse the repository at this point in the history
…ation, issues #49 and #51
  • Loading branch information
saharmehrpour committed Nov 1, 2023
1 parent 9958a71 commit e025965
Show file tree
Hide file tree
Showing 8 changed files with 1,386 additions and 1,108 deletions.
16 changes: 12 additions & 4 deletions rulePadGrammar.g4
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ nameCondition
;


classNames
: NAME classNameCondition?
;

classNameCondition
: combinatorialWords SPACE
;

/*
annotations
*/
Expand Down Expand Up @@ -178,7 +186,7 @@ extensions
;

extensionCondition
: of ( words SPACE | SUPERCLASS)
: of ( combinatorialWords SPACE | words SPACE | SUPERCLASS)
;


Expand All @@ -199,7 +207,7 @@ implementations
;

implementationCondition
: of ( words SPACE | INTERFACE )
: of ( combinatorialWords SPACE | words SPACE | INTERFACE )
;


Expand Down Expand Up @@ -490,7 +498,7 @@ classCondition
classExpression
: LPAREN classExpression RPAREN
| left=classExpression op=binary right=classExpression
| ( annotations | specifiers | visibilities | names | extensions | implementations | functions
| ( annotations | specifiers | visibilities | classNames | extensions | implementations | functions
| abstractFunctions | constructors | declarationStatements | returnValues | comments | subclasses)
| classExpression SPACE
;
Expand Down Expand Up @@ -519,7 +527,7 @@ subclassCondition
subclassExpression
: LPAREN subclassExpression RPAREN
| left=subclassExpression op=binary right=subclassExpression
| ( annotations | specifiers | visibilities | names | extensions | implementations | functions | subclasses |
| ( annotations | specifiers | visibilities | classNames | extensions | implementations | functions | subclasses |
| abstractFunctions | constructors | declarationStatements | returnValues | comments )
| subclassExpression SPACE
;
66 changes: 66 additions & 0 deletions src/core/generateXPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class GenerateXPath {
this.namesContextTraversal(node, isConstraintCondition);
break;

case "ClassNamesContext":
this.classNamesContextTraversal(node, isConstraintCondition);
break;

case "AnnotationsContext":
this.annotationsContextTraversal(node, isConstraintCondition);
break;
Expand Down Expand Up @@ -383,6 +387,44 @@ class GenerateXPath {
}
}

classNamesContextTraversal(node, isConstraintCondition) {
let nodeChildren = node.children.slice(0);

for (let i = 0; i < node.children.length; i++) {
let nodeType = nodeChildren[i].constructor.name;

// process ofContext
if (nodeType === "NameOfContext") {
if (!isConstraintCondition) this.XPathQ += "[ancestor-or-self::";
this.XPathC += "[ancestor-or-self::";
this.traverseNode(nodeChildren[i], isConstraintCondition);
if (!isConstraintCondition) this.XPathQ += "]";
this.XPathC += "]";
}

if (nodeType === "TerminalNodeImpl") {
if (this.XPathQ === "" && !isConstraintCondition) this.XPathQ += "/";
if (this.XPathC === "") this.XPathC += "/";

if (!isConstraintCondition) this.XPathQ += "src:name";
this.XPathC += "src:name";
}

if (nodeType === "ClassNameConditionContext") {
let tempText = "";
let messageID = Math.floor(new Date().getTime() / 1000); // to match send and receive messages
for (let j = 0; j < nodeChildren[i].children.length; j++) {
if (nodeChildren[i].getChild(j).constructor.name === "CombinatorialWordsContext") {
tempText = this.combinatorialWordsContextTraversal(nodeChildren[i].getChild(j));
this.sendTextDataToSrcML(tempText, "className", messageID);
if (!isConstraintCondition) this.XPathQ += "[" + messageID + tempText + "]";
this.XPathC += "[" + messageID + tempText + "]";
}
}
}
}
}

// simplified version of wordsContextTraversal
identifiersContextTraversal(node) {
let identifierTraversal = (node) => {
Expand Down Expand Up @@ -473,12 +515,19 @@ class GenerateXPath {

if (nodeType === "ExtensionConditionContext") {
let tempText = "";
let messageID = Math.floor(new Date().getTime() / 1000); // to match send and receive messages
for (let j = 0; j < nodeChildren[i].children.length; j++) {
if (nodeChildren[i].getChild(j).constructor.name === "WordsContext") {
tempText = this.wordsContextTraversal(nodeChildren[i].getChild(j));
if (!isConstraintCondition) this.XPathQ += "/src:name[" + tempText + "]";
this.XPathC += "/src:name[" + tempText + "]";
}
else if (nodeChildren[i].getChild(j).constructor.name === "CombinatorialWordsContext") {
tempText = this.combinatorialWordsContextTraversal(nodeChildren[i].getChild(j));
this.sendTextDataToSrcML(tempText, "extensionImplementationName", messageID);
if (!isConstraintCondition) this.XPathQ += "[" + messageID + tempText + "]";
this.XPathC += "[" + messageID + tempText + "]";
}
}
}
}
Expand Down Expand Up @@ -509,12 +558,19 @@ class GenerateXPath {

if (nodeType === "ImplementationConditionContext") {
let tempText = "";
let messageID = Math.floor(new Date().getTime() / 1000); // to match send and receive messages
for (let j = 0; j < nodeChildren[i].children.length; j++) {
if (nodeChildren[i].getChild(j).constructor.name === "WordsContext") {
tempText = this.wordsContextTraversal(nodeChildren[i].getChild(j));
if (!isConstraintCondition) this.XPathQ += "/src:name[" + tempText + "]";
this.XPathC += "/src:name[" + tempText + "]";
}
else if (nodeChildren[i].getChild(j).constructor.name === "CombinatorialWordsContext") {
tempText = this.combinatorialWordsContextTraversal(nodeChildren[i].getChild(j));
this.sendTextDataToSrcML(tempText, "extensionImplementationName", messageID);
if (!isConstraintCondition) this.XPathQ += "[" + messageID + tempText + "]";
this.XPathC += "[" + messageID + tempText + "]";
}
}
}
}
Expand Down Expand Up @@ -975,6 +1031,16 @@ class GenerateXPath {
query = "//src:unit[count(src:decl_stmt)=1]/src:decl_stmt/src:decl/src:type";
cuttingLength = 9; // src:type[
break;
case "className":
code = "class " + text + " {}";
query = "//src:unit[count(src:class)=1]/src:class/src:name";
cuttingLength = 9; // src:name[
break;
case "extensionImplementationName":
code = text;
query = "//src:unit[count(src:expr_stmt)=1]/src:expr_stmt/src:expr";
cuttingLength = 9; // src:expr[
break;
case "returnValue":
case "expressionStatement":
case "initialValue":
Expand Down
4 changes: 3 additions & 1 deletion src/core/generated-parser/rulePadGrammar.interp

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/core/generated-parser/rulePadGrammarListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ rulePadGrammarListener.prototype.exitNameCondition = function(ctx) {
};


// Enter a parse tree produced by rulePadGrammarParser#classNames.
rulePadGrammarListener.prototype.enterClassNames = function(ctx) {
};

// Exit a parse tree produced by rulePadGrammarParser#classNames.
rulePadGrammarListener.prototype.exitClassNames = function(ctx) {
};


// Enter a parse tree produced by rulePadGrammarParser#classNameCondition.
rulePadGrammarListener.prototype.enterClassNameCondition = function(ctx) {
};

// Exit a parse tree produced by rulePadGrammarParser#classNameCondition.
rulePadGrammarListener.prototype.exitClassNameCondition = function(ctx) {
};


// Enter a parse tree produced by rulePadGrammarParser#annotations.
rulePadGrammarListener.prototype.enterAnnotations = function(ctx) {
};
Expand Down
Loading

0 comments on commit e025965

Please sign in to comment.