diff --git a/src/main/java/spoon/reflect/visitor/AccessibleVariablesFinder.java b/src/main/java/spoon/reflect/visitor/AccessibleVariablesFinder.java index 33d07826e63..716cf731c77 100644 --- a/src/main/java/spoon/reflect/visitor/AccessibleVariablesFinder.java +++ b/src/main/java/spoon/reflect/visitor/AccessibleVariablesFinder.java @@ -54,7 +54,9 @@ private List 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++) { diff --git a/src/main/java/spoon/reflect/visitor/AstParentConsistencyChecker.java b/src/main/java/spoon/reflect/visitor/AstParentConsistencyChecker.java index 6188a04d727..028f61ff346 100644 --- a/src/main/java/spoon/reflect/visitor/AstParentConsistencyChecker.java +++ b/src/main/java/spoon/reflect/visitor/AstParentConsistencyChecker.java @@ -13,6 +13,21 @@ public class AstParentConsistencyChecker extends CtScanner { private CtElement parent; + + /** + * Scans the given CtElement in the context of the AST. This method allows + * sharing references across the AST. A leaf reference can be the same + * at different places. + * + * @param element The CtElement to be scanned. If null or an instance of CtReference, + * the method returns without further processing. + * + * @throws IllegalStateException If the given element is already set as a child + * of a different parent in the AST, and the parent + * relationship is not properly initialized. + * The exception provides detailed debug information + * for better diagnosis. + */ @Override public void scan(CtElement element) { // We allow to share references across the AST diff --git a/src/main/java/spoon/reflect/visitor/CacheBasedConflictFinder.java b/src/main/java/spoon/reflect/visitor/CacheBasedConflictFinder.java index 2916769881b..588e7034230 100644 --- a/src/main/java/spoon/reflect/visitor/CacheBasedConflictFinder.java +++ b/src/main/java/spoon/reflect/visitor/CacheBasedConflictFinder.java @@ -28,7 +28,12 @@ public class CacheBasedConflictFinder { typeRef = type.getReference(); } - /** returns true if the given name is a field name */ + /** + * Checks if there is a field conflict with the specified name. + * A conflict refers to a situation where there is a field with the specified name ('name') that already exists in the collection of fields associated with the 'type'. + * @param name The name of the field to check for conflicts. + * @return {@code true} if there is a field conflict, {@code false} otherwise. + */ public boolean hasFieldConflict(String name) { if (cachedFieldNames == null) { Collection> allFields = type.getAllFields(); @@ -40,7 +45,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> allTypes = type.getNestedTypes(); diff --git a/src/main/java/spoon/reflect/visitor/CommentHelper.java b/src/main/java/spoon/reflect/visitor/CommentHelper.java index d88f6d7a924..3a9ef19b03f 100644 --- a/src/main/java/spoon/reflect/visitor/CommentHelper.java +++ b/src/main/java/spoon/reflect/visitor/CommentHelper.java @@ -25,7 +25,6 @@ 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 @@ -33,7 +32,6 @@ public static String printComment(CtComment comment) { return ph.toString(); } - static void printComment(PrinterHelper printer, CtComment comment) { CtComment.CommentType commentType = comment.getCommentType(); String content = comment.getContent(); @@ -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(); } diff --git a/src/main/java/spoon/reflect/visitor/PrinterHelper.java b/src/main/java/spoon/reflect/visitor/PrinterHelper.java index 44140034d74..b051c5b606b 100644 --- a/src/main/java/spoon/reflect/visitor/PrinterHelper.java +++ b/src/main/java/spoon/reflect/visitor/PrinterHelper.java @@ -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,6 +133,7 @@ public PrinterHelper write(char c) { /** * Generates a new line. + * @return current object of PrinterHelper class */ public PrinterHelper writeln() { write(lineSeparator); @@ -158,6 +163,7 @@ protected void autoWriteTabs() { /** * Increments the current number of tabs. + * @return current object of PrinterHelper class */ public PrinterHelper incTab() { nbTabs++; @@ -166,6 +172,7 @@ public PrinterHelper incTab() { /** * Decrements the current number of tabs. + * @return current object of PrinterHelper class */ public PrinterHelper decTab() { nbTabs--; @@ -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; @@ -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 @@ -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 @@ -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;