Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.jboss.forge.roaster.model.source.VisibilityScopedSource;
import org.jboss.forge.roaster.model.util.Assert;

import java.util.Arrays;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
Expand All @@ -18,12 +20,12 @@ public enum Visibility
{
PUBLIC("public"), PROTECTED("protected"), PRIVATE("private"), PACKAGE_PRIVATE("");

private Visibility(String scope)
Visibility(String scope)
{
this.scope = scope;
}

private String scope;
private final String scope;

/**
* private, public, protected, package private("")
Expand All @@ -49,7 +51,7 @@ public static Visibility getFrom(VisibilityScoped target)
else
{
throw new IllegalStateException(VisibilityScoped.class.getSimpleName()
+ " target does not comply with visibility scoping. Must be one of " + Visibility.values() + "[ "
+ " target does not comply with visibility scoping. Must be one of " + Arrays.toString(Visibility.values()) + "[ "
+ target + "]");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.jboss.forge.roaster.model.JavaType;
import org.jboss.forge.roaster.model.Property;
import org.jboss.forge.roaster.model.util.Refactory;

/**
* Source variant of {@link Property} interface.
Expand All @@ -23,19 +24,28 @@ public interface PropertySource<O extends JavaSource<O>> extends Property<O>,
/**
* Set the type of this {@link Property} to the given {@link Class} type. Attempt to add an import statement to this
* Property's base {@link O} if required.
*
* It is the caller's responsibility to create new {@code equals(Object)} and {@code hashCode()} methods,
* e.g. by using {@link Refactory#createHashCodeAndEquals(JavaClassSource, FieldSource[])}
*/
PropertySource<O> setType(Class<?> clazz);

/**
* Set the type of this {@link Property} to the given type. Attempt to add an import statement to this Property's
* base {@link O} if required. (Note that the given className must be fully-qualified in order to properly import
* required classes)
*
* It is the caller's responsibility to create new {@code equals(Object)} and {@code hashCode()} methods,
* e.g. by using {@link Refactory#createHashCodeAndEquals(JavaClassSource, FieldSource[])}
*/
PropertySource<O> setType(String type);

/**
* Set the type of this {@link Property} to the given {@link JavaType<?>} type. Attempt to add an import statement to
* this field's base {@link O} if required.
*
* It is the caller's responsibility to create new {@code equals(Object)} and {@code hashCode()} methods,
* e.g. by using {@link Refactory#createHashCodeAndEquals(JavaClassSource, FieldSource[])}
*/
PropertySource<O> setType(JavaType<?> entity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ else if (field.getType().isType("double"))
clazz.addMethod(
"public boolean equals(Object obj) { " +
"if (this == obj) { return true; } " +
superEqualsCheck.toString() +
superEqualsCheck +
typeCheckAndAssignment.toString() +
fieldEqualityChecks.toString() +
"return true; " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static boolean isBlank(final String string)

public static boolean isTrue(final String value)
{
return value == null ? false : "true".equalsIgnoreCase(value.trim());
return value != null && "true".equalsIgnoreCase(value.trim());
}

public static boolean areEqual(final String left, final String right)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ public static boolean areEquivalent(String left, String right)

if (l.equals(r))
{
if (!lp.isEmpty() && !rp.isEmpty())
{
return false;
}
return true;
return !(!lp.isEmpty() && !rp.isEmpty());
}

return false;
Expand Down Expand Up @@ -267,7 +263,7 @@ public static boolean isQualified(final String className)

public static String getPackage(final String className)
{
if (className.indexOf(".") > -1)
if (className.contains("."))
{
return className.substring(0, className.lastIndexOf("."));
}
Expand Down
1 change: 0 additions & 1 deletion dist/src/main/java/org/jboss/forge/roaster/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ else if (new File(arg).exists())
}

private void format(List<File> files, String configFile, final boolean recursive, final boolean quiet)
throws IOException
{
for (File file : files)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class TypeDeclarationFinderVisitor extends ASTVisitor
{
private List<AbstractTypeDeclaration> declarations = new ArrayList<AbstractTypeDeclaration>();
private final List<AbstractTypeDeclaration> declarations = new ArrayList<AbstractTypeDeclaration>();

private PackageDeclaration packageDeclaration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,10 @@ public boolean requiresImport(final String type)
{
resultType = Types.stripGenerics(resultType);
}
if (!validImport(resultType)
return !(!validImport(resultType)
|| hasImport(resultType)
|| Types.isJavaLang(resultType)
|| Strings.areEqual(getPackage(), Types.getPackage(resultType)))
{
return false;
}
return true;
|| Strings.areEqual(getPackage(), Types.getPackage(resultType)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ private Class<?> resolveTypeLiteral(TypeLiteral typeLiteral)

private final AnnotationAccessor<JavaAnnotationSource, AnnotationElementSource> annotations = new AnnotationAccessor<JavaAnnotationSource, AnnotationElementSource>();

private JavaAnnotationSource parent;
private AST ast;
private final JavaAnnotationSource parent;
private final AST ast;
private final AnnotationTypeMemberDeclaration member;

public AnnotationElementImpl(final JavaAnnotationSource parent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class EnumConstantImpl implements EnumConstantSource
private final AnnotationAccessor<JavaEnumSource, EnumConstantSource> annotations = new AnnotationAccessor<JavaEnumSource, EnumConstantSource>();
private JavaEnumSource parent;
private AST ast;
private EnumConstantDeclaration enumConstant;
private final EnumConstantDeclaration enumConstant;

private void init(final JavaEnumSource parent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class FieldImpl<O extends JavaSource<O>> implements FieldSource<O>
private final AnnotationAccessor<O, FieldSource<O>> annotations = new AnnotationAccessor<O, FieldSource<O>>();
private final ModifierAccessor modifiers = new ModifierAccessor();

private O parent;
private AST ast;
private final O parent;
private final AST ast;
private final FieldDeclaration field;
private final VariableDeclarationFragment fragment;
private final CompilationUnit cu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
public class ImportImpl implements Import
{
private AST ast = null;
private CompilationUnit cu = null;
private ImportDeclaration imprt = null;

private void init(final JavaSource<?> parent)
{
cu = (CompilationUnit) parent.getInternal();
CompilationUnit cu = (CompilationUnit) parent.getInternal();
ast = cu.getAST();
}

Expand Down Expand Up @@ -111,11 +110,7 @@ public boolean equals(final Object obj)
return false;

Import other = (Import) obj;
if (!getQualifiedName().equals(other.getQualifiedName()))
{
return false;
}
return true;
return getQualifiedName().equals(other.getQualifiedName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,9 @@ public boolean requiresImport(final String type)
{
resultType = Types.stripGenerics(resultType);
}
if (!validImport(resultType)
return !(!validImport(resultType)
|| hasImport(resultType)
|| Types.isJavaLang(resultType))
{
return false;
}
return true;
|| Types.isJavaLang(resultType));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public String toSignature()
}
}

signature.append(") : " + (this.getReturnType() == null ? "void" : this.getReturnType().getName()));
signature.append(") : ").append((this.getReturnType() == null ? "void" : this.getReturnType().getName()));
return signature.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ private static String ensureCorrectNewLines(String content)
{
String newLine = System.getProperty("line.separator");

if (content.indexOf("\n") != -1
&& content.indexOf(newLine) == -1)
if (content.contains("\n")
&& !content.contains(newLine))
return content.replaceAll("\n", newLine);

return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
*/
public class FieldTest
{
private InputStream stream;
private JavaClassSource javaClass;
private FieldSource<JavaClassSource> field;

@Before
public void reset()
{
stream = FieldTest.class.getResourceAsStream("/org/jboss/forge/grammar/java/MockAnnotatedField.java");
InputStream stream = FieldTest.class.getResourceAsStream("/org/jboss/forge/grammar/java/MockAnnotatedField.java");
javaClass = Roaster.parse(JavaClassSource.class, stream);
field = javaClass.getFields().get(javaClass.getFields().size() - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@
*/
public class JavaClassMethodTest
{
private InputStream stream;
private JavaClassSource javaClass;
private MethodSource<JavaClassSource> method;

@Before
public void reset()
{
stream = JavaClassMethodTest.class.getResourceAsStream("/org/jboss/forge/grammar/java/MockClass.java");
InputStream stream = JavaClassMethodTest.class.getResourceAsStream("/org/jboss/forge/grammar/java/MockClass.java");
javaClass = Roaster.parse(JavaClassSource.class, stream);
javaClass.addMethod("public URL rewriteURL(String pattern, String replacement) { return null; }");
method = javaClass.getMethods().get(javaClass.getMethods().size() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
*/
public class JavaEnumFieldTest
{
private InputStream stream;
private JavaEnumSource javaEnum;
private FieldSource<JavaEnumSource> field;

@Before
public void reset()
{
stream = JavaEnumFieldTest.class.getResourceAsStream("/org/jboss/forge/grammar/java/MockEnum.java");
InputStream stream = JavaEnumFieldTest.class.getResourceAsStream("/org/jboss/forge/grammar/java/MockEnum.java");
javaEnum = Roaster.parse(JavaEnumSource.class, stream);
field = javaEnum.getFields().get(javaEnum.getFields().size() - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@
*/
public class JavaEnumMethodTest
{
private InputStream stream;
private JavaEnumSource javaEnum;
private MethodSource<JavaEnumSource> method;

@Before
public void reset()
{
stream = JavaEnumMethodTest.class.getResourceAsStream("/org/jboss/forge/grammar/java/MockEnum.java");
InputStream stream = JavaEnumMethodTest.class.getResourceAsStream("/org/jboss/forge/grammar/java/MockEnum.java");
javaEnum = Roaster.parse(JavaEnumSource.class, stream);
javaEnum.addMethod("public URL rewriteURL(String pattern, String replacement) { return null; }");
method = javaEnum.getMethods().get(javaEnum.getMethods().size() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class NonAsciiCharactersTest
{

String nonAsciiCharactersClass = "public class NonAsciiCharacters {" +
final String nonAsciiCharactersClass = "public class NonAsciiCharacters {" +

" public int punctuations_example_áéíóú = 0; " +

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ private void assertHashCodeForInnerClass(MethodSource<JavaClassSource> hashcode)
{
assertEquals("hashCode", hashcode.getName());
assertEquals(0, hashcode.getParameters().size());
assertEquals("int", hashcode.getReturnType());
assertEquals("int", hashcode.getReturnType().getName());
assertThat(hashcode.getBody(), containsString("result=prime * result + getOuterType().hashCode();"));
assertThat(hashcode.getBody(), containsString("result=prime * result + ((flag == null) ? 0 : flag.hashCode());"));

Expand Down