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

Use tokenrange to construct lex pres data #1034

Merged
merged 8 commits into from
Aug 15, 2017
Merged

Use tokenrange to construct lex pres data #1034

merged 8 commits into from
Aug 15, 2017

Conversation

matozoid
Copy link
Contributor

No description provided.

@matozoid matozoid changed the title Use tokenrange to construct lex pres data [DRAFT] Use tokenrange to construct lex pres data Aug 12, 2017
@@ -65,6 +67,7 @@

/**
* Parse the code and setup the LexicalPreservingPrinter.
* @deprecated just use the other constructor.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ftomassetti - I can't see a good reason to have this constructor, is it okay to deprecate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, until now it was the easiest way to setup LPP. The user would call this method and get the AST with LPP enabled. How the user should get the same result? Should he parse the code and then call new LexicalPreservingPrinter(parseResult)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok, with the new changes the Node is enough to start LPP, right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhuh, we might even refactor this code into the node constructors ("I know my start token, my end token, and the start and end token of my children, so I can deduce which tokens are mine")

@@ -201,7 +205,7 @@ public void process(Node node) {

// We go over tokens and find to which nodes belong. Note that we start from the most specific nodes
// and we move up to more general nodes
for (JavaToken token : documentTokens) {
for (JavaToken token : root.getTokenRange().get()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ftomassetti Well, having token ranges didn't help much to reduce the code here :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, now we do not need a ParseResult anymore, just the AST is enough to enable LPP, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is an advantage.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 65.19% when pulling e36ba9d on matozoid:lex_pres_use_tokenrange into 9e72bb3 on javaparser:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 65.19% when pulling e36ba9d on matozoid:lex_pres_use_tokenrange into 9e72bb3 on javaparser:master.

…kenrange

# Conflicts:
#	javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java
public static TokenTextElement newLine() {
return new TokenTextElement(TokenTypes.eolTokenKind(), EOL);
}
private final JavaToken token;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll directly wrap a JavaToken here, so the lex pres code gets a little more connected to the rest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Ok, that's great!" or "ok, if you insist..." ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one: it is great!

return "TokenTextElement(" + tokenKind +
") {" + text + '}';
return "TokenTextElement(" + token.getKind() +
") {" + getText() + '}';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ftomassetti I could use JavaToken's toString here - are you very attached to this representation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with changing it, if it shows the token kind

@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 65.09% when pulling 1144d3e on matozoid:lex_pres_use_tokenrange into ef8a617 on javaparser:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 65.086% when pulling 23226e3 on matozoid:lex_pres_use_tokenrange into ef8a617 on javaparser:master.

import java.util.Optional;

import static com.github.javaparser.utils.Utils.assertNotNull;

/**
* The range of tokens covered by this node.
*/
public class TokenRange {
public class TokenRange implements Iterable<JavaToken> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@@ -65,6 +67,7 @@

/**
* Parse the code and setup the LexicalPreservingPrinter.
* @deprecated just use the other constructor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok, with the new changes the Node is enough to start LPP, right

public static TokenTextElement newLine() {
return new TokenTextElement(TokenTypes.eolTokenKind(), EOL);
}
private final JavaToken token;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

return "TokenTextElement(" + tokenKind +
") {" + text + '}';
return "TokenTextElement(" + token.getKind() +
") {" + getText() + '}';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with changing it, if it shows the token kind

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 65.083% when pulling 49e1a63 on matozoid:lex_pres_use_tokenrange into 85a3b00 on javaparser:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 65.083% when pulling 4052d96 on matozoid:lex_pres_use_tokenrange into 8310b90 on javaparser:master.

@matozoid matozoid merged commit 8e2082d into javaparser:master Aug 15, 2017
@matozoid matozoid deleted the lex_pres_use_tokenrange branch August 15, 2017 17:16
@matozoid matozoid changed the title [DRAFT] Use tokenrange to construct lex pres data Use tokenrange to construct lex pres data Aug 15, 2017
@matozoid matozoid added this to the next release milestone Aug 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants