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

Documentation adding and editing #5490

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ private List<CtVariable> getVariable(final CtElement parent) {
if (parent == null) {
return variables;
}

class VariableScanner extends CtInheritanceScanner {

@Override
public void visitCtStatementList(CtStatementList e) {
for (int i = 0; i < e.getStatements().size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
public class AstParentConsistencyChecker extends CtScanner {

private CtElement parent;

/**
* Scans a CtElement in the abstract syntax tree (AST) and enforces reference sharing across the AST.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont get where this method enforces references sharing.

Copy link
Author

Choose a reason for hiding this comment

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

This method does not exactly enforce sharing references, but allows sharing reference across the Abstract Syntax Tree. I will correct this.

* @param element The CtElement to scan in the AST.
*/
@Override
public void scan(CtElement element) {
// We allow to share references across the AST
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/spoon/reflect/visitor/CacheBasedConflictFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public class CacheBasedConflictFinder {
typeRef = type.getReference();
}

/** returns true if the given name is a field name */
/**
* Checks if a field with the given name conflicts with fields in the type's scope.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Explain what a conflict is.

Copy link
Author

Choose a reason for hiding this comment

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

I will add the suggested changes.

* @param name The name of the field to check for conflicts.
* @return true if a field with the same name exists in the type's scope, false otherwise.
*/
public boolean hasFieldConflict(String name) {
if (cachedFieldNames == null) {
Collection<CtFieldReference<?>> allFields = type.getAllFields();
Expand All @@ -40,7 +44,11 @@ public boolean hasFieldConflict(String name) {
return cachedFieldNames.contains(name);
}

/** returns true if the given name is a nested type name */
/**
* Checks if a nested type with the given name conflicts with nested types in the type's scope.
* @param name The name of the nested type to check for conflicts.
* @return true if a nested type with the same name exists in the type's scope, false otherwise.
*/
public boolean hasNestedTypeConflict(String name) {
if (cachedNestedTypeNames == null) {
Collection<CtType<?>> allTypes = type.getNestedTypes();
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/spoon/reflect/visitor/CommentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ public class CommentHelper {
private CommentHelper() {
}

/** returns a pretty-printed version of a comment, with prefix, suffix, and intermediate prefix for block and Javadoc */
public static String printComment(CtComment comment) {
PrinterHelper ph = new PrinterHelper(comment.getFactory().getEnvironment());
// now we only use one single method to print all tags
printCommentContent(ph, comment, s -> { return s; });
return ph.toString();
}


static void printComment(PrinterHelper printer, CtComment comment) {
CtComment.CommentType commentType = comment.getCommentType();
String content = comment.getContent();
Expand Down Expand Up @@ -100,11 +98,6 @@ static void printCommentContent(PrinterHelper printer, CtComment comment, Functi
}
}

/**
* Checks if the given stream has more than one element.
* @param stream the stream to check
* @return true if the stream has more than one element, false otherwise.
*/
private static boolean hasMoreThanOneElement(Stream<?> stream) {
return stream.skip(1).findAny().isPresent();
}
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/spoon/reflect/visitor/PrinterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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) {
Expand All @@ -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') {
Expand Down Expand Up @@ -129,6 +133,7 @@ public PrinterHelper write(char c) {

/**
* Generates a new line.
* @return current object of PrinterHelper class
*/
public PrinterHelper writeln() {
write(lineSeparator);
Expand Down Expand Up @@ -158,6 +163,7 @@ protected void autoWriteTabs() {

/**
* Increments the current number of tabs.
* @return current object of PrinterHelper class
*/
public PrinterHelper incTab() {
nbTabs++;
Expand All @@ -166,6 +172,7 @@ public PrinterHelper incTab() {

/**
* Decrements the current number of tabs.
* @return current object of PrinterHelper class
*/
public PrinterHelper decTab() {
nbTabs--;
Expand All @@ -181,6 +188,7 @@ public int getTabCount() {

/**
* Sets the current number of tabs.
* @return current object of PrinterHelper class
*/
public PrinterHelper setTabCount(int tabCount) {
nbTabs = tabCount;
Expand Down Expand Up @@ -211,7 +219,10 @@ 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
Expand All @@ -228,11 +239,6 @@ public PrinterHelper adjustStartPosition(CtElement e) {
return this;
}

/**
* writes as many newlines as needed for the current line to match the end line of the passed element
* @param e element whose line number will be preserved by adding newlines
* @return PrinterHelper
*/
public PrinterHelper adjustEndPosition(CtElement e) {
if (env != null && env.isPreserveLineNumbers() && e.getPosition().isValidPosition()) {
// let's add lines if required
Expand Down Expand Up @@ -284,7 +290,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;
Expand Down
Loading