Skip to content

Commit

Permalink
Organize imports and source formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanSweet committed Feb 26, 2014
1 parent 2400246 commit a4e11a9
Show file tree
Hide file tree
Showing 35 changed files with 147 additions and 280 deletions.
10 changes: 4 additions & 6 deletions src/com/esotericsoftware/yamlbeans/Beans.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.esotericsoftware.yamlbeans;

import com.esotericsoftware.yamlbeans.YamlConfig.ConstructorParameters;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
Expand All @@ -33,12 +35,8 @@
import java.util.Set;
import java.util.TreeSet;

import com.esotericsoftware.yamlbeans.YamlConfig.ConstructorParameters;

/**
* Utility for dealing with beans and public fields.
* @author <a href="mailto:[email protected]">Nathan Sweet</a>
*/
/** Utility for dealing with beans and public fields.
* @author <a href="mailto:[email protected]">Nathan Sweet</a> */
class Beans {
private Beans () {
}
Expand Down
10 changes: 4 additions & 6 deletions src/com/esotericsoftware/yamlbeans/DeferredConstruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@

package com.esotericsoftware.yamlbeans;

import com.esotericsoftware.yamlbeans.Beans.Property;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import com.esotericsoftware.yamlbeans.Beans.Property;

/**
* Stores a constructor, parameters names, and property values so construction can be deferred until all property values are
/** Stores a constructor, parameters names, and property values so construction can be deferred until all property values are
* known.
* @author <a href="mailto:[email protected]">Nathan Sweet</a>
*/
* @author <a href="mailto:[email protected]">Nathan Sweet</a> */
class DeferredConstruction {
private final Constructor constructor;
private final String[] parameterNames;
Expand Down
6 changes: 2 additions & 4 deletions src/com/esotericsoftware/yamlbeans/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package com.esotericsoftware.yamlbeans;

/**
* Represents the version of a YAML document.
* @author <a href="mailto:[email protected]">Nathan Sweet</a>
*/
/** Represents the version of a YAML document.
* @author <a href="mailto:[email protected]">Nathan Sweet</a> */
public class Version {
public final int major;
public final int minor;
Expand Down
130 changes: 39 additions & 91 deletions src/com/esotericsoftware/yamlbeans/YamlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package com.esotericsoftware.yamlbeans;

import com.esotericsoftware.yamlbeans.Beans.Property;
import com.esotericsoftware.yamlbeans.emitter.EmitterConfig;
import com.esotericsoftware.yamlbeans.scalar.DateSerializer;
import com.esotericsoftware.yamlbeans.scalar.ScalarSerializer;

import java.beans.IntrospectionException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
Expand All @@ -26,24 +31,13 @@
import java.util.IdentityHashMap;
import java.util.Map;

import com.esotericsoftware.yamlbeans.Beans.Property;
import com.esotericsoftware.yamlbeans.emitter.EmitterConfig;
import com.esotericsoftware.yamlbeans.scalar.DateSerializer;
import com.esotericsoftware.yamlbeans.scalar.ScalarSerializer;

/**
* Stores configuration for reading and writing YAML.
* @author <a href="mailto:[email protected]">Nathan Sweet</a>
*/
/** Stores configuration for reading and writing YAML.
* @author <a href="mailto:[email protected]">Nathan Sweet</a> */
public class YamlConfig {
/**
* Configuration for writing YAML.
*/
/** Configuration for writing YAML. */
public final WriteConfig writeConfig = new WriteConfig();

/**
* Configuration for reading YAML.
*/
/** Configuration for reading YAML. */
public final ReadConfig readConfig = new ReadConfig();

final Map<String, String> classNameToTag = new HashMap();
Expand All @@ -65,29 +59,23 @@ public YamlConfig () {
tagToClass.put("tag:yaml.org,2002:float", Float.class);
}

/**
* Allows the specified tag to be used in YAML instead of the full class name.
*/
/** Allows the specified tag to be used in YAML instead of the full class name. */
public void setClassTag (String tag, Class type) {
if (tag == null) throw new IllegalArgumentException("tag cannot be null.");
if (type == null) throw new IllegalArgumentException("type cannot be null.");
classNameToTag.put(type.getName(), tag);
tagToClass.put(tag, type);
}

/**
* Adds a serializer for the specified scalar type.
*/
/** Adds a serializer for the specified scalar type. */
public void setScalarSerializer (Class type, ScalarSerializer serializer) {
if (type == null) throw new IllegalArgumentException("type cannot be null.");
if (serializer == null) throw new IllegalArgumentException("serializer cannot be null.");
scalarSerializers.put(type, serializer);
}

/**
* Sets the default type of elements in a Collection or Map property. No tag will be output for elements of this type. This
* type will be used for each element if no tag is found.
*/
/** Sets the default type of elements in a Collection or Map property. No tag will be output for elements of this type. This
* type will be used for each element if no tag is found. */
public void setPropertyElementType (Class type, String propertyName, Class elementType) {
if (type == null) throw new IllegalArgumentException("type cannot be null.");
if (propertyName == null) throw new IllegalArgumentException("propertyName cannot be null.");
Expand All @@ -109,10 +97,8 @@ public void setPropertyElementType (Class type, String propertyName, Class eleme
propertyToElementType.put(property, elementType);
}

/**
* Sets the default type of a property. No tag will be output for values of this type. This type will be used if no tag is
* found.
*/
/** Sets the default type of a property. No tag will be output for values of this type. This type will be used if no tag is
* found. */
public void setPropertyDefaultType (Class type, String propertyName, Class defaultType) {
if (type == null) throw new IllegalArgumentException("type cannot be null.");
if (propertyName == null) throw new IllegalArgumentException("propertyName cannot be null.");
Expand All @@ -131,23 +117,17 @@ public void setPropertyDefaultType (Class type, String propertyName, Class defau
propertyToDefaultType.put(property, defaultType);
}

/**
* If true, bean properties with both a getter and setter will be used. Default is true.
*/
/** If true, bean properties with both a getter and setter will be used. Default is true. */
public void setBeanProperties (boolean beanProperties) {
this.beanProperties = beanProperties;
}

/**
* If true, private non-transient fields will be used. Default is false.
*/
/** If true, private non-transient fields will be used. Default is false. */
public void setPrivateFields (boolean privateFields) {
this.privateFields = privateFields;
}

/**
* If true, private no-arg constructors will be used. Default is true.
*/
/** If true, private no-arg constructors will be used. Default is true. */
public void setPrivateConstructors (boolean privateConstructors) {
this.privateConstructors = privateConstructors;
}
Expand All @@ -166,102 +146,76 @@ static public class WriteConfig {
emitterConfig.setUseVerbatimTags(false);
}

/**
* If true, the first document will have a document start token (---). Default is false.
*/
/** If true, the first document will have a document start token (---). Default is false. */
public void setExplicitFirstDocument (boolean explicitFirstDocument) {
this.explicitFirstDocument = explicitFirstDocument;
}

/**
* If true, the every document will have a document end token (...). Default is false.
*/
/** If true, the every document will have a document end token (...). Default is false. */
public void setExplicitEndDocument (boolean explicitEndDocument) {
this.explicitEndDocument = explicitEndDocument;
}

/**
* If true, the root of each YAML document will have a tag defining the class that was written, if necessary. Tags are not
/** If true, the root of each YAML document will have a tag defining the class that was written, if necessary. Tags are not
* necessary for primitive types, Strings, {@link ArrayList}, or {@link HashMap}. It is useful to set this to false when
* planning to read the object with the {@link YamlReader#read(Class)} method. Default is true.
*/
* planning to read the object with the {@link YamlReader#read(Class)} method. Default is true. */
public void setWriteRootTags (boolean writeRootTags) {
this.writeRootTags = writeRootTags;
}

/**
* If true, the elements of a Collection or Map root for each YAML document will have a tag defining the class that was
/** If true, the elements of a Collection or Map root for each YAML document will have a tag defining the class that was
* written, if necessary. Tags are not necessary for primitive types, Strings, {@link ArrayList}, or {@link HashMap}. It is
* useful to set this to false when planning to read the object with the {@link YamlReader#read(Class, Class)} method.
* Default is true.
*/
* Default is true. */
public void setWriteRootElementTags (boolean writeRootElementTags) {
this.writeRootElementTags = writeRootElementTags;
}

/**
* If false, object fields with default values will not be written. A prototype object is created to determine the default
* value for each field on the object. Default is false.
*/
/** If false, object fields with default values will not be written. A prototype object is created to determine the default
* value for each field on the object. Default is false. */
public void setWriteDefaultValues (boolean writeDefaultValues) {
this.writeDefaultValues = writeDefaultValues;
}

/**
* If true, values that are referenced multiple times will use an anchor. This works across YAML documents (ie multiple
/** If true, values that are referenced multiple times will use an anchor. This works across YAML documents (ie multiple
* calls to {@link YamlWriter#write(Object)}). When true, objects are not actually written until
* {@link YamlWriter#clearAnchors()} or {@link YamlWriter#close()} is called. If changing auto anchor to false,
* {@link YamlWriter#clearAnchors()} should be called first to output any buffered objects. Default is true.
*/
* {@link YamlWriter#clearAnchors()} should be called first to output any buffered objects. Default is true. */
public void setAutoAnchor (boolean autoAnchor) {
this.autoAnchor = autoAnchor;
}

/**
* Sets the YAML version to output. Default is 1.1.
*/
/** Sets the YAML version to output. Default is 1.1. */
public void setVersion (Version version) {
emitterConfig.setVersion(version);
}

/**
* If true, the YAML output will be canonical. Default is false.
*/
/** If true, the YAML output will be canonical. Default is false. */
public void setCanonical (boolean canonical) {
emitterConfig.setCanonical(canonical);
}

/**
* Sets the number of spaces to indent. Default is 3.
*/
/** Sets the number of spaces to indent. Default is 3. */
public void setIndentSize (int indentSize) {
emitterConfig.setIndentSize(indentSize);
}

/**
* Sets the column at which values will attempt to wrap. Default is 100.
*/
/** Sets the column at which values will attempt to wrap. Default is 100. */
public void setWrapColumn (int wrapColumn) {
emitterConfig.setWrapColumn(wrapColumn);
}

/**
* If false, tags will never be surrounded by angle brackets (eg, "!<java.util.LinkedList>"). Default is false.
*/
/** If false, tags will never be surrounded by angle brackets (eg, "!<java.util.LinkedList>"). Default is false. */
public void setUseVerbatimTags (boolean useVerbatimTags) {
emitterConfig.setUseVerbatimTags(useVerbatimTags);
}

/**
* If false, unicode characters will be output instead of the escaped unicode character code.
*/
/** If false, unicode characters will be output instead of the escaped unicode character code. */
public void setEscapeUnicode (boolean escapeUnicode) {
emitterConfig.setEscapeUnicode(escapeUnicode);
}

/**
* If true, class name tags will always be output.
*/
/** If true, class name tags will always be output. */
public void setAlwaysWriteClassname (boolean write) {
alwaysWriteClassName = write;
}
Expand All @@ -275,25 +229,19 @@ static public class ReadConfig {
ReadConfig () {
}

/**
* Sets the default YAML version to expect if a YAML document does not explicitly specify a version. Default is 1.1.
*/
/** Sets the default YAML version to expect if a YAML document does not explicitly specify a version. Default is 1.1. */
public void setDefaultVersion (Version defaultVersion) {
if (defaultVersion == null) throw new IllegalArgumentException("defaultVersion cannot be null.");
this.defaultVersion = defaultVersion;
}

/**
* Sets the class loader to use to find classes read from the YAML.
*/
/** Sets the class loader to use to find classes read from the YAML. */
public void setClassLoader (ClassLoader classLoader) {
this.classLoader = classLoader;
}

/**
* Sets the names of the constructor parameters so classes without no-arg constructors can be instantiated. The Java 6+
* annotation java.beans.ConstructorProperties can be used instead of this method.
*/
/** Sets the names of the constructor parameters so classes without no-arg constructors can be instantiated. The Java 6+
* annotation java.beans.ConstructorProperties can be used instead of this method. */
public void setConstructorParameters (Class type, Class[] parameterTypes, String[] parameterNames) {
if (type == null) throw new IllegalArgumentException("type cannot be null.");
if (parameterTypes == null) throw new IllegalArgumentException("parameterTypes cannot be null.");
Expand Down
4 changes: 1 addition & 3 deletions src/com/esotericsoftware/yamlbeans/YamlException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import java.io.IOException;

/**
* @author <a href="mailto:[email protected]">Nathan Sweet</a>
*/
/** @author <a href="mailto:[email protected]">Nathan Sweet</a> */
public class YamlException extends IOException {
public YamlException () {
super();
Expand Down
1 change: 0 additions & 1 deletion src/com/esotericsoftware/yamlbeans/YamlWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
Expand Down
26 changes: 12 additions & 14 deletions src/com/esotericsoftware/yamlbeans/emitter/Emitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@

import static com.esotericsoftware.yamlbeans.parser.EventType.*;

import com.esotericsoftware.yamlbeans.parser.CollectionStartEvent;
import com.esotericsoftware.yamlbeans.parser.DocumentEndEvent;
import com.esotericsoftware.yamlbeans.parser.DocumentStartEvent;
import com.esotericsoftware.yamlbeans.parser.Event;
import com.esotericsoftware.yamlbeans.parser.MappingStartEvent;
import com.esotericsoftware.yamlbeans.parser.NodeEvent;
import com.esotericsoftware.yamlbeans.parser.Parser;
import com.esotericsoftware.yamlbeans.parser.ScalarEvent;
import com.esotericsoftware.yamlbeans.parser.SequenceStartEvent;

import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.IOException;
Expand All @@ -32,21 +42,9 @@
import java.util.TreeSet;
import java.util.regex.Pattern;

import com.esotericsoftware.yamlbeans.parser.CollectionStartEvent;
import com.esotericsoftware.yamlbeans.parser.DocumentEndEvent;
import com.esotericsoftware.yamlbeans.parser.DocumentStartEvent;
import com.esotericsoftware.yamlbeans.parser.Event;
import com.esotericsoftware.yamlbeans.parser.MappingStartEvent;
import com.esotericsoftware.yamlbeans.parser.NodeEvent;
import com.esotericsoftware.yamlbeans.parser.Parser;
import com.esotericsoftware.yamlbeans.parser.ScalarEvent;
import com.esotericsoftware.yamlbeans.parser.SequenceStartEvent;

/**
* Converts events into YAML output.
/** Converts events into YAML output.
* @author <a href="mailto:[email protected]">Nathan Sweet</a>
* @author <a href="mailto:[email protected]">Ola Bini</a>
*/
* @author <a href="mailto:[email protected]">Ola Bini</a> */
public class Emitter {
static private final Pattern HANDLE_FORMAT = Pattern.compile("^![-\\w]*!$");
static private final Pattern ANCHOR_FORMAT = Pattern.compile("^[-\\w]*$");
Expand Down
Loading

0 comments on commit a4e11a9

Please sign in to comment.