org.openrewrite.java.tree.Javadoc Maven / Gradle / Ivy
Show all versions of rewrite-java Show documentation
/*
* Copyright 2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java.tree;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.With;
import lombok.experimental.NonFinal;
import org.jspecify.annotations.Nullable;
import org.openrewrite.Cursor;
import org.openrewrite.PrintOutputCapture;
import org.openrewrite.Tree;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.JavadocPrinter;
import org.openrewrite.java.JavadocVisitor;
import org.openrewrite.marker.Markers;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public interface Javadoc extends Tree {
@SuppressWarnings("unchecked")
@Override
default R accept(TreeVisitor v, P p) {
return (R) acceptJavadoc((JavadocVisitor) v, p);
}
@Override
default
boolean isAcceptable(TreeVisitor, P> v, P p) {
return v instanceof JavadocVisitor;
}
default
@Nullable Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.defaultValue(this, p);
}
@Override
default
TreeVisitor, PrintOutputCapture
> printer(Cursor cursor) {
return new JavadocPrinter<>();
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Attribute implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
String name;
@Nullable
List spaceBeforeEqual;
@Nullable
List value;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitAttribute(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Author implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List name;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitAuthor(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Deprecated implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitDeprecated(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class EndElement implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
String name;
List spaceBeforeEndBracket;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitEndElement(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
class DocComment implements Javadoc, Comment {
@With
@EqualsAndHashCode.Include
UUID id;
@With
Markers markers;
@With
List body;
String suffix;
@Override
@SuppressWarnings("unchecked")
public DocComment withSuffix(String suffix) {
if (!suffix.equals(this.suffix)) {
return new DocComment(id, markers, body, suffix);
}
return this;
}
@Override
public boolean isMultiline() {
return true;
}
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitDocComment(this, p);
}
@Override
public
void printComment(Cursor cursor, PrintOutputCapture
print) {
new JavadocPrinter
().visit(this, print, cursor);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class DocRoot implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List endBrace;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitDocRoot(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class DocType implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List text;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitDocType(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Erroneous implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List text;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitErroneous(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class InheritDoc implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List endBrace;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitInheritDoc(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Hidden implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List body;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitHidden(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Index implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List searchTerm;
List description;
List endBrace;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitIndex(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class InlinedValue implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List spaceBeforeTree;
@Nullable
J tree;
List endBrace;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitInlinedValue(this, p);
}
}
/**
* Holds line break plus the margin that starts the next line. The margin in many cases
* ends in a '*'.
*/
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
class LineBreak implements Javadoc {
@EqualsAndHashCode.Include
@With
UUID id;
String margin;
Markers markers;
@Override
public
Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitLineBreak(this, p);
}
public LineBreak withMargin(String margin) {
if (margin.equals(this.margin)) {
return this;
}
return new LineBreak(this.id, margin, this.markers);
}
@Override
@SuppressWarnings("unchecked")
public LineBreak withMarkers(Markers markers) {
if (markers == this.markers) {
return this;
}
return new LineBreak(id, margin, markers);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Link implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
boolean plain;
List spaceBeforeTree;
@Nullable
J tree;
public @Nullable Reference getTreeReference() {
if (tree != null && treeReference == null) {
treeReference = new Reference(Tree.randomId(), Markers.EMPTY, tree, null);
}
return treeReference;
}
// This is non-final to maintain backwards compatibility.
@NonFinal
@Nullable
Reference treeReference;
List label;
List endBrace;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitLink(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Literal implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
boolean code;
List description;
List endBrace;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitLiteral(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Parameter implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List spaceBeforeName;
@Nullable
J name;
public @Nullable Reference getNameReference() {
if (name != null && nameReference == null) {
nameReference = new Reference(Tree.randomId(), Markers.EMPTY, name, null);
}
return nameReference;
}
// This is non-final to maintain backwards compatibility.
@NonFinal
@Nullable
Reference nameReference;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitParameter(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Provides implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List spaceBeforeServiceType;
J serviceType;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitProvides(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Return implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitReturn(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class See implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List spaceBeforeTree;
@Nullable
J tree;
public @Nullable Reference getTreeReference() {
if (tree != null && treeReference == null) {
treeReference = new Reference(Tree.randomId(), Markers.EMPTY, tree, null);
}
return treeReference;
}
// This is non-final to maintain backwards compatibility.
@NonFinal
@Nullable
Reference treeReference;
List reference;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitSee(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Serial implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitSerial(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class SerialData implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitSerialData(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class SerialField implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
J.Identifier name;
J type;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitSerialField(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Since implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitSince(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class StartElement implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
String name;
List attributes;
boolean selfClosing;
List spaceBeforeEndBracket;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitStartElement(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Summary implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List summary;
List beforeBrace;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitSummary(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Text implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
String text;
@Override
public
Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitText(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Throws implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
/**
* {@code @throws} and {@code @exception} are synonyms.
*/
boolean throwsKeyword;
List spaceBeforeExceptionName;
J exceptionName;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitThrows(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class UnknownBlock implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
String name;
List content;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitUnknownBlock(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class UnknownInline implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
String name;
List content;
List endBrace;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitUnknownInline(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Uses implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List beforeServiceType;
J serviceType;
List description;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitUses(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Version implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
Markers markers;
List body;
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitVersion(this, p);
}
}
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@With
class Reference implements Javadoc {
@EqualsAndHashCode.Include
UUID id;
/**
* Not truly nullable, but done for deserialization backwards compatibility since this
* field was accidentally omitted prior to 7.31.0.
*/
@Nullable
Markers markers;
@Override
public Markers getMarkers() {
return markers == null ? Markers.EMPTY : markers;
}
@Nullable
J tree;
@Nullable
List lineBreaks;
public List getLineBreaks() {
return lineBreaks == null ? Collections.emptyList() : lineBreaks;
}
@Override
public Javadoc acceptJavadoc(JavadocVisitor
v, P p) {
return v.visitReference(this, p);
}
}
}