Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: kayahr/jasdoc
base: d1632543ac
...
head fork: kayahr/jasdoc
compare: 13b7b7a6db
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 25 files changed
  • 0 commit comments
  • 1 contributor
Showing with 929 additions and 107 deletions.
  1. +10 −9 src/main/java/de/ailis/jasdoc/annotations/EnumAnnotation.java
  2. +2 −2 src/main/java/de/ailis/jasdoc/annotations/ParamAnnotation.java
  3. +2 −2 src/main/java/de/ailis/jasdoc/annotations/ReturnAnnotation.java
  4. +6 −6 src/main/java/de/ailis/jasdoc/annotations/TypeAnnotation.java
  5. +20 −19 src/main/java/de/ailis/jasdoc/doc/DocTreeBuilder.java
  6. +3 −1 src/main/java/de/ailis/jasdoc/doc/FunctionDoc.java
  7. +0 −66 src/main/java/de/ailis/jasdoc/doc/JsType.java
  8. +3 −1 src/main/java/de/ailis/jasdoc/doc/ParamDoc.java
  9. +3 −1 src/main/java/de/ailis/jasdoc/doc/PropertyDoc.java
  10. +24 −0 src/main/java/de/ailis/jasdoc/doc/types/AnyType.java
  11. +47 −0 src/main/java/de/ailis/jasdoc/doc/types/ArrayType.java
  12. +23 −0 src/main/java/de/ailis/jasdoc/doc/types/BooleanType.java
  13. +48 −0 src/main/java/de/ailis/jasdoc/doc/types/CustomType.java
  14. +216 −0 src/main/java/de/ailis/jasdoc/doc/types/JsType.java
  15. +68 −0 src/main/java/de/ailis/jasdoc/doc/types/MapType.java
  16. +48 −0 src/main/java/de/ailis/jasdoc/doc/types/NonNullType.java
  17. +48 −0 src/main/java/de/ailis/jasdoc/doc/types/NullableType.java
  18. +23 −0 src/main/java/de/ailis/jasdoc/doc/types/NumberType.java
  19. +16 −0 src/main/java/de/ailis/jasdoc/doc/types/ObjectType.java
  20. +48 −0 src/main/java/de/ailis/jasdoc/doc/types/OptionalType.java
  21. +16 −0 src/main/java/de/ailis/jasdoc/doc/types/PrimitiveType.java
  22. +23 −0 src/main/java/de/ailis/jasdoc/doc/types/StringType.java
  23. +48 −0 src/main/java/de/ailis/jasdoc/doc/types/VarArgType.java
  24. +24 −0 src/main/java/de/ailis/jasdoc/doc/types/VoidType.java
  25. +160 −0 src/test/java/de/ailis/jasdoc/doc/types/JsTypeTest.java
