Comments (13)
maybe give this a shot yourself? :)
from prettier-java.
@thorbenvh8 honestly, this one is a hell to fix, the node tree doesn't have the right abstractions: we would need to differentiate between block statement and an expression, so that we can have expression inside a statement and variable declaration (instead of field declaration) inside a statement too.
We could then apply wrapping to the statement and not to the expression as it is currently done.
from prettier-java.
Ok sure I could put that into the parser.
Can you give me two examples when to return what do understand better?
If we have this return block, if we have this return expression. :)
from prettier-java.
Inside a BLOCK
, in node.statements
we should have only BLOCK_STATEMENT
objects, and inside a BLOCK_STATEMENT
we should have what is currently present in BLOCK
(i.e. identifier statement, expression statement and field declaration).
So that the new line rule (that checks if we are in a lambda, etc) currently defined for EXPRESSION_STATEMENT
can actually be moved to BLOCK_STATEMENT
and applied to any of the 3 type of block statement.
from prettier-java.
So you want from:
{
"type": "BLOCK",
"statements": [
{
"type": "IDENTIFIER_STATEMENT"
},
{
"type": "EXPRESSION_STATEMENT"
},
{
"type": "FIELD_DECLARATION"
}
]
}
to:
{
"type": "BLOCK",
"statements": [
{
"type": "BLOCK_STATEMENT",
"statement": {
"type": "IDENTIFIER_STATEMENT"
}
},
{
"type": "BLOCK_STATEMENT",
"statement": {
"type": "EXPRESSION_STATEMENT"
}
},
{
"type": "BLOCK_STATEMENT",
"statement": {
"type": "FIELD_DECLARATION"
}
}
]
}
from prettier-java.
Did you know you can do path.getParent() (parameter can be a number and that means the parent of level like 1 (default), 2, 3 etc.)
Maybe you can use that?
from prettier-java.
Let's scratch that, I wonder if the bug is not coming from something simpler:
In the example in the description, the variable declaration is parsed as a FIELD_DECLARATION
: this doesn't make any sense. Reading the code of chevrotain-java, I can see that a EXPRESSION_STATEMENT
actually can contains a LOCAL_VARIABLE_DECLARATION
.
If the variable declaration in the example was inside a node of type EXPRESSION_STATEMENT
, then the correct printing behaviour would have been applied.
WDYT? Is that a bug in chevrotain-java?
from prettier-java.
void localVariables() { final List<Filter> filterList = new ArrayList<>(); }
I get this back from the parser, what would you expect instead?
{
type: "METHOD_DECLARATION",
typeType: { type: "VOID" },
name: { type: "IDENTIFIER", value: "localVariables" },
parameters: { parameters: [], type: "FORMAL_PARAMETERS" },
dimensions: [],
body: {
type: "BLOCK",
statements: [
{
type: "FIELD_DECLARATION",
typeType: {
modifiers: [{ type: "MODIFIER", value: "final" }],
type: "TYPE_TYPE",
dimensions: [],
value: {
name: { type: "IDENTIFIER", value: "List" },
type: "CLASS_OR_INTERFACE_TYPE_ELEMENT",
typeArguments: {
type: "TYPE_ARGUMENTS",
value: {
type: "TYPE_LIST",
list: [
{
type: "TYPE_ARGUMENT",
argument: {
type: "IDENTIFIER",
value: "Filter"
},
extends: undefined,
super: undefined
}
]
}
}
}
},
variableDeclarators: {
type: "VARIABLE_DECLARATORS",
list: [
{
type: "VARIABLE_DECLARATOR",
id: {
type: "VARIABLE_DECLARATOR_ID",
id: { type: "IDENTIFIER", value: "filterList" },
dimensions: []
},
init: {
type: "SIMPLE_CREATOR",
name: {
elements: [
{
type: "IDENTIFIER_NAME_ELEMENT",
id: {
type: "IDENTIFIER",
value: "ArrayList"
},
typeArguments: {
type: "TYPE_ARGUMENTS",
value: undefined
}
}
],
type: "IDENTIFIER_NAME"
},
rest: {
type: "CLASS_CREATOR_REST",
arguments: { list: [], type: "EXPRESSION_LIST" },
body: undefined
}
}
}
]
},
followedEmptyLine: false
}
]
},
throws: undefined
}
Did you check the visitor code? Maybe there is a bug that I return the wrong ast?
from prettier-java.
I don't understand how, semantically, a field could be contained in a method block.
I would have expected it to contain an EXPRESSION_STATEMENT, itself containing a LOCAL_VARIABLE_DECLARATION or something like that.
I checked quickly the visitor code of chevrotain-java, but honestly it is not very readable, especially in that place. I'm trying to help understanding where the problem is, but I'm mostly not able to fix it myself because the code is too complex.
from prettier-java.
Fixed in last release :)
from prettier-java.
@thorbenvh8 is it really? You only merged my PR in the last release, nothing since then and my PR didn't fix this!
from prettier-java.
Ups, I released some more stuff but forgot to push the code. On the road right now, so I will push it later :) thanks for the heads up :)
from prettier-java.
cool, that's great news then :)
from prettier-java.
Related Issues (20)
- Migrate e2e pipeline tests to use Java 17 HOT 2
- Record pattern in exhaustive switch syntax unsupported HOT 4
- Support JDK 22 multiple patterns in switch case label HOT 3
- Support preview feature "Unnamed Classes and Instance main Methods "
- Support JDK 22 string templates HOT 1
- [FEATURE REQUEST] make online playground please HOT 2
- Don't split a short line static method to two lines. HOT 7
- Add formatted examples to readme
- Global formatter on macOS - cannot find package 'prettier-plugin-java' HOT 1
- checkstyle inconsistent with prettier HOT 2
- Make use of "Bracket Line" option
- (switch) case with braces not consistent with checkstyle HOT 2
- checkstyle RightCurly not correct when there are comments HOT 1
- Unexpected new line when assigning to a class member
- How do specify plugins without requiring a fully qualified path? HOT 1
- sort module-info
- prettier doesn't correct EmptyLineSeparator for checkstyle with comments
- Regression: more builder chaining being off
- Wrap long javadoc lines where possible
- Unknown 'es5' option for 'trailingComma' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettier-java.