-
-
Notifications
You must be signed in to change notification settings - Fork 347
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
Feature request: provide API to add blank lines #1268
Comments
Actually I don't agree with that kind of API: because it would mean that the blank line will be contained in the model, whereas it's only a pretty-print consideration. |
This simple API looks good to me. Would you propose a tentative implementation in a pull request? |
I suggest to have formatting information OPTIONALLY configurable on level of each CtElement. If the formatting information is not null then DJPP would use it instead of standard formatting. The formatting information might consist of this information:
To have it memory efficient, we can share this complex structure between all elements, which has same formatting request. |
CtElement#getMetaData is an option for this.
|
For me the best way to handle it is to support standart Code Formatter Settings (xml file). |
@schakko What would you preffer? I guess it depends on the use case It would be nice to support all these usecases |
Personally I'd prefer option A as I like to have control when to add a line break. For example, after initialization of local variables I always add a line break to visualize that business logic follows. A formatter setting can't handle this use case. |
Automated source code formatting cannot determine when to apply newlines for grouping blocks of code that are logically related. For example: String[] tokens = key.split(XML_DELIM);
List<String> tokenList = new ArrayList(Arrays.asList(tokens));
tokenList.remove(tokenList.size() - 1);
LOG.fine( "..." );
String parentKey = buildString(tokenList);
LOG.fine( "..." );
Element parentElement = getElementMap().get(parentKey);
if (parentElement == null) {
parentElement = createElementHierarchy(parentKey);
}
LOG.fine( "..." ); Usually I'd want a blank line before and after the After processing with Spoon, the code becomes: String[] tokens = key.split(XML_DELIM);
List<String> tokenList = new ArrayList(Arrays.asList(tokens));
tokenList.remove(tokenList.size() - 1);
LOG.fine( "..." );
String parentKey = buildString(tokenList);
LOG.fine( "..." );
Element parentElement = getElementMap().get(parentKey);
if (parentElement == null) {
parentElement = createElementHierarchy(parentKey);
}
LOG.fine( "..." ); This "wall of text" loses information.
Depends on how one views the model as it pertains to the problem domain. For an interpreter or compiler, whitespace and comments are superfluous. For a source code manipulation tool, whitespace is reasonably important to track. Although an AST doesn't generally include whitespace, line terminators, and comments, such lexical preservation is not unheard of. See also:
Having a |
I do agree that vertical spacing has a semantic.
The current solution to this is the somewhat experimental "--lines" option.
The next solution is the so-called sniper mode (#1358) where any help would be appreciated to finish
the implementation and testing.
|
i am a beginner can i work on this can i write this issue for my coding period in GSoC spoon project proposal? |
Talking about this feature with @MartinWitt today. This feature would definitely be useful. In addition, it may be a solution to workaround some limitations of the sniper printer. |
per our meeting, is what you're looking for @I-Al-Istannen? |
Yes, it would be helpful sometimes to create some visual separation. I think @MartinWitt did some stuff with custom AST elements which just cause a whitespace to be printed. I haven't really thought about a nice API for this. |
This is a simple feature request with no real business value but makes it a lot more easier to read through the source code.
Usage
Current result
Expected result
The text was updated successfully, but these errors were encountered: