-
-
Notifications
You must be signed in to change notification settings - Fork 354
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
Documentation adding and editing #5490
Changes from 6 commits
ead4fc1
4ea6c8c
2d5b85a
1c9aec1
4cd4a7c
06e733a
606019b
a6ae2c5
68163f7
a2811b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -42,19 +42,38 @@ public AccessibleVariablesFinder(CtElement expression) { | |||||||||||
this.expression = expression; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Finds and returns a list of CtVariable objects associated with the parent of the expression. | ||||||||||||
* If the parent of the expression is not initialized, it returns an empty list. | ||||||||||||
* @return List of CtVariable objects if the parent of the expression is initialized, otherwise an empty list. | ||||||||||||
*/ | ||||||||||||
public List<CtVariable> find() { | ||||||||||||
if (expression.isParentInitialized()) { | ||||||||||||
return getVariable(expression.getParent()); | ||||||||||||
} | ||||||||||||
return Collections.emptyList(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* This method retrieves a list of variables from a given parent CtElement instance. | ||||||||||||
* @param parent The parent element from which to retrieve variables. | ||||||||||||
* @return A list of variables found within the parent element. | ||||||||||||
*/ | ||||||||||||
private List<CtVariable> getVariable(final CtElement parent) { | ||||||||||||
final List<CtVariable> variables = new ArrayList<>(); | ||||||||||||
if (parent == null) { | ||||||||||||
return variables; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/* | ||||||||||||
* This class scans for variables within a given element. | ||||||||||||
*/ | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We can skip for |
||||||||||||
class VariableScanner extends CtInheritanceScanner { | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* This method visits a list of statements and adds any variables it finds to the list. | ||||||||||||
* @param e The list of statements to visit. | ||||||||||||
*/ | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we can remove all the docstring in the overridden methods in this class as they are not part of the public API. They are just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright. Thanks for pointing out these corrections. I will rectify these and add new javadocs based your suggestions. |
||||||||||||
@Override | ||||||||||||
public void visitCtStatementList(CtStatementList e) { | ||||||||||||
for (int i = 0; i < e.getStatements().size(); i++) { | ||||||||||||
|
@@ -72,6 +91,10 @@ public void visitCtStatementList(CtStatementList e) { | |||||||||||
super.visitCtStatementList(e); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* This method scans CtType instance and adds any fields it finds to the list. | ||||||||||||
* @param type The type to scan. | ||||||||||||
*/ | ||||||||||||
@Override | ||||||||||||
public <T> void scanCtType(CtType<T> type) { | ||||||||||||
List<CtField<?>> fields = type.getFields(); | ||||||||||||
|
@@ -98,6 +121,10 @@ public <T> void scanCtType(CtType<T> type) { | |||||||||||
super.scanCtType(type); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* This method visits a try-with-resource statement and adds any resources it finds to the list. | ||||||||||||
* @param e The try-with-resource statement to visit. | ||||||||||||
*/ | ||||||||||||
@Override | ||||||||||||
public void visitCtTryWithResource(CtTryWithResource e) { | ||||||||||||
for (CtResource<?> resource: e.getResources()) { | ||||||||||||
|
@@ -108,12 +135,20 @@ public void visitCtTryWithResource(CtTryWithResource e) { | |||||||||||
super.visitCtTryWithResource(e); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* This method scans an executable and adds any parameters it finds to the list. | ||||||||||||
* @param e The executable to scan. | ||||||||||||
*/ | ||||||||||||
@Override | ||||||||||||
public void scanCtExecutable(CtExecutable e) { | ||||||||||||
variables.addAll(e.getParameters()); | ||||||||||||
super.scanCtExecutable(e); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* This method visits a for loop and scans its initialization statements for variables. | ||||||||||||
* @param e The for loop to visit. | ||||||||||||
*/ | ||||||||||||
@Override | ||||||||||||
public void visitCtFor(CtFor e) { | ||||||||||||
for (CtStatement ctStatement : e.getForInit()) { | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,7 +23,7 @@ | |||||||||
public class PrinterHelper { | ||||||||||
/** | ||||||||||
* Line separator which is used by the printer helper. | ||||||||||
* By default the system line separator is used | ||||||||||
* By default, the system line separator is used | ||||||||||
*/ | ||||||||||
private String lineSeparator = System.getProperty("line.separator"); | ||||||||||
|
||||||||||
|
@@ -85,6 +85,8 @@ public void reset() { | |||||||||
|
||||||||||
/** | ||||||||||
* Outputs a string. | ||||||||||
* @param s String to printed in output | ||||||||||
* @return current object of PrintHelper class | ||||||||||
*/ | ||||||||||
public PrinterHelper write(String s) { | ||||||||||
if (s != null) { | ||||||||||
|
@@ -98,6 +100,8 @@ public PrinterHelper write(String s) { | |||||||||
|
||||||||||
/** | ||||||||||
* Outputs a char. | ||||||||||
* @param c Character to be printed in output | ||||||||||
* @return current object of PrinterHelper class | ||||||||||
*/ | ||||||||||
public PrinterHelper write(char c) { | ||||||||||
if (c == '\r') { | ||||||||||
|
@@ -129,12 +133,16 @@ public PrinterHelper write(char c) { | |||||||||
|
||||||||||
/** | ||||||||||
* Generates a new line. | ||||||||||
* @return current object of PrinterHelper class | ||||||||||
*/ | ||||||||||
public PrinterHelper writeln() { | ||||||||||
write(lineSeparator); | ||||||||||
return this; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Appends tabs or spaces to a StringBuilder based on the environment settings. | ||||||||||
*/ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
private void writeTabsInternal() { | ||||||||||
for (int i = 0; i < nbTabs; i++) { | ||||||||||
if (env != null && env.isUsingTabulations()) { | ||||||||||
|
@@ -149,6 +157,10 @@ private void writeTabsInternal() { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Writes tabs if the condition is met. | ||||||||||
* This method checks if tabs should be written, and if so, it writes them and resets the flag. | ||||||||||
*/ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
protected void autoWriteTabs() { | ||||||||||
if (shouldWriteTabs) { | ||||||||||
writeTabsInternal(); | ||||||||||
|
@@ -158,6 +170,7 @@ protected void autoWriteTabs() { | |||||||||
|
||||||||||
/** | ||||||||||
* Increments the current number of tabs. | ||||||||||
* @return current object of PrinterHelper class | ||||||||||
*/ | ||||||||||
public PrinterHelper incTab() { | ||||||||||
nbTabs++; | ||||||||||
|
@@ -166,6 +179,7 @@ public PrinterHelper incTab() { | |||||||||
|
||||||||||
/** | ||||||||||
* Decrements the current number of tabs. | ||||||||||
* @return current object of PrinterHelper class | ||||||||||
*/ | ||||||||||
public PrinterHelper decTab() { | ||||||||||
nbTabs--; | ||||||||||
|
@@ -181,12 +195,17 @@ public int getTabCount() { | |||||||||
|
||||||||||
/** | ||||||||||
* Sets the current number of tabs. | ||||||||||
* @return current object of PrinterHelper class | ||||||||||
*/ | ||||||||||
public PrinterHelper setTabCount(int tabCount) { | ||||||||||
nbTabs = tabCount; | ||||||||||
return this; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Removes the last line from the buffer if it matches the line separator. | ||||||||||
* @return true if the line was removed, false otherwise. | ||||||||||
*/ | ||||||||||
public boolean removeLine() { | ||||||||||
String ls = lineSeparator; | ||||||||||
int i = sbf.length() - ls.length(); | ||||||||||
|
@@ -207,11 +226,18 @@ public boolean removeLine() { | |||||||||
return true; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* @param c Character that needs to be checked for being space/line-break character | ||||||||||
* @return true if character is space/line-break character | ||||||||||
*/ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
private boolean isWhite(char c) { | ||||||||||
return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'); | ||||||||||
} | ||||||||||
|
||||||||||
/** writes as many newlines as needed to align the line number again between the element position and the current line number */ | ||||||||||
/** writes as many newlines as needed to align the line number again between the element position and the current line number | ||||||||||
* @param e The CtElement whose start position is to be adjusted. It should not be implicit and should have a valid position. | ||||||||||
* @return The current instance of PrinterHelper with the adjusted start position. | ||||||||||
*/ | ||||||||||
public PrinterHelper adjustStartPosition(CtElement e) { | ||||||||||
if (!e.isImplicit() && e.getPosition().isValidPosition()) { | ||||||||||
// we should add some lines | ||||||||||
|
@@ -243,12 +269,24 @@ public PrinterHelper adjustEndPosition(CtElement e) { | |||||||||
return this; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Undefines the current line number mapping. | ||||||||||
* If the current line number mapping is null, it sets the line number mapping to 0. | ||||||||||
*/ | ||||||||||
public void undefineLine() { | ||||||||||
if (lineNumberMapping.get(line) == null) { | ||||||||||
putLineNumberMapping(0); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Maps the line number of a given CtElement to the current line number. | ||||||||||
* If the position of the CtElement is not valid, or it does not belong to the expected compilation unit, or it is a partial source position, | ||||||||||
* it undefines the current line number. | ||||||||||
* | ||||||||||
* @param e The CtElement whose line number is to be mapped. | ||||||||||
* @param unitExpected The expected compilation unit of the CtElement. | ||||||||||
*/ | ||||||||||
public void mapLine(CtElement e, CtCompilationUnit unitExpected) { | ||||||||||
SourcePosition sp = e.getPosition(); | ||||||||||
if ((sp.isValidPosition()) | ||||||||||
|
@@ -261,14 +299,26 @@ public void mapLine(CtElement e, CtCompilationUnit unitExpected) { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Maps a given line number to the current line number. | ||||||||||
* @param valueLine The line number to be mapped to the current line. | ||||||||||
*/ | ||||||||||
public void putLineNumberMapping(int valueLine) { | ||||||||||
lineNumberMapping.put(this.line, valueLine); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Retrieves the current line number mapping as an unmodifiable map. | ||||||||||
* @return An unmodifiable map of the current line number mapping. | ||||||||||
*/ | ||||||||||
public Map<Integer, Integer> getLineNumberMapping() { | ||||||||||
return Collections.unmodifiableMap(lineNumberMapping); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Converts the content of sbf StringBuilder in current object to a string representation. | ||||||||||
* @return String that contains content stored in sbf for current object of PrinterHelper class | ||||||||||
*/ | ||||||||||
@Override | ||||||||||
public String toString() { | ||||||||||
return sbf.toString(); | ||||||||||
|
@@ -284,7 +334,7 @@ public String getLineSeparator() { | |||||||||
|
||||||||||
/** | ||||||||||
* @param lineSeparator characters which will be printed as End of line. | ||||||||||
* By default there is System.getProperty("line.separator") | ||||||||||
* By default, there is System.getProperty("line.separator") | ||||||||||
*/ | ||||||||||
public void setLineSeparator(String lineSeparator) { | ||||||||||
this.lineSeparator = lineSeparator; | ||||||||||
|
@@ -295,6 +345,10 @@ public void writeSpace() { | |||||||||
this.write(' '); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Sets the flag indicating whether to write tabs. | ||||||||||
* @param b The boolean value to set. If true, tabs will be written; if false, they won't be. | ||||||||||
*/ | ||||||||||
public void setShouldWriteTabs(boolean b) { | ||||||||||
this.shouldWriteTabs = b; | ||||||||||
} | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can skip documentation for private methods.