View
19 src/main/java/de/ailis/jasdoc/annotations/EnumAnnotation.java
@@ -8,24 +8,25 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import de.ailis.jasdoc.doc.JsType;
+import de.ailis.jasdoc.doc.types.AnyType;
+import de.ailis.jasdoc.doc.types.JsType;
/**
* Enum annotation.
- *
+ *
* @author Klaus Reimer (k@ailis.de)
*/
public class EnumAnnotation implements UniqueAnnotation
{
/** The logger. */
private static final Log LOG = LogFactory.getLog(EnumAnnotation.class);
-
+
/** The type. */
private final JsType type;
/**
* Constructor.
- *
+ *
* @param type
* The type. Must not be null.
*/
@@ -37,7 +38,7 @@ public EnumAnnotation(final JsType type)
/**
* Creates a new enum annotation with the specified annotation arguments.
- *
+ *
* @param arg
* The annotation arguments.
*/
@@ -47,15 +48,15 @@ public EnumAnnotation(final JsType type)
if (arg.isEmpty())
{
LOG.warn("@enum annotation without type. Assuming any type.");
- this.type = JsType.ANY;
+ this.type = new AnyType();
}
else
- this.type = new JsType(arg);
+ this.type = JsType.parseInitial(arg);
}
-
+
/**
* Returns the type.
- *
+ *
* @return The type.
*/
public JsType getType()
View
4 src/main/java/de/ailis/jasdoc/annotations/ParamAnnotation.java
@@ -5,7 +5,7 @@
package de.ailis.jasdoc.annotations;
-import de.ailis.jasdoc.doc.JsType;
+import de.ailis.jasdoc.doc.types.JsType;
import de.ailis.jasdoc.util.HTMLUtils;
/**
@@ -58,7 +58,7 @@ public ParamAnnotation(final JsType type, final String name,
if (parts.length < 2)
throw new IllegalArgumentException(
"Not enough arguments for param annotation");
- this.type = new JsType(parts[0]);
+ this.type = JsType.parseInitial(parts[0]);
this.name = HTMLUtils.strip(parts[1]);
this.description = parts.length == 3 ? HTMLUtils.clean(parts[2]) : "";
}
View
4 src/main/java/de/ailis/jasdoc/annotations/ReturnAnnotation.java
@@ -5,7 +5,7 @@
package de.ailis.jasdoc.annotations;
-import de.ailis.jasdoc.doc.JsType;
+import de.ailis.jasdoc.doc.types.JsType;
import de.ailis.jasdoc.util.HTMLUtils;
/**
@@ -50,7 +50,7 @@ public ReturnAnnotation(final JsType type, final String description)
if (parts.length < 1)
throw new IllegalArgumentException(
"Not enough arguments for return annotation");
- this.type = new JsType(parts[0]);
+ this.type = JsType.parseInitial(parts[0]);
this.description = parts.length == 2 ? HTMLUtils.clean(parts[1]) : "";
}
View
12 src/main/java/de/ailis/jasdoc/annotations/TypeAnnotation.java
@@ -5,11 +5,11 @@
package de.ailis.jasdoc.annotations;
-import de.ailis.jasdoc.doc.JsType;
+import de.ailis.jasdoc.doc.types.JsType;
/**
* Type annotation.
- *
+ *
* @author Klaus Reimer (k@ailis.de)
*/
public class TypeAnnotation implements UniqueAnnotation
@@ -19,7 +19,7 @@
/**
* Constructor.
- *
+ *
* @param type
* The type. Must not be null.
*/
@@ -31,7 +31,7 @@ public TypeAnnotation(final JsType type)
/**
* Creates a new type annotation with the specified annotation arguments.
- *
+ *
* @param arg
* The annotation arguments.
*/
@@ -40,12 +40,12 @@ public TypeAnnotation(final JsType type)
if (arg == null) throw new IllegalArgumentException("arg is null");
if (arg.isEmpty())
throw new IllegalArgumentException("@type annotation without type");
- this.type = new JsType(arg);
+ this.type = JsType.parseInitial(arg);
}
/**
* Returns the type.
- *
+ *
* @return The type.
*/
public JsType getType()
View
39 src/main/java/de/ailis/jasdoc/doc/DocTreeBuilder.java
@@ -27,11 +27,12 @@
import de.ailis.jasdoc.annotations.EnumAnnotation;
import de.ailis.jasdoc.annotations.InterfaceAnnotation;
import de.ailis.jasdoc.annotations.TypeAnnotation;
+import de.ailis.jasdoc.doc.types.JsType;
/**
* Builds a documentation tree. Let it visit all the parsed JavaScript root
* nodes.
- *
+ *
* @author Klaus Reimer (k@ailis.de)
*/
public class DocTreeBuilder implements NodeVisitor
@@ -47,7 +48,7 @@
/**
* Constructor.
- *
+ *
* @param config
* The documentation parser configuration.
*/
@@ -86,7 +87,7 @@ public boolean visit(final AstNode node)
/**
* Visits a variable declaration.
- *
+ *
* @param node
* The variable declaration node.
* @param scope
@@ -129,7 +130,7 @@ else if (initializer.getType() == Token.OBJECTLIT)
/**
* Visits an expression statement.
- *
+ *
* @param node
* The expression statement node.
* @param scope
@@ -150,7 +151,7 @@ else if (expression.getType() == Token.NAME)
/**
* Returns the JavaScript documentation string from the specified node. If
* it doesn't have one then the specified fallback is returned instead
- *
+ *
* @param node
* The node to read the documentation string from.
* @param fallback
@@ -166,7 +167,7 @@ private String getJsDoc(final AstNode node, final String fallback)
/**
* Visits an assignment.
- *
+ *
* @param node
* The assignment node.
* @param scope
@@ -222,7 +223,7 @@ else if (right.getType() == Token.OBJECTLIT)
/**
* Visits a function node.
- *
+ *
* @param node
* The function node to visit.
* @param name
@@ -260,7 +261,7 @@ private boolean visitFunctionNode(final FunctionNode node,
addSymbol(scope,
new InterfaceDoc(funcName, annotations, scope));
}
-
+
// Check if function is actually a class constructor. When this is
// the case then we are adding a class instead of a function
else if (annotations.isAnnotationPresent(ConstructorAnnotation.class)
@@ -290,7 +291,7 @@ else if (annotations.isAnnotationPresent(ConstructorAnnotation.class)
/**
* Visits a enum node.
- *
+ *
* @param node
* The enum node to visit.
* @param name
@@ -336,7 +337,7 @@ private boolean visitEnum(final ObjectLiteral node, final String name,
/**
* Visits a object literal node.
- *
+ *
* @param node
* The object literal node to visit.
* @param name
@@ -396,7 +397,7 @@ else if (right.getType() == Token.FUNCTION)
/**
* Visits a property name node.
- *
+ *
* @param node
* The property name node to visit.
* @param jsDoc
@@ -416,7 +417,7 @@ private boolean visitPropertyName(final Name node, final String jsDoc,
/**
* Visits a property value node.
- *
+ *
* @param node
* The property value node to visit.
* @param name
@@ -439,7 +440,7 @@ private boolean visitPropertyValue(final AstNode node,
/**
* Creates and returns the scope described by the specified node.
- *
+ *
* @param node
* The scope node.
* @param parentScope
@@ -481,7 +482,7 @@ else if (node.getType() == Token.THIS)
/**
* Returns the root scope documentation.
- *
+ *
* @return The root scope documentation. Never null.
*/
public GlobalDoc getGlobalScope()
@@ -491,7 +492,7 @@ public GlobalDoc getGlobalScope()
/**
* Adds a symbol to the specified scope.
- *
+ *
* @param scope
* The scope
* @param symbol
@@ -506,7 +507,7 @@ private void addSymbol(final ScopeDoc scope, final SymbolDoc symbol)
/**
* Processes a function parameter.
- *
+ *
* @param node
* The parameter node.
* @param function
@@ -533,13 +534,13 @@ public void applyFixes()
/**
* Recursively applies special fixes to the specified scope.
- *
+ *
* @param scope
* The scope to apply special fixes to.
*/
- private void applyFixes(ScopeDoc scope)
+ private void applyFixes(final ScopeDoc scope)
{
- for (ScopeDoc subScope: scope.getScopes())
+ for (final ScopeDoc subScope: scope.getScopes())
applyFixes(subScope);
if (!scope.isNamespace() && (scope.getNamespaceScopes().size() > 0)
|| scope.getClasses().size() > 0 || scope.getEnums().size() > 0
View
4 src/main/java/de/ailis/jasdoc/doc/FunctionDoc.java
@@ -15,6 +15,8 @@
import de.ailis.jasdoc.annotations.Annotations;
import de.ailis.jasdoc.annotations.ReturnAnnotation;
+import de.ailis.jasdoc.doc.types.JsType;
+import de.ailis.jasdoc.doc.types.VoidType;
/**
@@ -77,7 +79,7 @@ public JsType getReturnType()
{
final ReturnAnnotation returnAnno =
this.annotations.getAnnotation(ReturnAnnotation.class);
- return returnAnno != null ? returnAnno.getType() : JsType.VOID;
+ return returnAnno != null ? returnAnno.getType() : new VoidType();
}
/**
View
66 src/main/java/de/ailis/jasdoc/doc/JsType.java
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
- * See LICENSE.txt for licensing information.
- */
-
-package de.ailis.jasdoc.doc;
-
-/**
- * JavaScript type.
- *
- * @author Klaus Reimer (k@ailis.de)
- */
-public class JsType
-{
- /** The ANY type. */
- public static final JsType ANY = new JsType("{*}");
-
- /** The VOID type. */
- public static final JsType VOID = new JsType("{void}");
-
- /** The type expression. */
- private final String expression;
-
- /**
- * Constructor.
- *
- * @param expression
- * The type expression.
- */
- public JsType(final String expression)
- {
- if (expression.startsWith("{") && expression.endsWith("}"))
- this.expression = expression.substring(1, expression.length() - 1);
- else
- this.expression = expression;
- }
-
- /**
- * Returns the type expression.
- *
- * @return The type expression.
- */
- public String getExpression()
- {
- return this.expression;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return getExpression();
- }
-
- /**
- * Checks if this type is void.
- *
- * @return True if type is void, false if not.
- */
- public boolean isVoid()
- {
- return this == VOID;
- }
-}
View
4 src/main/java/de/ailis/jasdoc/doc/ParamDoc.java
@@ -9,6 +9,8 @@
import de.ailis.jasdoc.annotations.DescriptionAnnotation;
import de.ailis.jasdoc.annotations.ParamAnnotation;
import de.ailis.jasdoc.annotations.TypeAnnotation;
+import de.ailis.jasdoc.doc.types.AnyType;
+import de.ailis.jasdoc.doc.types.JsType;
/**
@@ -79,6 +81,6 @@ public JsType getType()
// function
final ParamAnnotation param =
this.function.getAnnotations().getParamAnnotation(this.name);
- return param != null ? param.getType() : JsType.ANY;
+ return param != null ? param.getType() : new AnyType();
}
}
View
4 src/main/java/de/ailis/jasdoc/doc/PropertyDoc.java
@@ -8,6 +8,8 @@
import de.ailis.jasdoc.annotations.Annotations;
import de.ailis.jasdoc.annotations.ConstAnnotation;
import de.ailis.jasdoc.annotations.TypeAnnotation;
+import de.ailis.jasdoc.doc.types.AnyType;
+import de.ailis.jasdoc.doc.types.JsType;
/**
* Property documentation.
@@ -45,7 +47,7 @@ public JsType getType()
{
final TypeAnnotation type =
this.annotations.getAnnotation(TypeAnnotation.class);
- if (type == null) return JsType.ANY;
+ if (type == null) return new AnyType();
return type.getType();
}
View
24 src/main/java/de/ailis/jasdoc/doc/types/AnyType.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+
+/**
+ * The "any" type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public class AnyType extends JsType
+{
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "*";
+ }
+}
View
47 src/main/java/de/ailis/jasdoc/doc/types/ArrayType.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Array type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class ArrayType extends ObjectType
+{
+ /** The array type. */
+ private final JsType type;
+
+ /**
+ * Constructor.
+ *
+ * @param type
+ * The array type. Must not be null.
+ */
+ public ArrayType(final JsType type)
+ {
+ this.type = type;
+ }
+
+ /**
+ * Returns the array type.
+ *
+ * @return The array type. Never null.
+ */
+ public JsType getType()
+ {
+ return this.type;
+ }
+
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "Array.<" + this.type.getExpression() + ">";
+ }
+}
View
23 src/main/java/de/ailis/jasdoc/doc/types/BooleanType.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Primitive boolean type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public class BooleanType extends PrimitiveType
+{
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "boolean";
+ }
+}
View
48 src/main/java/de/ailis/jasdoc/doc/types/CustomType.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Array type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class CustomType extends ObjectType
+{
+ /** The type name. */
+ private final String name;
+
+ /**
+ * Constructor.
+ *
+ * @param name
+ * The type name. Must not be null.
+ */
+ public CustomType(final String name)
+ {
+ if (name == null) throw new IllegalArgumentException("name is null");
+ this.name = name;
+ }
+
+ /**
+ * Returns the type name.
+ *
+ * @return The type name. Never null.
+ */
+ public String getName()
+ {
+ return this.name;
+ }
+
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return this.name;
+ }
+}
View
216 src/main/java/de/ailis/jasdoc/doc/types/JsType.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+
+
+/**
+ * Base type for all types and factory to convert a type expression into a
+ * concrete type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public abstract class JsType
+{
+ /**
+ * Performs an initial parsing of a type expression. This means top-level
+ * curly braces are removed before starting the real type parsing. This
+ * allows to support type expressions like "number" and "{number}".
+ *
+ * @param expression
+ * The type expression.
+ * @return The concrete type.
+ */
+ public static JsType parseInitial(final String expression)
+ {
+ if (expression.startsWith("{") && expression.endsWith("}"))
+ return parse(expression.substring(1, expression.length() - 1));
+ else
+ return parse(expression);
+ }
+
+ /**
+ * Converts the specified type expression into a concrete type.
+ *
+ * @param expression
+ * The type expression.
+ * @return The concrete type.
+ */
+ public static JsType parse(final String expression)
+ {
+ if ("void".equals(expression))
+ return new VoidType();
+ if ("*".equals(expression))
+ return new AnyType();
+ if ("string".equals(expression))
+ return new StringType();
+ if ("number".equals(expression))
+ return new NumberType();
+ if ("boolean".equals(expression))
+ return new BooleanType();
+ if (expression.startsWith("..."))
+ return new VarArgType(JsType.parse(expression.substring(3)));
+ if (expression.endsWith("="))
+ return new OptionalType(JsType.parse(expression.substring(0,
+ expression.length() - 1)));
+ if (expression.startsWith("!"))
+ return new NonNullType(JsType.parse(expression.substring(1)));
+ if (expression.startsWith("?"))
+ return new NullableType(JsType.parse(expression.substring(1)));
+ if (expression.startsWith("Array.<"))
+ return new ArrayType(JsType.parse(expression.substring(
+ 7, findEnd(expression, 6))));
+ if (expression.startsWith("Object.<"))
+ {
+ final int end = findEnd(expression, 7);
+ final String[] args = split(expression.substring(8, end), ',');
+ if (args.length == 2)
+ return new MapType(JsType.parse(args[0]), JsType.parse(args[1]));
+ }
+ return new CustomType(expression);
+ }
+
+ /**
+ * Splits an expression by the specified separator but keeps track of
+ * brackets so separator characters inside of a sub type are ignored. The
+ * splitted parts are also trimmed.
+ *
+ * @param expression
+ * The expression to split.
+ * @param separator
+ * The separator character.
+ * @return The splitted expression parts.
+ */
+ private static String[]
+ split(final String expression, final char separator)
+ {
+ final List<String> parts = new ArrayList<String>();
+ int start = 0;
+ int level = 0;
+ final int len = expression.length();
+ for (int i = 0; i < len; i += 1)
+ {
+ final char c = expression.charAt(i);
+ if (c == separator)
+ {
+ if (level == 0)
+ {
+ parts.add(expression.substring(start, i).trim());
+ start = i + 1;
+ }
+ }
+ if (c == '{' || c == '<' || c == '[' || c == '(')
+ level += 1;
+ else if (c == '}' || c == '>' || c == ']' || c == ')')
+ level -= 1;
+ }
+ if (start <= len) parts.add(expression.substring(start, len).trim());
+ return parts.toArray(new String[parts.size()]);
+ }
+
+ /**
+ * Searches the end index for a specific bracket.
+ *
+ * @param e
+ * The type expression to search in.
+ * @param start
+ * The start index pointing at the opening bracket.
+ * @return The end index.
+ */
+ private static int findEnd(final String e, final int start)
+ {
+ final char startChar = e.charAt(start);
+ final int len = e.length();
+ int level = 0;
+ char endChar;
+
+ switch (startChar)
+ {
+ case '(':
+ endChar = ')';
+ break;
+ case '<':
+ endChar = '>';
+ break;
+ case '{':
+ endChar = '}';
+ break;
+ case '[':
+ endChar = '}';
+ break;
+ default:
+ return len;
+ }
+ for (int i = start + 1; i < len; i += 1)
+ {
+ final char c = e.charAt(i);
+ if (c == endChar)
+ {
+ if (level == 0) return i;
+ level -= 1;
+ }
+ else if (c == startChar)
+ {
+ level += 1;
+ }
+ }
+ return len;
+ }
+
+ /**
+ * Returns the expression of this type.
+ *
+ * @return The type expression.
+ */
+ public abstract String getExpression();
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public final String toString()
+ {
+ return getExpression();
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public final boolean equals(final Object obj)
+ {
+ if (obj == null) return false;
+ if (obj == this) return true;
+ if (obj.getClass() != getClass()) return false;
+ final JsType other = (JsType) obj;
+ return new EqualsBuilder().append(getExpression(),
+ other.getExpression())
+ .isEquals();
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public final int hashCode()
+ {
+ return getExpression().hashCode();
+ }
+
+ /**
+ * Checks if this type is void.
+ *
+ * @return True if type is void, false if not.
+ */
+ public boolean isVoid()
+ {
+ return this.getClass() == VoidType.class;
+ }
+}
View
68 src/main/java/de/ailis/jasdoc/doc/types/MapType.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Map type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class MapType extends ObjectType
+{
+ /** The key type. */
+ private final JsType keyType;
+
+ /** The value type. */
+ private final JsType valueType;
+
+ /**
+ * Constructor.
+ *
+ * @param keyType
+ * The key type. Must not be null.
+ * @param valueType
+ * The value type. Must not be null.
+ */
+ public MapType(final JsType keyType, final JsType valueType)
+ {
+ if (keyType == null)
+ throw new IllegalArgumentException("keyType is null");
+ if (valueType == null)
+ throw new IllegalArgumentException("valueType is null");
+ this.keyType = keyType;
+ this.valueType = valueType;
+ }
+
+ /**
+ * Returns the key type.
+ *
+ * @return The key type. Never null.
+ */
+ public JsType getKeyType()
+ {
+ return this.keyType;
+ }
+
+ /**
+ * Returns the value type.
+ *
+ * @return The value type. Never null.
+ */
+ public JsType getValueType()
+ {
+ return this.valueType;
+ }
+
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "Object.<" + this.keyType.getExpression() + ","
+ + this.valueType.getExpression() + ">";
+ }
+}
View
48 src/main/java/de/ailis/jasdoc/doc/types/NonNullType.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Non Nullable type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class NonNullType extends JsType
+{
+ /** The non nullable type. */
+ private final JsType type;
+
+ /**
+ * Constructor.
+ *
+ * @param type
+ * The non nullable type. Must not be null.
+ */
+ public NonNullType(final JsType type)
+ {
+ if (type == null) throw new IllegalArgumentException("type is null");
+ this.type = type;
+ }
+
+ /**
+ * Returns the non nullable type.
+ *
+ * @return The non nullable. Never null.
+ */
+ public JsType getType()
+ {
+ return this.type;
+ }
+
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "!" + this.type.getExpression();
+ }
+}
View
48 src/main/java/de/ailis/jasdoc/doc/types/NullableType.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Nullable type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class NullableType extends JsType
+{
+ /** The nullable type. */
+ private final JsType type;
+
+ /**
+ * Constructor.
+ *
+ * @param type
+ * The nullable type. Must not be null.
+ */
+ public NullableType(final JsType type)
+ {
+ if (type == null) throw new IllegalArgumentException("type is null");
+ this.type = type;
+ }
+
+ /**
+ * Returns the nullable type.
+ *
+ * @return The nullable. Never null.
+ */
+ public JsType getType()
+ {
+ return this.type;
+ }
+
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "?" + this.type.getExpression();
+ }
+}
View
23 src/main/java/de/ailis/jasdoc/doc/types/NumberType.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Primitive number type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class NumberType extends PrimitiveType
+{
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "number";
+ }
+}
View
16 src/main/java/de/ailis/jasdoc/doc/types/ObjectType.java
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Base class for object types (array, map, custom).
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public abstract class ObjectType extends JsType
+{
+ // Empty
+}
View
48 src/main/java/de/ailis/jasdoc/doc/types/OptionalType.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Optional type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class OptionalType extends JsType
+{
+ /** The optional type. */
+ private final JsType type;
+
+ /**
+ * Constructor.
+ *
+ * @param type
+ * The optional type. Must not be null.
+ */
+ public OptionalType(final JsType type)
+ {
+ if (type == null) throw new IllegalArgumentException("type is null");
+ this.type = type;
+ }
+
+ /**
+ * Returns the optional type.
+ *
+ * @return The optional type. Never null.
+ */
+ public JsType getType()
+ {
+ return this.type;
+ }
+
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return this.type.getExpression() + "=";
+ }
+}
View
16 src/main/java/de/ailis/jasdoc/doc/types/PrimitiveType.java
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Base class for primitive types (string, number, boolean).
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public abstract class PrimitiveType extends JsType
+{
+ // Empty
+}
View
23 src/main/java/de/ailis/jasdoc/doc/types/StringType.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Primitive string type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class StringType extends PrimitiveType
+{
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "string";
+ }
+}
View
48 src/main/java/de/ailis/jasdoc/doc/types/VarArgType.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+/**
+ * Variable argument type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class VarArgType extends JsType
+{
+ /** The variable argument type. */
+ private final JsType type;
+
+ /**
+ * Constructor.
+ *
+ * @param type
+ * The variable argument type. Must not be null.
+ */
+ public VarArgType(final JsType type)
+ {
+ if (type == null) throw new IllegalArgumentException("type is null");
+ this.type = type;
+ }
+
+ /**
+ * Returns the variable argument type.
+ *
+ * @return The variable argument type. Never null.
+ */
+ public JsType getType()
+ {
+ return this.type;
+ }
+
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "..." + this.type.getExpression();
+ }
+}
View
24 src/main/java/de/ailis/jasdoc/doc/types/VoidType.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+
+/**
+ * The "void" type.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public final class VoidType extends JsType
+{
+ /**
+ * @see de.ailis.jasdoc.doc.types.JsType#getExpression()
+ */
+ @Override
+ public String getExpression()
+ {
+ return "void";
+ }
+}
View
160 src/test/java/de/ailis/jasdoc/doc/types/JsTypeTest.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
+ * See LICENSE.txt for licensing information.
+ */
+
+package de.ailis.jasdoc.doc.types;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Tests the JsType class.
+ *
+ * @author Klaus Reimer (k@ailis.de)
+ */
+public class JsTypeTest
+{
+ /**
+ * Tests parsing a void type.
+ */
+ @Test
+ public void testParseVoid()
+ {
+ final JsType type = JsType.parse("void");
+ assertEquals(VoidType.class, type.getClass());
+ assertEquals("void", type.getExpression());
+ }
+
+ /**
+ * Tests parsing a ANY type.
+ */
+ @Test
+ public void testParseAny()
+ {
+ final JsType type = JsType.parse("*");
+ assertEquals(AnyType.class, type.getClass());
+ assertEquals("*", type.getExpression());
+ }
+
+ /**
+ * Tests parsing a string type.
+ */
+ @Test
+ public void testParseString()
+ {
+ final StringType type = (StringType) JsType.parse("string");
+ assertEquals("string", type.getExpression());
+ }
+
+ /**
+ * Tests parsing a boolean type.
+ */
+ @Test
+ public void testParseBoolean()
+ {
+ final BooleanType type = (BooleanType) JsType.parse("boolean");
+ assertEquals("boolean", type.getExpression());
+ }
+
+ /**
+ * Tests parsing a number type.
+ */
+ @Test
+ public void testParseNumber()
+ {
+ final NumberType type = (NumberType) JsType.parse("number");
+ assertEquals("number", type.getExpression());
+ }
+
+ /**
+ * Tests parsing a variable argument type.
+ */
+ @Test
+ public void testParseVarArg()
+ {
+ final VarArgType type = (VarArgType) JsType.parse("...number");
+ assertEquals(NumberType.class, type.getType().getClass());
+ assertEquals("...number", type.getExpression());
+ }
+
+ /**
+ * Tests parsing an optional argument type.
+ */
+ @Test
+ public void testParseOptional()
+ {
+ final OptionalType type = (OptionalType) JsType.parse("number=");
+ assertEquals(NumberType.class, type.getType().getClass());
+ assertEquals("number=", type.getExpression());
+ }
+
+ /**
+ * Tests parsing a nullable argument type.
+ */
+ @Test
+ public void testParseNullable()
+ {
+ final NullableType type = (NullableType) JsType.parse("?number");
+ assertEquals(NumberType.class, type.getType().getClass());
+ assertEquals("?number", type.getExpression());
+ }
+
+ /**
+ * Tests parsing a non nullable argument type.
+ */
+ @Test
+ public void testParseNonNullable()
+ {
+ final NonNullType type = (NonNullType) JsType.parse("!number");
+ assertEquals(NumberType.class, type.getType().getClass());
+ assertEquals("!number", type.getExpression());
+ }
+
+ /**
+ * Tests parsing an array type.
+ */
+ @Test
+ public void testParseArray()
+ {
+ final ArrayType type = (ArrayType) JsType.parse("Array.<number>");
+ assertEquals(NumberType.class, type.getType().getClass());
+ assertEquals("Array.<number>", type.getExpression());
+ }
+
+ /**
+ * Tests parsing an array type.
+ */
+ @Test
+ public void testParseArrayArray()
+ {
+ final ArrayType type = (ArrayType) JsType.parse("Array.<Array.<number>>");
+ final ArrayType subType = (ArrayType) type.getType();
+ assertEquals(NumberType.class, subType.getType().getClass());
+ assertEquals("Array.<Array.<number>>", type.getExpression());
+ }
+
+ /**
+ * Tests parsing an array type.
+ */
+ @Test
+ public void testParseCustom()
+ {
+ final CustomType type = (CustomType) JsType.parse("namespace.SomeClass");
+ assertEquals("namespace.SomeClass", type.getName());
+ assertEquals("namespace.SomeClass", type.getExpression());
+ }
+
+ /**
+ * Tests parsing a map type.
+ */
+ @Test
+ public void testParseMap()
+ {
+ final MapType type = (MapType) JsType.parse("Object.<string,number>");
+ assertEquals(StringType.class, type.getKeyType().getClass());
+ assertEquals(NumberType.class, type.getValueType().getClass());
+ assertEquals("Object.<string,number>", type.getExpression());
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.