Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xpath: change implementation of the @text attribute #6356

Closed
timurt opened this issue Jan 8, 2019 · 7 comments

Comments

Projects
None yet
3 participants
@timurt
Copy link
Collaborator

commented Jan 8, 2019

@romani @rnveach

Followed by
Issue#6240 and Issue#6115

Current implementation does not allow us to query elements by their values.
For example, we want to query the following variable

$ cat TestClass.java
class TestClass {
  String country = "Kazakhstan";
}

$ java -jar checkstyle-8.15-all.jar -t TestClass.java
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
|--LITERAL_CLASS -> class [1:0]
|--IDENT -> TestClass [1:6]
`--OBJBLOCK -> OBJBLOCK [1:16]
    |--LCURLY -> { [1:16]
    |--VARIABLE_DEF -> VARIABLE_DEF [2:2]
    |   |--MODIFIERS -> MODIFIERS [2:2]
    |   |--TYPE -> TYPE [2:2]
    |   |   `--IDENT -> String [2:2]
    |   |--IDENT -> country [2:9]
    |   |--ASSIGN -> = [2:17]
    |   |   `--EXPR -> EXPR [2:19]
    |   |       `--STRING_LITERAL -> "Kazakhstan" [2:19]
    |   `--SEMI -> ; [2:31]
    `--RCURLY -> } [3:0]

We can query variable by its name country (//VARIABLE_DEF[@text='country']), but we cannot query it by its value Kazakhstan.

New implementation will make it possible to query by name and by value
Example xpath queries for previous variable:

By name: //VARIABLE_DEF[./IDENT[@text='country']]
By value: //VARIABLE_DEF[.//STRING_LITERAL[@text='Kazakhstan']]

Migration note: for migration of xpath queries please look at a1cd7a5 for bunch of examples.

@rnveach

This comment has been minimized.

Copy link
Member

commented Jan 8, 2019

Xpath changed from

//VARIABLE_DEF[@text='country']

to

//VARIABLE_DEF[./IDENT[@text='country']]

and some even

//VARIABLE_DEF[./IDENT[@text='country']]/IDENT[@text='country']

I dislike this change. The old way was much more readable and understandable.

@timurt

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 8, 2019

@rnveach

I dislike this change. The old way was much more readable and understandable.

Didn't we agree that we do not need this shortcut? Issue#6240

@rnveach

This comment has been minimized.

Copy link
Member

commented Jan 8, 2019

The only shortcut I thought we agreed on removing was @firstIdentText. #6240 (comment)

@romani can speak on his other comment but I think the change is making the xpath too complex, especially when you need to specify ident text twice.

@romani

This comment has been minimized.

Copy link
Member

commented Jan 10, 2019

I dislike this change. The old way was much more readable and understandable.
...
but I think the change is making the xpath too complex, especially when you need to specify ident text twice.

we agreed to follow AST structure completely, without any shortcuts and virtual attributes. It become a bit verbose but, it is absolute match to AST

AST is:

|--VARIABLE_DEF -> VARIABLE_DEF [2:2]
....
    |   |--IDENT -> country [2:9]
    |   |--ASSIGN -> = [2:17]
    |   |   `--EXPR -> EXPR [2:19]
    |   |       `--STRING_LITERAL -> "Kazakhstan" [2:19]

VARIABLE_DEF does not have text in AST, so it should not have it Xpath.
So Xpaths are as declared in issue description.

to suppress by variable name: //VARIABLE_DEF[./IDENT[@text='country']]
to suppress by variable value: //VARIABLE_DEF[.//STRING_LITERAL[@text='Kazakhstan']]

It will be user responsibility to write easy to read xpath. But when user look at AST, we can easily make xpath, even it could be a bit long.

@rnveach , please review issues one more time and lets finalize our expectation of xpath format.
if you agree, please mark issue as approved.

@romani romani removed the approved label Jan 10, 2019

@rnveach

This comment has been minimized.

Copy link
Member

commented Jan 11, 2019

without any shortcuts and virtual attributes

I am fine with shortcuts if they are a shortcut and make things easier.

if you agree, please mark issue as approved.

Like I said I don't really agree with new format.
I am fine with following AST for now.

@rnveach rnveach added the approved label Jan 11, 2019

@romani

This comment has been minimized.

Copy link
Member

commented Jan 11, 2019

We start with following ast, later on extend with simplification enhancements as we collect more experience

timurt added a commit to timurt/checkstyle that referenced this issue Jan 22, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Jan 22, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Jan 22, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Jan 23, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Feb 3, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Feb 18, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Feb 18, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Feb 19, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Feb 19, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 8, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 8, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 8, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 17, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 19, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 21, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 26, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 27, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 27, 2019

timurt added a commit to timurt/checkstyle that referenced this issue Mar 27, 2019

rnveach added a commit that referenced this issue Mar 28, 2019

@rnveach

This comment has been minimized.

Copy link
Member

commented Mar 28, 2019

Fix was merged

@rnveach rnveach closed this Mar 28, 2019

@rnveach rnveach added this to the 8.19 milestone Mar 28, 2019

Vantuz added a commit to Vantuz/checkstyle that referenced this issue Apr 3, 2019

peterdemaeyer added a commit to peterdemaeyer/checkstyle that referenced this issue Apr 27, 2019

peterdemaeyer added a commit to peterdemaeyer/checkstyle that referenced this issue Apr 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.