Skip to content

Commit

Permalink
new nodes types (NodeWithMembers,NodeWithThrowable,NodeWithParameters)
Browse files Browse the repository at this point in the history
moved every node type to a new package
  • Loading branch information
Maximilien CRUZ committed Jul 17, 2016
1 parent aac3f85 commit dce5d3e
Show file tree
Hide file tree
Showing 35 changed files with 492 additions and 331 deletions.
Expand Up @@ -28,12 +28,12 @@
import java.util.List;

import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.TypedNode;
import com.github.javaparser.ast.body.AnnotableNode;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.nodeTypes.AnnotableNode;
import com.github.javaparser.ast.nodeTypes.TypedNode;

public final class PositionUtils {

Expand Down
Expand Up @@ -28,6 +28,7 @@

import com.github.javaparser.Range;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.nodeTypes.NamedNode;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
Expand Down Expand Up @@ -118,8 +119,10 @@ public List<ClassOrInterfaceType> getTypeBound() {
* @param name
* the name to set
*/
public void setName(final String name) {
@Override
public TypeParameter setName(final String name) {
this.name = name;
return this;
}

/**
Expand Down

This file was deleted.

Expand Up @@ -18,21 +18,21 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/

package com.github.javaparser.ast.body;

import static com.github.javaparser.Position.pos;

import java.util.List;

import com.github.javaparser.Range;
import com.github.javaparser.ast.DocumentableNode;
import com.github.javaparser.ast.NamedNode;
import com.github.javaparser.ast.NodeWithModifiers;
import com.github.javaparser.ast.TypedNode;
import com.github.javaparser.ast.comments.JavadocComment;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.nodeTypes.DocumentableNode;
import com.github.javaparser.ast.nodeTypes.NamedNode;
import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
import com.github.javaparser.ast.nodeTypes.TypedNode;
import com.github.javaparser.ast.type.Type;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
Expand Down Expand Up @@ -62,7 +62,8 @@ public AnnotationMemberDeclaration(int modifiers, Type type, String name, Expres
setDefaultValue(defaultValue);
}

public AnnotationMemberDeclaration(int modifiers, List<AnnotationExpr> annotations, Type type, String name, Expression defaultValue) {
public AnnotationMemberDeclaration(int modifiers, List<AnnotationExpr> annotations, Type type, String name,
Expression defaultValue) {
super(annotations);
setModifiers(modifiers);
setType(type);
Expand All @@ -74,11 +75,15 @@ public AnnotationMemberDeclaration(int modifiers, List<AnnotationExpr> annotatio
* @deprecated prefer using Range objects.
*/
@Deprecated
public AnnotationMemberDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List<AnnotationExpr> annotations, Type type, String name, Expression defaultValue) {
this(new Range(pos(beginLine, beginColumn), pos(endLine, endColumn)), modifiers, annotations, type, name, defaultValue);
public AnnotationMemberDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers,
List<AnnotationExpr> annotations, Type type, String name,
Expression defaultValue) {
this(new Range(pos(beginLine, beginColumn), pos(endLine, endColumn)), modifiers, annotations, type, name,
defaultValue);
}

public AnnotationMemberDeclaration(Range range, int modifiers, List<AnnotationExpr> annotations, Type type, String name, Expression defaultValue) {
public AnnotationMemberDeclaration(Range range, int modifiers, List<AnnotationExpr> annotations, Type type,
String name, Expression defaultValue) {
super(range, annotations);
setModifiers(modifiers);
setType(type);
Expand Down Expand Up @@ -126,12 +131,16 @@ public void setDefaultValue(Expression defaultValue) {
setAsParentNodeOf(defaultValue);
}

public void setModifiers(int modifiers) {
@Override
public AnnotationMemberDeclaration setModifiers(int modifiers) {
this.modifiers = modifiers;
return this;
}

public void setName(String name) {
@Override
public AnnotationMemberDeclaration setName(String name) {
this.name = name;
return this;
}

@Override
Expand All @@ -143,7 +152,7 @@ public AnnotationMemberDeclaration setType(Type type) {

@Override
public JavadocComment getJavaDoc() {
if(getComment() instanceof JavadocComment){
if (getComment() instanceof JavadocComment) {
return (JavadocComment) getComment();
}
return null;
Expand Down
Expand Up @@ -18,7 +18,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/

package com.github.javaparser.ast.body;

import static com.github.javaparser.Position.pos;
Expand All @@ -27,53 +27,54 @@
import java.util.List;

import com.github.javaparser.Range;
import com.github.javaparser.ast.NamedNode;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeWithModifiers;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.nodeTypes.AnnotableNode;
import com.github.javaparser.ast.nodeTypes.NamedNode;
import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;

public abstract class BaseParameter<T>
extends Node
implements AnnotableNode<T>, NamedNode<T>, NodeWithModifiers<T>
{
extends Node
implements AnnotableNode<T>, NamedNode<T>, NodeWithModifiers<T> {
private int modifiers;

private List<AnnotationExpr> annotations;

private VariableDeclaratorId id;

public BaseParameter() {
}

public BaseParameter(VariableDeclaratorId id) {
setId(id);
}
}

public BaseParameter(int modifiers, VariableDeclaratorId id) {
public BaseParameter(int modifiers, VariableDeclaratorId id) {
setModifiers(modifiers);
setId(id);
}
public BaseParameter(int modifiers, List<AnnotationExpr> annotations, VariableDeclaratorId id) {
}

public BaseParameter(int modifiers, List<AnnotationExpr> annotations, VariableDeclaratorId id) {
setModifiers(modifiers);
setAnnotations(annotations);
setId(id);
}
}

/**
* @deprecated prefer using Range objects.
*/
@Deprecated
public BaseParameter(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List<AnnotationExpr> annotations, VariableDeclaratorId id) {
public BaseParameter(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers,
List<AnnotationExpr> annotations, VariableDeclaratorId id) {
this(new Range(pos(beginLine, beginColumn), pos(endLine, endColumn)), modifiers, annotations, id);
}

public BaseParameter(final Range range, int modifiers, List<AnnotationExpr> annotations, VariableDeclaratorId id) {
super(range);
super(range);
setModifiers(modifiers);
setAnnotations(annotations);
setId(id);
}
}

/**
* @return the list returned could be immutable (in that case it will be empty)
Expand All @@ -93,6 +94,16 @@ public String getName() {
return getId().getName();
}

@SuppressWarnings("unchecked")
@Override
public T setName(String name) {
if (id != null)
id.setName(name);
else
id = new VariableDeclaratorId(name);
return (T) this;
}

/**
* Return the modifiers of this parameter declaration.
*
Expand All @@ -106,19 +117,25 @@ public int getModifiers() {

/**
* @param annotations a null value is currently treated as an empty list. This behavior could change
* in the future, so please avoid passing null
* in the future, so please avoid passing null
*/
public void setAnnotations(List<AnnotationExpr> annotations) {
@Override
@SuppressWarnings("unchecked")
public T setAnnotations(List<AnnotationExpr> annotations) {
this.annotations = annotations;
setAsParentNodeOf(this.annotations);
return (T) this;
}

public void setId(VariableDeclaratorId id) {
this.id = id;
setAsParentNodeOf(this.id);
}

public void setModifiers(int modifiers) {
@Override
@SuppressWarnings("unchecked")
public T setModifiers(int modifiers) {
this.modifiers = modifiers;
return (T) this;
}
}
Expand Up @@ -29,6 +29,7 @@
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.internal.Utils;
import com.github.javaparser.ast.nodeTypes.AnnotableNode;

/**
* @author Julio Vilmar Gesser
Expand Down Expand Up @@ -68,8 +69,11 @@ public final List<AnnotationExpr> getAnnotations() {
* @param annotations a null value is currently treated as an empty list. This behavior could change
* in the future, so please avoid passing null
*/
public final void setAnnotations(List<AnnotationExpr> annotations) {
@SuppressWarnings("unchecked")
@Override
public final T setAnnotations(List<AnnotationExpr> annotations) {
this.annotations = annotations;
setAsParentNodeOf(this.annotations);
return (T) this;
}
}

0 comments on commit dce5d3e

Please sign in to comment.