Skip to content

Commit

Permalink
Reduce warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
matozoid committed Dec 15, 2016
1 parent 16ec853 commit 9dfe6cb
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 73 deletions.
3 changes: 3 additions & 0 deletions javaparser-core/bnd.bnd
Expand Up @@ -4,8 +4,11 @@ Bundle-SymbolicName: com.github.javaparser.javaparser-core
# Export all packages except impl
-exportcontents: \
com.github.javaparser, \
com.github.javaparser.printer, \
com.github.javaparser.utils, \
com.github.javaparser.ast, \
com.github.javaparser.ast.body, \
com.github.javaparser.ast.imports, \
com.github.javaparser.ast.comments, \
com.github.javaparser.ast.nodeTypes, \
com.github.javaparser.ast.expr, \
Expand Down
Expand Up @@ -321,6 +321,7 @@ public static ImportDeclaration parseImport(final String importDeclaration) {
* @return Expression representing the Java expression
* @throws ParseProblemException if the source code has parser errors
*/
@SuppressWarnings("unchecked")
public static <T extends Expression> T parseExpression(final String expression) {
return (T) simplifiedParse(EXPRESSION, provider(expression));
}
Expand Down
Expand Up @@ -373,6 +373,7 @@ public <N extends Node> List<N> getNodesByType(Class<N> clazz) {
* @return The data or null of no data was found for the given key
* @see DataKey
*/
@SuppressWarnings("unchecked")
public <M> M getData(final DataKey<M> key) {
if (data == null) {
return null;
Expand Down
Expand Up @@ -15,6 +15,10 @@

/**
* A list of nodes.
* It usually has a parent node.
* Different from normal Nodes, this does not mean that it is a child of that parent.
* Instead, this list will make every node it contains a child of its parent.
* This way, a NodeList does not create an extra level inside the AST.
*
* @param <N> the type of nodes contained.
*/
Expand Down Expand Up @@ -53,15 +57,13 @@ public boolean remove(Node node) {
notifyElementRemoved(index, node);
node.setParentNode(null);
}
boolean remove = innerList.remove(node);
return remove;
return innerList.remove(node);
}

@SafeVarargs
public static <X extends Node> NodeList<X> nodeList(X... nodes) {
final NodeList<X> nodeList = new NodeList<>();
for (X node : nodes) {
nodeList.add(node);
}
Collections.addAll(nodeList, nodes);
return nodeList;
}

Expand All @@ -75,9 +77,7 @@ public static <X extends Node> NodeList<X> nodeList(Collection<X> nodes) {

public static <X extends Node> NodeList<X> nodeList(NodeList<X> nodes) {
final NodeList<X> nodeList = new NodeList<>();
for (X node : nodes) {
nodeList.add(node);
}
nodeList.addAll(nodes);
return nodeList;
}

Expand Down Expand Up @@ -180,7 +180,6 @@ public <A> void accept(final VoidVisitor<A> v, final A arg) {
}

/**
* @param action
* @see java.lang.Iterable#forEach(java.util.function.Consumer)
*/
@Override
Expand All @@ -189,8 +188,6 @@ public void forEach(Consumer<? super N> action) {
}

/**
* @param o
* @return
* @see java.util.List#contains(java.lang.Object)
*/
@Override
Expand All @@ -199,7 +196,6 @@ public boolean contains(Object o) {
}

/**
* @return
* @see java.util.List#toArray()
*/
@Override
Expand All @@ -208,8 +204,6 @@ public Object[] toArray() {
}

/**
* @param a
* @return
* @see java.util.List#toArray(java.lang.Object[])
*/
@Override
Expand All @@ -218,8 +212,6 @@ public <T> T[] toArray(T[] a) {
}

/**
* @param o
* @return
* @see java.util.List#remove(java.lang.Object)
*/
@Override
Expand All @@ -232,8 +224,6 @@ public boolean remove(Object o) {
}

/**
* @param c
* @return
* @see java.util.List#containsAll(java.util.Collection)
*/
@Override
Expand All @@ -242,20 +232,15 @@ public boolean containsAll(Collection<?> c) {
}

/**
* @param c
* @return
* @see java.util.List#addAll(java.util.Collection)
*/
@Override
public boolean addAll(Collection<? extends N> c) {
c.forEach(e -> add(e));
c.forEach(this::add);
return !c.isEmpty();
}

/**
* @param index
* @param c
* @return
* @see java.util.List#addAll(int, java.util.Collection)
*/
@Override
Expand All @@ -267,8 +252,6 @@ public boolean addAll(int index, Collection<? extends N> c) {
}

/**
* @param c
* @return
* @see java.util.List#removeAll(java.util.Collection)
*/
@Override
Expand All @@ -281,8 +264,6 @@ public boolean removeAll(Collection<?> c) {
}

/**
* @param c
* @return
* @see java.util.List#retainAll(java.util.Collection)
*/
@Override
Expand All @@ -297,7 +278,6 @@ public boolean retainAll(Collection<?> c) {
}

/**
* @param operator
* @see java.util.List#replaceAll(java.util.function.UnaryOperator)
*/
@Override
Expand All @@ -308,8 +288,6 @@ public void replaceAll(UnaryOperator<N> operator) {
}

/**
* @param filter
* @return
* @see java.util.Collection#removeIf(java.util.function.Predicate)
*/
@Override
Expand All @@ -332,8 +310,6 @@ public void clear() {
}

/**
* @param o
* @return
* @see java.util.List#equals(java.lang.Object)
*/
@Override
Expand All @@ -342,7 +318,6 @@ public boolean equals(Object o) {
}

/**
* @return
* @see java.util.List#hashCode()
*/
@Override
Expand All @@ -351,8 +326,6 @@ public int hashCode() {
}

/**
* @param o
* @return
* @see java.util.List#indexOf(java.lang.Object)
*/
@Override
Expand All @@ -361,8 +334,6 @@ public int indexOf(Object o) {
}

/**
* @param o
* @return
* @see java.util.List#lastIndexOf(java.lang.Object)
*/
@Override
Expand All @@ -371,7 +342,6 @@ public int lastIndexOf(Object o) {
}

/**
* @return
* @see java.util.List#listIterator()
*/
@Override
Expand All @@ -380,8 +350,6 @@ public ListIterator<N> listIterator() {
}

/**
* @param index
* @return
* @see java.util.List#listIterator(int)
*/
@Override
Expand All @@ -390,7 +358,6 @@ public ListIterator<N> listIterator(int index) {
}

/**
* @return
* @see java.util.Collection#parallelStream()
*/
@Override
Expand All @@ -399,9 +366,6 @@ public Stream<N> parallelStream() {
}

/**
* @param fromIndex
* @param toIndex
* @return
* @see java.util.List#subList(int, int)
*/
@Override
Expand All @@ -410,7 +374,6 @@ public List<N> subList(int fromIndex, int toIndex) {
}

/**
* @return
* @see java.util.List#spliterator()
*/
@Override
Expand Down
Expand Up @@ -135,6 +135,7 @@ public T setModifiers(EnumSet<Modifier> modifiers) {
return (T) this;
}

@SuppressWarnings("unchecked")
@Override
public T setName(SimpleName name) {
notifyPropertyChange(ObservableProperty.NAME, this.name, name);
Expand Down
Expand Up @@ -26,7 +26,7 @@
import com.github.javaparser.ast.body.Parameter;
import com.github.javaparser.ast.nodeTypes.NodeWithParameters;
import com.github.javaparser.ast.observer.ObservableProperty;
import com.github.javaparser.ast.stmt.EmptyStmt;
import com.github.javaparser.ast.stmt.ReturnStmt;
import com.github.javaparser.ast.stmt.Statement;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
Expand All @@ -50,7 +50,7 @@ public class LambdaExpr extends Expression implements
public LambdaExpr() {
this(null,
new NodeList<>(),
new EmptyStmt(),
new ReturnStmt(),
false);
}

Expand Down
Expand Up @@ -63,10 +63,12 @@ public <A> void accept(final VoidVisitor<A> v, final A arg) {
v.visit(this, arg);
}

@Override
public final SimpleName getName() {
return name;
}

@Override
public NameExpr setName(final SimpleName name) {
notifyPropertyChange(ObservableProperty.NAME, this.name, name);
this.name = assertNotNull(name);
Expand Down
Expand Up @@ -14,11 +14,13 @@ default Expression getArgument(int i) {
return getArguments().get(i);
}

@SuppressWarnings("unchecked")
default N addArgument(String arg) {
addArgument(new NameExpr(arg));
return (N) this;
}

@SuppressWarnings("unchecked")
default N addArgument(Expression arg) {
getArguments().add(arg);
return (N) this;
Expand Down
Expand Up @@ -38,6 +38,7 @@ public interface NodeWithName<N extends Node> {

N setName(Name name);

@SuppressWarnings("unchecked")
default N setName(String name) {
setName(parse(name));
return (N) this;
Expand Down
Expand Up @@ -56,11 +56,13 @@ public interface NodeWithType<N extends Node, T extends Type> {
* @param typeClass the type
* @return this
*/
@SuppressWarnings("unchecked")
default N setType(Class<?> typeClass) {
((Node) this).tryAddImportToParentCompilationUnit(typeClass);
return setType((T) new ClassOrInterfaceType(typeClass.getSimpleName()));
}

@SuppressWarnings("unchecked")
default N setType(final String type) {
ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(type);
return setType((T) classOrInterfaceType);
Expand Down
Expand Up @@ -39,7 +39,7 @@ public final class DoStmt extends Statement implements NodeWithBody<DoStmt> {
private Expression condition;

public DoStmt() {
this(null, new EmptyStmt(), new BooleanLiteralExpr());
this(null, new ReturnStmt(), new BooleanLiteralExpr());
}

public DoStmt(final Statement body, final Expression condition) {
Expand Down
Expand Up @@ -52,7 +52,7 @@ public ForStmt() {
new NodeList<>(),
new BooleanLiteralExpr(),
new NodeList<>(),
new EmptyStmt());
new ReturnStmt());
}

public ForStmt(final NodeList<Expression> initialization, final Expression compare,
Expand Down
Expand Up @@ -47,7 +47,7 @@ public ForeachStmt() {
this(null,
new VariableDeclarationExpr(),
new NameExpr(),
new EmptyStmt());
new ReturnStmt());
}

public ForeachStmt(final VariableDeclarationExpr variable,
Expand Down
Expand Up @@ -46,7 +46,7 @@ public final class IfStmt extends Statement {
public IfStmt() {
this(null,
new BooleanLiteralExpr(),
new EmptyStmt(),
new ReturnStmt(),
null);
}

Expand Down

0 comments on commit 9dfe6cb

Please sign in to comment.