- Revision
- 1380
- Author
- rfscholte
- Date
- 2011-10-09 04:40:07 -0500 (Sun, 09 Oct 2011)
Log Message
Move default implementation of JavaField to separate package
Modified Paths
Added Paths
- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaField.java
- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaFieldTest.java
Removed Paths
Diff
Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/ModelBuilder.java (1379 => 1380)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/ModelBuilder.java 2011-10-09 09:38:03 UTC (rev 1379) +++ trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/ModelBuilder.java 2011-10-09 09:40:07 UTC (rev 1380) @@ -30,7 +30,6 @@ import com.thoughtworks.qdox.model.Annotation; import com.thoughtworks.qdox.model.DefaultJavaClass; import com.thoughtworks.qdox.model.DefaultJavaConstructor; -import com.thoughtworks.qdox.model.DefaultJavaField; import com.thoughtworks.qdox.model.DefaultJavaMethod; import com.thoughtworks.qdox.model.DefaultJavaParameter; import com.thoughtworks.qdox.model.DefaultJavaSource; @@ -46,6 +45,7 @@ import com.thoughtworks.qdox.model.JavaType; import com.thoughtworks.qdox.model.Type; import com.thoughtworks.qdox.model.TypeVariable; +import com.thoughtworks.qdox.model.impl.DefaultJavaField; import com.thoughtworks.qdox.model.impl.DefaultJavaPackage; import com.thoughtworks.qdox.parser.structs.AnnoDef; import com.thoughtworks.qdox.parser.structs.ClassDef;
Deleted: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaField.java (1379 => 1380)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaField.java 2011-10-09 09:38:03 UTC (rev 1379) +++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaField.java 2011-10-09 09:40:07 UTC (rev 1380) @@ -1,188 +0,0 @@ -package com.thoughtworks.qdox.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -public class DefaultJavaField<T extends JavaClass & JavaParameterizedType> extends AbstractJavaEntity implements JavaField { - - private T type; - private String initializationExpression; - private boolean enumConstant; - - public DefaultJavaField() { - } - - public DefaultJavaField(String name) { - setName(name); - } - - public DefaultJavaField(T type, String name) { - this( name ); - this.type = type; - } - - /* - * (non-Javadoc) - * @see com.thoughtworks.qdox.model.JavaMember#getDeclaringClass() - */ - public JavaClass getDeclaringClass() { - return getParentClass(); - } - - /** - * Retrieve the Type of this field - * - * @return the Type of this field - */ - public JavaClass getType() { - return type; - } - - /* (non-Javadoc) - * @see com.thoughtworks.qdox.model.JavaField#getCodeBlock() - */ - public String getCodeBlock() - { - return getModelWriter().writeField( this ).toString(); - } - - public void setType(T type) { - this.type = type; - } - - /* (non-Javadoc) - * @see com.thoughtworks.qdox.model.JavaField#getDeclarationSignature(boolean) - */ - public String getDeclarationSignature(boolean withModifiers) { - StringBuffer result = new StringBuffer(); - if (withModifiers) { - for (String modifier : getModifiers()) { - result.append(modifier); - result.append(' '); - } - } - result.append(type.getCanonicalName()); - result.append(' '); - result.append(getName()); - return result.toString(); - } - - /* (non-Javadoc) - * @see com.thoughtworks.qdox.model.JavaField#getCallSignature() - */ - public String getCallSignature() { - return getName(); - } - - - /* - * (non-Javadoc) - * @see com.thoughtworks.qdox.model.JavaField#getInitializationExpression() - */ - public String getInitializationExpression(){ - return initializationExpression; - } - - public void setInitializationExpression(String initializationExpression){ - this.initializationExpression = initializationExpression; - } - - /* - * (non-Javadoc) - * @see com.thoughtworks.qdox.model.JavaField#isEnumConstant() - */ - public boolean isEnumConstant() { - return enumConstant; - } - - public void setEnumConstant(boolean enumConstant) { - this.enumConstant = enumConstant; - } - - /** - * @see java.lang.reflect.Field#toString() - */ - public String toString() { - StringBuffer result = new StringBuffer(); - if(isPrivate()) { - result.append("private "); - } - else if(isProtected()) { - result.append("protected "); - } - else if(isPublic()) { - result.append("public "); - } - if(isStatic()) { - result.append("static "); - } - if(isFinal()) { - result.append("final "); - } - if(isTransient()) { - result.append("transient "); - } - if(isVolatile()) { - result.append("volatile "); - } - result.append( type.getValue() ).append(' '); - result.append( getDeclaringClass().getFullyQualifiedName() ).append( '.' ).append( getName() ); - return result.toString(); - } - - /** - * Compares this Field against the specified object. - * Returns <code>true</code> if the objects are the same. - * Two Field objects are the same if they were declared by the same class and have the same name and type. - */ - @Override - public boolean equals( Object obj ) - { - if(this == obj) - { - return true; - } - if ( !(obj instanceof JavaField) ) - { - return false; - } - JavaField fld = (JavaField) obj; - if ( fld.getDeclaringClass().equals( this.getDeclaringClass() ) ) - { - return false; - } - //Don't see any reason to compare the Type. Otherwise it's already invalid - return fld.getName().equals( this.getName() ); - } - - @Override - public int hashCode() - { - int hashCode = 5; - if ( getDeclaringClass() != null ) - { - hashCode *=31 + getDeclaringClass().hashCode(); - } - if( getName() != null ) - { - hashCode *= 37 + getName().hashCode(); - } - return hashCode; - } -}
Copied: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaField.java (from rev 1366, trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaField.java) (0 => 1380)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaField.java (rev 0) +++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/impl/DefaultJavaField.java 2011-10-09 09:40:07 UTC (rev 1380) @@ -0,0 +1,193 @@ +package com.thoughtworks.qdox.model.impl; + +import com.thoughtworks.qdox.model.AbstractJavaEntity; +import com.thoughtworks.qdox.model.JavaClass; +import com.thoughtworks.qdox.model.JavaField; +import com.thoughtworks.qdox.model.JavaParameterizedType; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class DefaultJavaField<T extends JavaClass & JavaParameterizedType> extends AbstractJavaEntity implements JavaField { + + private T type; + private String initializationExpression; + private boolean enumConstant; + + public DefaultJavaField() { + } + + public DefaultJavaField(String name) { + setName(name); + } + + public DefaultJavaField(T type, String name) { + this( name ); + this.type = type; + } + + /* + * (non-Javadoc) + * @see com.thoughtworks.qdox.model.JavaMember#getDeclaringClass() + */ + public JavaClass getDeclaringClass() { + return getParentClass(); + } + + /** + * Retrieve the Type of this field + * + * @return the Type of this field + */ + public JavaClass getType() { + return type; + } + + /* (non-Javadoc) + * @see com.thoughtworks.qdox.model.JavaField#getCodeBlock() + */ + public String getCodeBlock() + { + return getModelWriter().writeField( this ).toString(); + } + + public void setType(T type) { + this.type = type; + } + + /* (non-Javadoc) + * @see com.thoughtworks.qdox.model.JavaField#getDeclarationSignature(boolean) + */ + public String getDeclarationSignature(boolean withModifiers) { + StringBuffer result = new StringBuffer(); + if (withModifiers) { + for (String modifier : getModifiers()) { + result.append(modifier); + result.append(' '); + } + } + result.append(type.getCanonicalName()); + result.append(' '); + result.append(getName()); + return result.toString(); + } + + /* (non-Javadoc) + * @see com.thoughtworks.qdox.model.JavaField#getCallSignature() + */ + public String getCallSignature() { + return getName(); + } + + + /* + * (non-Javadoc) + * @see com.thoughtworks.qdox.model.JavaField#getInitializationExpression() + */ + public String getInitializationExpression(){ + return initializationExpression; + } + + public void setInitializationExpression(String initializationExpression){ + this.initializationExpression = initializationExpression; + } + + /* + * (non-Javadoc) + * @see com.thoughtworks.qdox.model.JavaField#isEnumConstant() + */ + public boolean isEnumConstant() { + return enumConstant; + } + + public void setEnumConstant(boolean enumConstant) { + this.enumConstant = enumConstant; + } + + /** + * @see java.lang.reflect.Field#toString() + */ + public String toString() { + StringBuffer result = new StringBuffer(); + if(isPrivate()) { + result.append("private "); + } + else if(isProtected()) { + result.append("protected "); + } + else if(isPublic()) { + result.append("public "); + } + if(isStatic()) { + result.append("static "); + } + if(isFinal()) { + result.append("final "); + } + if(isTransient()) { + result.append("transient "); + } + if(isVolatile()) { + result.append("volatile "); + } + result.append( type.getValue() ).append(' '); + result.append( getDeclaringClass().getFullyQualifiedName() ).append( '.' ).append( getName() ); + return result.toString(); + } + + /** + * Compares this Field against the specified object. + * Returns <code>true</code> if the objects are the same. + * Two Field objects are the same if they were declared by the same class and have the same name and type. + */ + @Override + public boolean equals( Object obj ) + { + if(this == obj) + { + return true; + } + if ( !(obj instanceof JavaField) ) + { + return false; + } + JavaField fld = (JavaField) obj; + if ( fld.getDeclaringClass().equals( this.getDeclaringClass() ) ) + { + return false; + } + //Don't see any reason to compare the Type. Otherwise it's already invalid + return fld.getName().equals( this.getName() ); + } + + @Override + public int hashCode() + { + int hashCode = 5; + if ( getDeclaringClass() != null ) + { + hashCode *=31 + getDeclaringClass().hashCode(); + } + if( getName() != null ) + { + hashCode *= 37 + getName().hashCode(); + } + return hashCode; + } +}
Deleted: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultJavaFieldTest.java (1379 => 1380)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultJavaFieldTest.java 2011-10-09 09:38:03 UTC (rev 1379) +++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultJavaFieldTest.java 2011-10-09 09:40:07 UTC (rev 1380) @@ -1,66 +0,0 @@ -package com.thoughtworks.qdox.model; - -import java.util.List; - -public class DefaultJavaFieldTest - extends JavaFieldTest<DefaultJavaField> -{ - - public DefaultJavaFieldTest( String s ) - { - super( s ); - } - - @Override - public DefaultJavaField newJavaField() - { - JavaSource source = new DefaultJavaSource( null ); - JavaClass javaClass = new DefaultJavaClass( source ); - DefaultJavaField result = new DefaultJavaField(); - result.setParentClass( javaClass ); - return result; - } - - @Override - public DefaultJavaField newJavaField( Type type, String name ) - { - return new DefaultJavaField(type, name); - } - - @Override - public void setComment( DefaultJavaField fld, String comment ) - { - fld.setComment( comment ); - } - - @Override - public void setInitializationExpression( DefaultJavaField fld, String _expression_ ) - { - fld.setInitializationExpression( _expression_ ); - } - - @Override - public void setModifiers( DefaultJavaField fld, List<String> modifiers ) - { - fld.setModifiers( modifiers ); - } - - @Override - public void setName( DefaultJavaField fld, String name ) - { - fld.setName( name ); - } - - @Override - public void setType( DefaultJavaField fld, Type type ) - { - fld.setType( type ); - } - - @Override - public void setDeclaringClass( DefaultJavaField fld, JavaClass cls ) - { - fld.setParentClass( cls ); - } - -}
Copied: trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaFieldTest.java (from rev 1303, trunk/qdox/src/test/java/com/thoughtworks/qdox/model/DefaultJavaFieldTest.java) (0 => 1380)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaFieldTest.java (rev 0) +++ trunk/qdox/src/test/java/com/thoughtworks/qdox/model/impl/DefaultJavaFieldTest.java 2011-10-09 09:40:07 UTC (rev 1380) @@ -0,0 +1,73 @@ +package com.thoughtworks.qdox.model.impl; + +import java.util.List; + +import com.thoughtworks.qdox.model.DefaultJavaClass; +import com.thoughtworks.qdox.model.DefaultJavaSource; +import com.thoughtworks.qdox.model.JavaClass; +import com.thoughtworks.qdox.model.JavaFieldTest; +import com.thoughtworks.qdox.model.JavaSource; +import com.thoughtworks.qdox.model.Type; + +public class DefaultJavaFieldTest + extends JavaFieldTest<DefaultJavaField> +{ + + public DefaultJavaFieldTest( String s ) + { + super( s ); + } + + @Override + public DefaultJavaField newJavaField() + { + JavaSource source = new DefaultJavaSource( null ); + JavaClass javaClass = new DefaultJavaClass( source ); + DefaultJavaField result = new DefaultJavaField(); + result.setParentClass( javaClass ); + return result; + } + + @Override + public DefaultJavaField newJavaField( Type type, String name ) + { + return new DefaultJavaField(type, name); + } + + @Override + public void setComment( DefaultJavaField fld, String comment ) + { + fld.setComment( comment ); + } + + @Override + public void setInitializationExpression( DefaultJavaField fld, String _expression_ ) + { + fld.setInitializationExpression( _expression_ ); + } + + @Override + public void setModifiers( DefaultJavaField fld, List<String> modifiers ) + { + fld.setModifiers( modifiers ); + } + + @Override + public void setName( DefaultJavaField fld, String name ) + { + fld.setName( name ); + } + + @Override + public void setType( DefaultJavaField fld, Type type ) + { + fld.setType( type ); + } + + @Override + public void setDeclaringClass( DefaultJavaField fld, JavaClass cls ) + { + fld.setParentClass( cls ); + } + +}
To unsubscribe from this list please visit:
