Skip to content

Commit

Permalink
Merge pull request #29 from gastaldi/ROASTER-28
Browse files Browse the repository at this point in the history
ROASTER-28: Implemented Javadoc support
  • Loading branch information
gastaldi committed Oct 30, 2014
2 parents 3918a08 + 15d56fd commit cc8e27d
Show file tree
Hide file tree
Showing 19 changed files with 765 additions and 18 deletions.
47 changes: 47 additions & 0 deletions api/src/main/java/org/jboss/forge/roaster/model/JavaDoc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.roaster.model;

import java.util.List;
import java.util.Set;

import org.jboss.forge.roaster.Internal;
import org.jboss.forge.roaster.Origin;

/**
* A {@link JavaDoc} represents Javadoc-style doc comment
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface JavaDoc<O> extends Internal, Origin<O>
{
/**
* Returns the text for this {@link JavaDoc}, excluding tags
*/
String getText();

/**
* Returns the full text for this {@link JavaDoc}, including tags
*/
String getFullText();

/**
* Return the tag names for this {@link JavaDoc}
*/
Set<String> getTagNames();

/**
* Returns a list of {@link JavaDocTag} values for the given tag name (eg: @param) or an empty list if not found
*/
List<JavaDocTag> getTags(String tagName);

/**
* Returns a list of {@link JavaDocTag} values for the given tag name (eg: @param) or an empty list if not found
*/
List<JavaDocTag> getTags();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.roaster.model;

/**
* Represents a {@link JavaType} that may support {@link JavaDoc}
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface JavaDocCapable<O>
{
/**
* Returns the {@link JavaDoc} for this element. Never null.
*/
JavaDoc<O> getJavaDoc();

/**
* Returns if this {@link JavaType} already has a {@link JavaDoc}
*/
boolean hasJavaDoc();
}
28 changes: 28 additions & 0 deletions api/src/main/java/org/jboss/forge/roaster/model/JavaDocTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.roaster.model;

import org.jboss.forge.roaster.Internal;

/**
* Represents a {@link JavaDoc} tag, like the author tag below
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface JavaDocTag extends Internal
{
/**
* The tag name
*/
String getName();

/**
* The tag value
*/
String getValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public interface JavaType<T extends JavaType<T>> extends
Named,
VisibilityScoped,
AnnotationTarget<T>,
Origin<T>
Origin<T>,
JavaDocCapable<T>
{
/**
* Return the canonical name of this {@link T} instance. This is equivalent to calling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.jboss.forge.roaster.model;


/**
* Represents a parameter of a {@link Method}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.roaster.model.source;

import org.jboss.forge.roaster.model.JavaDoc;
import org.jboss.forge.roaster.model.JavaDocCapable;

/**
* Represents a {@link JavaSource} element that can hold {@link JavaDoc}
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface JavaDocCapableSource<O> extends JavaDocCapable<O>
{
@Override
JavaDocSource<O> getJavaDoc();

/**
* Remove the associated {@link JavaDoc}
*/
O removeJavaDoc();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.roaster.model.source;

import org.jboss.forge.roaster.model.JavaDoc;
import org.jboss.forge.roaster.model.JavaDocTag;
import org.jboss.forge.roaster.model.JavaType;

/**
* Represents a {@link JavaDoc} entry of a {@link JavaType}.
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface JavaDocSource<O> extends JavaDoc<O>
{
/**
* Sets the whole {@link JavaDoc} text, including tags
*/
JavaDocSource<O> setFullText(String text);

/**
* Sets the text for this {@link JavaDoc} (without any tags)
*/
JavaDocSource<O> setText(String text);

/**
* Add a tag value for this {@link JavaDocSource}
*/
JavaDocSource<O> addTagValue(String tagName, String tagValue);

/**
* Add a tag value given an existing {@link JavaDocTag}
*/
JavaDocSource<O> addTagValue(JavaDocTag tag);

/**
* Removes the given tagName from this {@link JavaDoc}
*/
JavaDocSource<O> removeTags(String tagName);

/**
* Removes the given {@link JavaDocTag}
*/
JavaDocSource<O> removeTag(JavaDocTag tag);

/**
* Remove all tags
*/
JavaDocSource<O> removeAllTags();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public interface JavaSource<T extends JavaSource<T>> extends JavaType<T>,
Importer<T>,
NamedSource<T>,
VisibilityScopedSource<T>,
AnnotationTargetSource<T, T>
AnnotationTargetSource<T, T>,
JavaDocCapableSource<T>
{
@Override
public JavaSource<?> getEnclosingType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/
public interface MemberSource<O extends JavaSource<O>, T> extends Member<O>, AnnotationTargetSource<O, T>,
VisibilityScopedSource<T>, NamedSource<T>
VisibilityScopedSource<T>, NamedSource<T>, JavaDocCapableSource<T>
{

public T setFinal(boolean finl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public interface ParameterSource<O extends JavaSource<O>> extends Parameter<O>, AnnotationTargetSource<O, ParameterSource<O>>
public interface ParameterSource<O extends JavaSource<O>> extends Parameter<O>,
AnnotationTargetSource<O, ParameterSource<O>>
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.EnumDeclaration;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
Expand All @@ -38,6 +39,7 @@
import org.jboss.forge.roaster.model.ast.TypeDeclarationFinderVisitor;
import org.jboss.forge.roaster.model.source.AnnotationSource;
import org.jboss.forge.roaster.model.source.Import;
import org.jboss.forge.roaster.model.source.JavaDocSource;
import org.jboss.forge.roaster.model.source.JavaSource;
import org.jboss.forge.roaster.model.source.TypeHolderSource;
import org.jboss.forge.roaster.model.util.Formatter;
Expand Down Expand Up @@ -868,6 +870,31 @@ public List<JavaSource<?>> getNestedClasses()
return getNestedTypes();
}

@Override
public JavaDocSource<O> getJavaDoc()
{
Javadoc javadoc = body.getJavadoc();
if (javadoc == null)
{
javadoc = body.getAST().newJavadoc();
body.setJavadoc(javadoc);
}
return new JavaDocImpl<O>((O) this, javadoc);
}

@Override
public O removeJavaDoc()
{
body.setJavadoc(null);
return (O) this;
}

@Override
public boolean hasJavaDoc()
{
return body.getJavadoc() != null;
}

private List<AbstractTypeDeclaration> getNestedDeclarations(BodyDeclaration body)
{
TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jface.text.Document;
Expand All @@ -38,6 +39,7 @@
import org.jboss.forge.roaster.model.source.FieldSource;
import org.jboss.forge.roaster.model.source.Import;
import org.jboss.forge.roaster.model.source.JavaClassSource;
import org.jboss.forge.roaster.model.source.JavaDocSource;
import org.jboss.forge.roaster.model.source.JavaEnumSource;
import org.jboss.forge.roaster.model.source.JavaSource;
import org.jboss.forge.roaster.model.source.MemberSource;
Expand Down Expand Up @@ -883,4 +885,34 @@ public List<JavaSource<?>> getNestedClasses()
return getNestedTypes();
}

@Override
public JavaDocSource<Body> getJavaDoc()
{
BodyDeclaration body = getFirstBodyDeclaration();
Javadoc javadoc = body.getJavadoc();
if (javadoc == null)
{
javadoc = body.getAST().newJavadoc();
body.setJavadoc(javadoc);
}
return new JavaDocImpl<Body>(this, javadoc);
}

@Override
public Body removeJavaDoc()
{
getFirstBodyDeclaration().setJavadoc(null);
return this;
}

@Override
public boolean hasJavaDoc()
{
return getFirstBodyDeclaration().getJavadoc() != null;
}

private BodyDeclaration getFirstBodyDeclaration()
{
return (BodyDeclaration) getBody().bodyDeclarations().get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.jboss.forge.roaster.Roaster;
Expand All @@ -27,6 +28,7 @@
import org.jboss.forge.roaster.model.source.AnnotationSource;
import org.jboss.forge.roaster.model.source.FieldSource;
import org.jboss.forge.roaster.model.source.JavaClassSource;
import org.jboss.forge.roaster.model.source.JavaDocSource;
import org.jboss.forge.roaster.model.source.JavaSource;
import org.jboss.forge.roaster.model.util.Strings;
import org.jboss.forge.roaster.model.util.Types;
Expand Down Expand Up @@ -428,4 +430,28 @@ public boolean isVolatile()
return modifiers.hasModifier(field, ModifierKeyword.VOLATILE_KEYWORD);
}

@Override
public boolean hasJavaDoc()
{
return field.getJavadoc() != null;
}

@Override
public FieldSource<O> removeJavaDoc()
{
field.setJavadoc(null);
return this;
}

@Override
public JavaDocSource<FieldSource<O>> getJavaDoc()
{
Javadoc javadoc = field.getJavadoc();
if (javadoc == null)
{
javadoc = field.getAST().newJavadoc();
field.setJavadoc(javadoc);
}
return new JavaDocImpl<FieldSource<O>>(this, javadoc);
}
}
Loading

0 comments on commit cc8e27d

Please sign in to comment.