Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FORGE-836: Added relocation tag in parser-java and parser-java-api

  • Loading branch information...
commit eb222f92795e41138511861e00d4054d52c9446c 1 parent c458986
George Gastaldi authored
Showing with 42 additions and 13,948 deletions.
  1. +3 −3 dist/build.xml
  2. +19 −17 parser-java-api/pom.xml
  3. +0 −24 parser-java-api/src/main/java/org/jboss/forge/parser/Internal.java
  4. +0 −122 parser-java-api/src/main/java/org/jboss/forge/parser/JavaParser.java
  5. +0 −23 parser-java-api/src/main/java/org/jboss/forge/parser/Origin.java
  6. +0 −36 parser-java-api/src/main/java/org/jboss/forge/parser/ParserException.java
  7. +0 −19 parser-java-api/src/main/java/org/jboss/forge/parser/java/Abstractable.java
  8. +0 −93 parser-java-api/src/main/java/org/jboss/forge/parser/java/Annotation.java
  9. +0 −99 parser-java-api/src/main/java/org/jboss/forge/parser/java/AnnotationElement.java
  10. +0 −50 parser-java-api/src/main/java/org/jboss/forge/parser/java/AnnotationTarget.java
  11. +0 −23 parser-java-api/src/main/java/org/jboss/forge/parser/java/EnumConstant.java
  12. +0 −50 parser-java-api/src/main/java/org/jboss/forge/parser/java/Extendable.java
  13. +0 −71 parser-java-api/src/main/java/org/jboss/forge/parser/java/Field.java
  14. +0 −57 parser-java-api/src/main/java/org/jboss/forge/parser/java/FieldHolder.java
  15. +0 −33 parser-java-api/src/main/java/org/jboss/forge/parser/java/GenericCapable.java
  16. +0 −32 parser-java-api/src/main/java/org/jboss/forge/parser/java/Import.java
  17. +0 −119 parser-java-api/src/main/java/org/jboss/forge/parser/java/Importer.java
  18. +0 −36 parser-java-api/src/main/java/org/jboss/forge/parser/java/InterfaceCapable.java
  19. +0 −66 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaAnnotation.java
  20. +0 −23 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaClass.java
  21. +0 −44 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaEnum.java
  22. +0 −17 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaInterface.java
  23. +0 −91 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaSource.java
  24. +0 −22 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaType.java
  25. +0 −29 parser-java-api/src/main/java/org/jboss/forge/parser/java/Member.java
  26. +0 −22 parser-java-api/src/main/java/org/jboss/forge/parser/java/MemberHolder.java
  27. +0 −128 parser-java-api/src/main/java/org/jboss/forge/parser/java/Method.java
  28. +0 −85 parser-java-api/src/main/java/org/jboss/forge/parser/java/MethodHolder.java
  29. +0 −33 parser-java-api/src/main/java/org/jboss/forge/parser/java/Named.java
  30. +0 −38 parser-java-api/src/main/java/org/jboss/forge/parser/java/Packaged.java
  31. +0 −20 parser-java-api/src/main/java/org/jboss/forge/parser/java/Parameter.java
  32. +0 −16 parser-java-api/src/main/java/org/jboss/forge/parser/java/SourceType.java
  33. +0 −21 parser-java-api/src/main/java/org/jboss/forge/parser/java/SyntaxError.java
  34. +0 −40 parser-java-api/src/main/java/org/jboss/forge/parser/java/Type.java
  35. +0 −21 parser-java-api/src/main/java/org/jboss/forge/parser/java/ValuePair.java
  36. +0 −86 parser-java-api/src/main/java/org/jboss/forge/parser/java/Visibility.java
  37. +0 −35 parser-java-api/src/main/java/org/jboss/forge/parser/java/VisibilityScoped.java
  38. +0 −38 parser-java-api/src/main/java/org/jboss/forge/parser/java/util/Assert.java
  39. +0 −118 parser-java-api/src/main/java/org/jboss/forge/parser/java/util/Refactory.java
  40. +0 −414 parser-java-api/src/main/java/org/jboss/forge/parser/java/util/Strings.java
  41. +0 −364 parser-java-api/src/main/java/org/jboss/forge/parser/java/util/Types.java
  42. +0 −70 parser-java-api/src/main/java/org/jboss/forge/parser/spi/JavaParserProvider.java
  43. +0 −21 parser-java-api/src/main/java/org/jboss/forge/parser/spi/WildcardImportResolver.java
  44. +0 −274 parser-java-api/src/main/resources/org/jboss/forge/parser/java/util/org.eclipse.jdt.core.prefs
  45. +19 −83 parser-java/pom.xml
  46. +0 −215 parser-java/src/main/java/org/jboss/forge/parser/java/ast/AnnotationAccessor.java
  47. +0 −75 parser-java/src/main/java/org/jboss/forge/parser/java/ast/MethodFinderVisitor.java
  48. +0 −87 parser-java/src/main/java/org/jboss/forge/parser/java/ast/ModifierAccessor.java
  49. +0 −51 parser-java/src/main/java/org/jboss/forge/parser/java/ast/TypeDeclarationFinderVisitor.java
  50. +0 −85 parser-java/src/main/java/org/jboss/forge/parser/java/impl/AbstractGenericCapableJavaSource.java
  51. +0 −902 parser-java/src/main/java/org/jboss/forge/parser/java/impl/AbstractJavaSource.java
  52. +0 −307 parser-java/src/main/java/org/jboss/forge/parser/java/impl/AbstractJavaSourceMemberHolder.java
  53. +0 −590 parser-java/src/main/java/org/jboss/forge/parser/java/impl/AnnotationElementImpl.java
  54. +0 −807 parser-java/src/main/java/org/jboss/forge/parser/java/impl/AnnotationImpl.java
  55. +0 −78 parser-java/src/main/java/org/jboss/forge/parser/java/impl/EnumConstantImpl.java
  56. +0 −542 parser-java/src/main/java/org/jboss/forge/parser/java/impl/FieldImpl.java
  57. +0 −132 parser-java/src/main/java/org/jboss/forge/parser/java/impl/ImportImpl.java
  58. +0 −76 parser-java/src/main/java/org/jboss/forge/parser/java/impl/JDTHelper.java
  59. +0 −145 parser-java/src/main/java/org/jboss/forge/parser/java/impl/JavaAnnotationImpl.java
  60. +0 −168 parser-java/src/main/java/org/jboss/forge/parser/java/impl/JavaClassImpl.java
  61. +0 −97 parser-java/src/main/java/org/jboss/forge/parser/java/impl/JavaEnumImpl.java
  62. +0 −39 parser-java/src/main/java/org/jboss/forge/parser/java/impl/JavaInterfaceImpl.java
  63. +0 −605 parser-java/src/main/java/org/jboss/forge/parser/java/impl/MethodImpl.java
  64. +0 −135 parser-java/src/main/java/org/jboss/forge/parser/java/impl/ParameterImpl.java
  65. +0 −56 parser-java/src/main/java/org/jboss/forge/parser/java/impl/SyntaxErrorImpl.java
  66. +0 −197 parser-java/src/main/java/org/jboss/forge/parser/java/impl/TypeImpl.java
  67. +0 −99 parser-java/src/main/java/org/jboss/forge/parser/java/impl/ValuePairImpl.java
  68. +0 −105 parser-java/src/main/java/org/jboss/forge/parser/java/util/Formatter.java
  69. +0 −233 parser-java/src/main/java/org/jboss/forge/parser/spi/JavaParserImpl.java
  70. +0 −1  parser-java/src/main/resources/META-INF/services/org.jboss.forge.parser.spi.JavaParserProvider
  71. +0 −274 parser-java/src/main/resources/org/jboss/forge/parser/java/util/org.eclipse.jdt.core.prefs
  72. +0 −44 parser-java/src/test/java/org/jboss/forge/test/parser/java/FieldAnnotationTest.java
  73. +0 −256 parser-java/src/test/java/org/jboss/forge/test/parser/java/FieldTest.java
  74. +0 −245 parser-java/src/test/java/org/jboss/forge/test/parser/java/FieldTypeTest.java
  75. +0 −30 parser-java/src/test/java/org/jboss/forge/test/parser/java/FieldVisibilityTest.java
  76. +0 −108 parser-java/src/test/java/org/jboss/forge/test/parser/java/ImportEqualityTest.java
  77. +0 −247 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaAnnotationTest.java
  78. +0 −29 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaClassAnnotationTest.java
  79. +0 −37 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaClassCreationTest.java
  80. +0 −119 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaClassGenericsTest.java
  81. +0 −23 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaClassInterfaceTest.java
  82. +0 −127 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaClassMethodTest.java
  83. +0 −26 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaClassTest.java
  84. +0 −28 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaClassVisibilityTest.java
  85. +0 −256 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaEnumFieldTest.java
  86. +0 −23 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaEnumInterfaceTest.java
  87. +0 −128 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaEnumMethodTest.java
  88. +0 −33 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaEnumTest.java
  89. +0 −23 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaInterfaceInterfaceTest.java
  90. +0 −82 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaInterfaceTest.java
  91. +0 −25 parser-java/src/test/java/org/jboss/forge/test/parser/java/JavaParserTest.java
  92. +0 −29 parser-java/src/test/java/org/jboss/forge/test/parser/java/MethodAnnotationTest.java
  93. +0 −205 parser-java/src/test/java/org/jboss/forge/test/parser/java/MethodReturnTypeTest.java
  94. +0 −105 parser-java/src/test/java/org/jboss/forge/test/parser/java/MethodSignatureTest.java
  95. +0 −86 parser-java/src/test/java/org/jboss/forge/test/parser/java/MethodThrowsExceptionsTest.java
  96. +0 −30 parser-java/src/test/java/org/jboss/forge/test/parser/java/MethodVisibilityTest.java
  97. +0 −155 parser-java/src/test/java/org/jboss/forge/test/parser/java/NestedClassTest.java
  98. +0 −16 parser-java/src/test/java/org/jboss/forge/test/parser/java/NestedJavaClassTest.java
  99. +0 −40 parser-java/src/test/java/org/jboss/forge/test/parser/java/ParameterAnnotationTest.java
  100. +0 −133 parser-java/src/test/java/org/jboss/forge/test/parser/java/ResolveTypeTest.java
  101. +0 −524 parser-java/src/test/java/org/jboss/forge/test/parser/java/common/AnnotationTest.java
  102. +0 −104 parser-java/src/test/java/org/jboss/forge/test/parser/java/common/InterfacedTestBase.java
  103. +0 −320 parser-java/src/test/java/org/jboss/forge/test/parser/java/common/JavaClassTestBase.java
  104. +0 −17 parser-java/src/test/java/org/jboss/forge/test/parser/java/common/MockAnnotation.java
  105. +0 −17 parser-java/src/test/java/org/jboss/forge/test/parser/java/common/MockEnumType.java
  106. +0 −19 parser-java/src/test/java/org/jboss/forge/test/parser/java/common/MockNestingAnnotation.java
  107. +0 −75 parser-java/src/test/java/org/jboss/forge/test/parser/java/common/VisibilityTest.java
  108. +0 −42 parser-java/src/test/java/org/jboss/forge/test/parser/java/common/WildCardImportsTest.java
  109. +0 −44 parser-java/src/test/java/org/jboss/forge/test/parser/java/util/FormatterTest.java
  110. +0 −63 parser-java/src/test/java/org/jboss/forge/test/parser/java/util/OSUtils.java
  111. +0 −109 parser-java/src/test/java/org/jboss/forge/test/parser/java/util/RefactoryTest.java
  112. +0 −145 parser-java/src/test/java/org/jboss/forge/test/parser/java/util/TypesTest.java
  113. +0 −383 parser-java/src/test/resources/org/jboss/forge/grammar/java/BigInterface.java
  114. +0 −21 parser-java/src/test/resources/org/jboss/forge/grammar/java/MockAnnotatedClass.java
  115. +0 −17 parser-java/src/test/resources/org/jboss/forge/grammar/java/MockAnnotatedField.java
  116. +0 −19 parser-java/src/test/resources/org/jboss/forge/grammar/java/MockAnnotatedMethod.java
  117. +0 −20 parser-java/src/test/resources/org/jboss/forge/grammar/java/MockAnnotatedParameter.java
  118. +0 −14 parser-java/src/test/resources/org/jboss/forge/grammar/java/MockClass.java
  119. +0 −20 parser-java/src/test/resources/org/jboss/forge/grammar/java/MockEnum.java
  120. +0 −14 parser-java/src/test/resources/org/jboss/forge/grammar/java/MockInterface.java
  121. +0 −22 parser-java/src/test/resources/org/jboss/forge/grammar/java/MockJavaAnnotationType.java
  122. +0 −5 parser-java/src/test/resources/org/jboss/forge/grammar/java/MockUnformattedClass.java
  123. +0 −17 parser-java/src/test/resources/org/jboss/forge/grammar/java/NestedMockClass.java
  124. +1 −2  pom.xml
6 dist/build.xml
View
@@ -245,7 +245,7 @@
<module-def name="org.freemarker">
<maven-resource group="org.freemarker" artifact="freemarker" />
</module-def>
-
+
<module-def name="org.javassist">
<maven-resource group="javassist" artifact="javassist" />
</module-def>
@@ -323,11 +323,11 @@
</module-def>
<module-def name="org.jboss.forge.parser.java.api">
- <maven-resource group="org.jboss.forge" artifact="forge-parser-java-api" />
+ <maven-resource group="org.jboss.forge" artifact="java-parser-api" />
</module-def>
<module-def name="org.jboss.forge.parser.java.impl">
- <maven-resource group="org.jboss.forge" artifact="forge-parser-java" />
+ <maven-resource group="org.jboss.forge" artifact="java-parser-impl" />
</module-def>
<module-def name="org.jboss.forge.parser.xml">
36 parser-java-api/pom.xml
View
@@ -1,21 +1,23 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.jboss.forge</groupId>
- <artifactId>forge-parent</artifactId>
- <version>1.2.3-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
+ <parent>
+ <groupId>org.jboss.forge</groupId>
+ <artifactId>forge-parent</artifactId>
+ <version>1.2.3-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
- <artifactId>forge-parser-java-api</artifactId>
- <packaging>jar</packaging>
- <name>Forge - Parser/Java API</name>
+ <artifactId>forge-parser-java-api</artifactId>
+ <packaging>jar</packaging>
+ <name>Forge - Parser/Java API</name>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- </dependencies>
+ <distributionManagement>
+ <relocation>
+ <groupId>org.jboss.forge</groupId>
+ <artifactId>java-parser-api</artifactId>
+ <version>1.0.1.Final</version>
+ </relocation>
+ </distributionManagement>
</project>
24 parser-java-api/src/main/java/org/jboss/forge/parser/Internal.java
View
@@ -1,24 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser;
-
-/**
- * Represents an object that stores implementation-specific data. This data must be accessible to other objects sharing
- * the implementation, but should not be referenced by end-users.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Internal
-{
- /**
- * Returns the implementation-specific Object representing <code>this</code>. <b>Do not call this method</b> unless
- * you are willing to risk breaking backwards compatibility if future versions do not use the same internal object
- * implementations.
- */
- Object getInternal();
-}
122 parser-java-api/src/main/java/org/jboss/forge/parser/JavaParser.java
View
@@ -1,122 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ServiceLoader;
-
-import org.jboss.forge.parser.java.JavaClass;
-import org.jboss.forge.parser.java.JavaSource;
-import org.jboss.forge.parser.spi.JavaParserProvider;
-
-/**
- * Responsible for parsing data into new {@link JavaClass} instances.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- */
-public final class JavaParser
-{
- public static ServiceLoader<JavaParserProvider> loader = ServiceLoader.load(JavaParserProvider.class);
- private static List<JavaParserProvider> parsers;
-
- private static JavaParserProvider getParser()
- {
- if (parsers == null)
- {
- parsers = new ArrayList<JavaParserProvider>();
- for (JavaParserProvider p : loader)
- {
- parsers.add(p);
- }
- }
- if (parsers.size() == 0)
- {
- throw new IllegalStateException("No instances of [" + JavaParserProvider.class.getName()
- + "] were found on the classpath.");
- }
- return parsers.get(0);
- }
-
- /**
- * Open the given {@link File}, parsing its contents into a new {@link JavaClass} instance.
- */
- public static JavaSource<?> parse(final File file) throws FileNotFoundException
- {
- return getParser().parse(file);
- }
-
- /**
- * Read the given {@link InputStream} and parse the data into a new {@link JavaClass} instance.
- */
- public static JavaSource<?> parse(final InputStream data)
- {
- return getParser().parse(data);
- }
-
- /**
- * Parse the given character array into a new {@link JavaClass} instance.
- */
- public static JavaSource<?> parse(final char[] data)
- {
- return getParser().parse(data);
- }
-
- /**
- * Parse the given String data into a new {@link JavaClass} instance.
- */
- public static JavaSource<?> parse(final String data)
- {
- return getParser().parse(data);
- }
-
- /**
- * Create a new empty {@link JavaClass} instance.
- */
- public static <T extends JavaSource<?>> T create(final Class<T> type)
- {
- return getParser().create(type);
- }
-
- /**
- * Read the given {@link File} and parse its data into a new {@link JavaSource} instance of the given type.
- *
- * @throws FileNotFoundException
- */
- public static <T extends JavaSource<?>> T parse(final Class<T> type, final File file) throws FileNotFoundException
- {
- return getParser().parse(type, file);
- }
-
- /**
- * Read the given {@link InputStream} and parse its data into a new {@link JavaSource} instance of the given type.
- */
- public static <T extends JavaSource<?>> T parse(final Class<T> type, final InputStream data)
- {
- return getParser().parse(type, data);
- }
-
- /**
- * Read the given character array and parse its data into a new {@link JavaSource} instance of the given type.
- */
- public static <T extends JavaSource<?>> T parse(final Class<T> type, final char[] data)
- {
- return getParser().parse(type, data);
- }
-
- /**
- * Read the given string and parse its data into a new {@link JavaSource} instance of the given type.
- */
- public static <T extends JavaSource<?>> T parse(final Class<T> type, final String data)
- {
- return getParser().parse(type, data);
- }
-}
23 parser-java-api/src/main/java/org/jboss/forge/parser/Origin.java
View
@@ -1,23 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser;
-
-
-/**
- * Represents an object that has a root ancestor that should be made accessible
- * to its clients.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Origin<T>
-{
- /**
- * @return the instance of the root ancestor.
- */
- T getOrigin();
-}
36 parser-java-api/src/main/java/org/jboss/forge/parser/ParserException.java
View
@@ -1,36 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public class ParserException extends RuntimeException
-{
- private static final long serialVersionUID = 642493448571856848L;
-
- public ParserException()
- {
- }
-
- public ParserException(final String message)
- {
- super(message);
- }
-
- public ParserException(final Throwable e)
- {
- super(e);
- }
-
- public ParserException(final String message, final Throwable e)
- {
- super(message, e);
- }
-
-}
19 parser-java-api/src/main/java/org/jboss/forge/parser/java/Abstractable.java
View
@@ -1,19 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Abstractable<T>
-{
- public abstract boolean isAbstract();
-
- public abstract T setAbstract(boolean abstrct);
-}
93 parser-java-api/src/main/java/org/jboss/forge/parser/java/Annotation.java
View
@@ -1,93 +0,0 @@
-/*
- * Copyright 2012-2013 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-import org.jboss.forge.parser.Internal;
-import org.jboss.forge.parser.Origin;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- */
-public interface Annotation<O extends JavaSource<O>> extends Internal, Origin<O>
-{
- boolean isSingleValue();
-
- boolean isMarker();
-
- boolean isNormal();
-
- String getName();
-
- String getQualifiedName();
-
- <T extends Enum<T>> T getEnumValue(Class<T> type);
-
- <T extends Enum<T>> T getEnumValue(Class<T> type, String name);
-
- <T extends Enum<T>> T[] getEnumArrayValue(Class<T> type);
-
- <T extends Enum<T>> T[] getEnumArrayValue(Class<T> type, String name);
-
- String getLiteralValue();
-
- String getLiteralValue(String name);
-
- List<ValuePair> getValues();
-
- String getStringValue();
-
- String getStringValue(String name);
-
- Annotation<O> removeValue(String name);
-
- Annotation<O> removeAllValues();
-
- Annotation<O> setName(String className);
-
- Annotation<O> setEnumValue(String name, Enum<?> value);
-
- Annotation<O> setEnumValue(Enum<?>... value);
-
- Annotation<O> setEnumArrayValue(String name, Enum<?>... values);
-
- Annotation<O> setEnumArrayValue(Enum<?>... values);
-
- Annotation<O> setLiteralValue(String value);
-
- Annotation<O> setLiteralValue(String name, String value);
-
- Annotation<O> setStringValue(String value);
-
- Annotation<O> setStringValue(String name, String value);
-
- Annotation<O> getAnnotationValue();
-
- Annotation<O> getAnnotationValue(String name);
-
- Annotation<O> setAnnotationValue();
-
- Annotation<O> setAnnotationValue(String name);
-
- Class<?> getClassValue();
-
- Class<?> getClassValue(String name);
-
- Class<?>[] getClassArrayValue();
-
- Class<?>[] getClassArrayValue(String name);
-
- Annotation<O> setClassValue(String name, Class<?> value);
-
- Annotation<O> setClassValue(Class<?> value);
-
- Annotation<O> setClassArrayValue(String name, Class<?>... values);
-
- Annotation<O> setClassArrayValue(Class<?>... values);
-
-}
99 parser-java-api/src/main/java/org/jboss/forge/parser/java/AnnotationElement.java
View
@@ -1,99 +0,0 @@
-/*
- * Copyright 2013 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import org.jboss.forge.parser.Origin;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- * @author Matt Benson
- */
-public interface AnnotationElement extends AnnotationTarget<JavaAnnotation, AnnotationElement>, Origin<JavaAnnotation>
-{
- public interface DefaultValue
- {
- String getString();
-
- String getLiteral();
-
- <T extends Enum<T>> T getEnum(Class<T> type);
-
- <T extends Enum<T>> T[] getEnumArray(Class<T> type);
-
- Annotation<JavaAnnotation> getAnnotation();
-
- Class<?> getSingleClass();
-
- Class<?>[] getClassArray();
-
- DefaultValue setLiteral(String value);
-
- DefaultValue setString(String value);
-
- <T extends Enum<T>> DefaultValue setEnum(T value);
-
- <T extends Enum<T>> DefaultValue setEnumArray(T... values);
-
- Annotation<JavaAnnotation> setAnnotation();
-
- DefaultValue setSingleClass(Class<?> value);
-
- DefaultValue setClassArray(Class<?>... values);
-
- }
-
- String getName();
-
- AnnotationElement setName(String name);
-
- /**
- * Get this annotation element's type.
- */
- String getType();
-
- /**
- * Get this annotation element's fully qualified type.
- */
- String getQualifiedType();
-
- /**
- * Get this annotation element's {@link Type}
- */
- Type<JavaAnnotation> getTypeInspector();
-
- /**
- * Attempt to determine if this annotation element is of the same type as the given type.
- */
- boolean isType(Class<?> type);
-
- /**
- * Attempt to determine if this annotation element is of the same type as the given type.
- */
- boolean isType(String type);
-
- /**
- * Set the type of this {@link AnnotationElement} to the given {@link Class} type. Attempt to add an import statement
- * to this annotation element's base {@link O} if required.
- */
- AnnotationElement setType(Class<?> clazz);
-
- /**
- * Set the type of this {@link AnnotationElement} to the given type. Attempt to add an import statement to this
- * annotation element's base {@link O} if required. (Note that the given className must be fully-qualified in order
- * to properly import required classes)
- */
- AnnotationElement setType(String type);
-
- /**
- * Set the type of this {@link AnnotationElement} to the given {@link JavaSource<?>} type. Attempt to add an import
- * statement to this field's base {@link O} if required.
- */
- AnnotationElement setType(JavaSource<?> entity);
-
- DefaultValue getDefaultValue();
-}
50 parser-java-api/src/main/java/org/jboss/forge/parser/java/AnnotationTarget.java
View
@@ -1,50 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-import org.jboss.forge.parser.Internal;
-import org.jboss.forge.parser.Origin;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- */
-public interface AnnotationTarget<O extends JavaSource<O>, T> extends Internal, Origin<O>
-{
- /**
- * Add a new annotation instance to this {@link T}. (Note that an import statement must be added manually if
- * required.)
- */
- public abstract Annotation<O> addAnnotation();
-
- /**
- * Add a new annotation instance to this {@link T}, using the given {@link Class} as the annotation type. Attempt to
- * add an import statement to this object's {@link O} if required.
- */
- public abstract Annotation<O> addAnnotation(Class<? extends java.lang.annotation.Annotation> type);
-
- /**
- * Add a new annotation instance to this {@link T}, using the given {@link String} className as the annotation type.
- * Attempt to add an import statement to this object's {@link O} if required. (Note that the given className must be
- * fully-qualified in order to properly import required classes)
- */
- public abstract Annotation<O> addAnnotation(final String className);
-
- public abstract List<Annotation<O>> getAnnotations();
-
- public boolean hasAnnotation(final Class<? extends java.lang.annotation.Annotation> type);
-
- public boolean hasAnnotation(final String type);
-
- public Annotation<O> getAnnotation(final Class<? extends java.lang.annotation.Annotation> type);
-
- public Annotation<O> getAnnotation(final String type);
-
- public abstract T removeAnnotation(Annotation<O> annotation);
-}
23 parser-java-api/src/main/java/org/jboss/forge/parser/java/EnumConstant.java
View
@@ -1,23 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-import org.jboss.forge.parser.Internal;
-import org.jboss.forge.parser.Origin;
-
-public interface EnumConstant<O extends JavaSource<O>> extends Internal, Origin<O>
-{
- /**
- * Get this enum constant name.
- */
- String getName();
-
- /**
- * Set this enum constant name.
- */
- EnumConstant<O> setName(String name);
-}
50 parser-java-api/src/main/java/org/jboss/forge/parser/java/Extendable.java
View
@@ -1,50 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-/**
- * Represents a {@link JavaSource} that can extend other types. (Java inheritance and interfaces.)
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Extendable<O extends JavaSource<O>>
-{
- /**
- * Get this type's super class.
- *
- * @see #setSuperType(String)
- */
- public String getSuperType();
-
- /**
- * Set this type's super class.
- *
- * @see #setSuperType(String)
- */
- public O setSuperType(O type);
-
- /**
- * Set this type's super class.
- *
- * @see #setSuperType(String)
- */
- public O setSuperType(Class<?> type);
-
- /**
- * Set this type's super class.
- * <p>
- * <strong>For example:</strong><br/>
- * In the case of " <code>public class Foo extends Bar {}</code>" - <code>Foo</code> is the base type, and
- * <code>Bar</code> is the super class.)
- * <p>
- * Attempt to add an import statement to this object's {@link O} if required. (Note that the given className must be
- * fully-qualified in order to properly import required classes)
- */
- public O setSuperType(String type);
-}
71 parser-java-api/src/main/java/org/jboss/forge/parser/java/Field.java
View
@@ -1,71 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Field<O extends JavaSource<O>> extends Member<O, Field<O>>
-{
- Field<O> setName(String name);
-
- /**
- * Get this field's type.
- */
- String getType();
-
- /**
- * Get this field's fully qualified type.
- */
- String getQualifiedType();
-
- /**
- * Get this field's {@link Type}
- */
- Type<O> getTypeInspector();
-
- /**
- * Attempt to determine if this field is of the same type as the given type.
- */
- boolean isType(Class<?> type);
-
- /**
- * Attempt to determine if this field is of the same type as the given type.
- */
- boolean isType(String type);
-
- /**
- * Set the type of this {@link Field} to the given {@link Class} type. Attempt to add an import statement to this
- * field's base {@link O} if required.
- */
- Field<O> setType(Class<?> clazz);
-
- /**
- * Set the type of this {@link Field} to the given type. Attempt to add an import statement to this field's base
- * {@link O} if required. (Note that the given className must be fully-qualified in order to properly import required
- * classes)
- */
- Field<O> setType(String type);
-
- /**
- * Set the type of this {@link Field} to the given {@link JavaSource<?>} type. Attempt to add an import statement to
- * this field's base {@link O} if required.
- */
- Field<O> setType(JavaSource<?> entity);
-
- String getStringInitializer();
-
- String getLiteralInitializer();
-
- Field<O> setLiteralInitializer(String value);
-
- Field<O> setStringInitializer(String value);
-
- boolean isPrimitive();
-}
57 parser-java-api/src/main/java/org/jboss/forge/parser/java/FieldHolder.java
View
@@ -1,57 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-@SuppressWarnings("rawtypes")
-public interface FieldHolder<O extends JavaSource<O>> extends MemberHolder<O, Member>
-{
- /**
- * Add a new Java {@link Field} to this {@link O} instance. This field will be a stub until further modified.
- */
- public Field<O> addField();
-
- /**
- * Add a new {@link Field} declaration to this {@link O} instance, using the given {@link String} as the declaration.
- * <p/>
- * <strong>For example:</strong><br>
- * <code>Field f = javaClass.addField("private String newField;");</code>
- */
- public Field<O> addField(final String declaration);
-
- /**
- * Return whether or not this {@link O} declares a {@link Field} with the given name.
- */
- public boolean hasField(String name);
-
- /**
- * Return whether or not this {@link O} declares the given {@link Field} instance.
- */
- public boolean hasField(Field<O> field);
-
- /**
- * Get the {@link Field} with the given name and return it, otherwise, return null.
- */
- public Field<O> getField(String name);
-
- /**
- * Get a list of all {@link Field}s declared by this {@link O}, or return an empty list if no {@link Field}s are
- * declared.
- */
- public List<Field<O>> getFields();
-
- /**
- * Remove the given {@link Field} from this {@link O} instance, if it exists; otherwise, do nothing.
- */
- public O removeField(final Field<O> field);
-}
33 parser-java-api/src/main/java/org/jboss/forge/parser/java/GenericCapable.java
View
@@ -1,33 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-public interface GenericCapable<T>
-{
- /**
- * Adds a generic type
- *
- * @param genericType should never be null
- * @return
- */
- T addGenericType(String genericType);
-
- /**
- * Removes a generic type
- *
- * @param genericType should never be null
- * @return
- */
- T removeGenericType(String genericType);
-
- /**
- * Returns all the generic types associated with this object
- */
- List<String> getGenericTypes();
-}
32 parser-java-api/src/main/java/org/jboss/forge/parser/java/Import.java
View
@@ -1,32 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import org.jboss.forge.parser.Internal;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Import extends Internal
-{
- public String getPackage();
-
- public String getSimpleName();
-
- public String getQualifiedName();
-
- public Import setName(final String name);
-
- public boolean isStatic();
-
- public Import setStatic(final boolean value);
-
- public boolean isWildcard();
-
-}
119 parser-java-api/src/main/java/org/jboss/forge/parser/java/Importer.java
View
@@ -1,119 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Importer<O extends JavaSource<?>>
-{
- /**
- * Add an import by qualified class name. (E.g: "com.example.Imported") unless it is in the provided 'java.lang.*'
- * package.
- */
- public Import addImport(final String className);
-
- /**
- * Add an import for the given {@link Class} type.
- */
- public Import addImport(final Class<?> type);
-
- /**
- * Add an import for the given {@link Import} type.
- */
- public Import addImport(Import imprt);
-
- /**
- * Add an import for the given {@link JavaSource} type.
- */
- public <T extends JavaSource<?>> Import addImport(T type);
-
- /**
- * Return whether or not this {@link O} has an import for the given {@link Class} type.
- */
- boolean hasImport(Class<?> type);
-
- /**
- * Return whether or not this {@link O} has an import for the given fully-qualified class name.
- */
- boolean hasImport(String type);
-
- /**
- * Return whether or not this {@link O} could accept an import for the given {@link Class} type.
- */
- boolean requiresImport(Class<?> type);
-
- /**
- * Return whether or not this {@link O} could accept an import for the given fully-qualified class name.
- */
- boolean requiresImport(String type);
-
- /**
- * Return whether or not this {@link O} has an import for the given {@link T} type.
- */
- public <T extends JavaSource<T>> boolean hasImport(T type);
-
- /**
- * Return whether or not this {@link O} has the given {@link Import} type.
- */
- public boolean hasImport(Import imprt);
-
- /**
- * Get the {@link Import} for the given fully-qualified class name, if it exists; otherwise, return null;
- */
- public Import getImport(String literalValue);
-
- /**
- * Get the {@link Import} for the given {@link Class} type, if it exists; otherwise, return null;
- */
- public Import getImport(Class<?> type);
-
- /**
- * Get the {@link Import} for the given {@link T} type, if it exists; otherwise, return null;
- */
- public <T extends JavaSource<?>> Import getImport(T type);
-
- /**
- * Get the {@link Import} of the given {@link Import} type, if it exists; otherwise, return null;
- */
- public Import getImport(Import imprt);
-
- /**
- * Remove any {@link Import} for the given fully-qualified class name, if it exists; otherwise, do nothing;
- */
- public O removeImport(String name);
-
- /**
- * Remove any {@link Import} for the given {@link Class} type, if it exists; otherwise, do nothing;
- */
- public O removeImport(Class<?> type);
-
- /**
- * Remove any {@link Import} for the given {@link T} type, if it exists; otherwise, do nothing;
- */
- public <T extends JavaSource<?>> O removeImport(T type);
-
- /**
- * Remove the given {@link Import} from this {@link O} instance, if it exists; otherwise, do nothing;
- */
- public O removeImport(Import imprt);
-
- /**
- * Get an immutable list of all {@link Import}s currently imported by this {@link O}
- */
- public List<Import> getImports();
-
- /**
- * Given a simple or qualified type, resolve that type against the available imports and return the referenced type.
- * If the type cannot be resolved, return the given type unchanged.
- */
- public String resolveType(String type);
-}
36 parser-java-api/src/main/java/org/jboss/forge/parser/java/InterfaceCapable.java
View
@@ -1,36 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface InterfaceCapable<T extends JavaSource<T>>
-{
- List<String> getInterfaces();
-
- T addInterface(String type);
-
- T addInterface(Class<?> type);
-
- T addInterface(JavaInterface type);
-
- boolean hasInterface(String type);
-
- boolean hasInterface(Class<?> type);
-
- boolean hasInterface(JavaInterface type);
-
- T removeInterface(String type);
-
- T removeInterface(Class<?> type);
-
- T removeInterface(JavaInterface type);
-}
66 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaAnnotation.java
View
@@ -1,66 +0,0 @@
-/*
- * Copyright 2012-2013 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.lang.annotation.Annotation;
-import java.util.List;
-
-import org.jboss.forge.parser.JavaParser;
-
-/**
- * Represents a Java {@link Annotation} source file as an in-memory modifiable
- * element. See {@link JavaParser} for various options in generating
- * {@link JavaAnnotation} instances.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- */
-public interface JavaAnnotation extends JavaSource<JavaAnnotation>
-{
-
- /**
- * Add a new Java {@link AnnotationElement} to this {@link JavaAnnotation} instance. This will be a stub until
- * further modified.
- */
- public AnnotationElement addAnnotationElement();
-
- /**
- * Add a new {@link AnnotationElement} declaration to this {@link JavaAnnotation} instance, using the given
- * {@link String} as the declaration.
- * <p/>
- * <strong>For example:</strong><br>
- * <code>AnnotationElement e = javaClass.addAnnotationElement("String newAnnotationElement();");</code>
- */
- public AnnotationElement addAnnotationElement(final String declaration);
-
- /**
- * Return whether or not this {@link JavaAnnotation} declares an {@link AnnotationElement} with the given name.
- */
- public boolean hasAnnotationElement(String name);
-
- /**
- * Return whether or not this {@link JavaAnnotation} declares the given {@link AnnotationElement} instance.
- */
- public boolean hasAnnotationElement(AnnotationElement annotationElement);
-
- /**
- * Get the {@link AnnotationElement} with the given name and return it, otherwise, return null.
- */
- public AnnotationElement getAnnotationElement(String name);
-
- /**
- * Get a list of all {@link AnnotationElement}s declared by this {@link JavaAnnotation}, or return an empty list if
- * no {@link AnnotationElement}s are declared.
- */
- public List<AnnotationElement> getAnnotationElements();
-
- /**
- * Remove the given {@link AnnotationElement} from this {@link JavaAnnotation} instance, if it exists; otherwise, do
- * nothing.
- */
- public JavaAnnotation removeAnnotationElement(final AnnotationElement annotationElement);
-}
23 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaClass.java
View
@@ -1,23 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import org.jboss.forge.parser.JavaParser;
-
-/**
- * Represents a Java {@link Class} or interface source file as an in-memory modifiable element. See {@link JavaParser}
- * for various options in generating {@link JavaClass} instances.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- */
-public interface JavaClass extends
- JavaType<JavaClass>,
- Extendable<JavaClass>,
- Abstractable<JavaClass>
-{
-}
44 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaEnum.java
View
@@ -1,44 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-import org.jboss.forge.parser.JavaParser;
-
-/**
- * Represents a Java {@link Enum} source file as an in-memory modifiable element. See {@link JavaParser} for various
- * options in generating {@link JavaEnum} instances.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- */
-public interface JavaEnum extends JavaSource<JavaEnum>, InterfaceCapable<JavaEnum>, FieldHolder<JavaEnum>,
- MethodHolder<JavaEnum>
-{
- /**
- * Add a new {@link EnumConstant}
- */
- EnumConstant<JavaEnum> addEnumConstant();
-
- /**
- * Add a new {@link EnumConstant} using the given declaration.
- */
- EnumConstant<JavaEnum> addEnumConstant(String declaration);
-
- /**
- * Return the {@link EnumConstant} with the given name, or return null if no such constant exists.
- * @param name
- * @return
- */
- EnumConstant<JavaEnum> getEnumConstant(String name);
-
- /**
- * Return all declared {@link EnumConstant} types for this {@link JavaEnum}
- */
- List<EnumConstant<JavaEnum>> getEnumConstants();
-}
17 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaInterface.java
View
@@ -1,17 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface JavaInterface extends JavaType<JavaInterface>,
- InterfaceCapable<JavaInterface>
-{
-
-}
91 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaSource.java
View
@@ -1,91 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-import org.jboss.forge.parser.Origin;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-@SuppressWarnings("rawtypes")
-public interface JavaSource<T extends JavaSource<T>> extends
- Packaged<T>,
- Importer<T>,
- Named<T>,
- VisibilityScoped<T>,
- AnnotationTarget<T, T>,
- MemberHolder<T, Member>,
- Origin<T>
-{
- /**
- * Return the canonical name of this {@link T} instance. This is equivalent to calling
- * {@link Class#getCanonicalName()}
- */
- public String getCanonicalName();
-
- /**
- * Get the qualified-name of this {@link T} instance, where the qualified-name contains both the Java package and
- * simple class name of the type represented by this {@link T} instance.
- * <p/>
- * <strong>For example</strong>, calling: {@link #getQualifiedName()} is equivalent to calling "{@link #getPackage()}
- * + "." + {@link #getName()}", which in turn is equivalent to calling: {@link Class#getName()}
- */
- public String getQualifiedName();
-
- /**
- * Get a list of all {@link SyntaxError}s detected in the current {@link T}. Note that when errors are present, the
- * class may still be modified, but changes may not be completely accurate.
- */
- public List<SyntaxError> getSyntaxErrors();
-
- /**
- * Return whether or not this {@link T} currently has any {@link SyntaxError} s.
- */
- public boolean hasSyntaxErrors();
-
- /**
- * Return true if this {@link JavaSource} represents a {@link JavaClass}
- */
- public boolean isClass();
-
- /**
- * Return true if this {@link JavaSource} represents a {@link JavaEnum}
- */
- public boolean isEnum();
-
- /**
- * Return true if this {@link JavaSource} represents a {@link JavaClass} interface.
- */
- public boolean isInterface();
-
- /**
- * Return true if this {@link JavaSource} represents a {@link JavaAnnotation}
- */
- public boolean isAnnotation();
-
- /**
- * Return the enclosing {@link JavaSource} type in which this class is defined. If this class is a top-level type,
- * and is not a nested type, this object will return itself.
- */
- public JavaSource<?> getEnclosingType();
-
- /**
- * Return a list containing {@link JavaSource} instances for each nested {@link Class} declaration found within
- * <code>this</code>. Any modification of returned {@link JavaSource} instances will result in modification of the
- * contents contained by <code>this</code> the parent instance.
- */
- public List<JavaSource<?>> getNestedClasses();
-
- /**
- * Return the {@link SourceType} of this {@link JavaSource} instance.
- */
- public SourceType getSourceType();
-}
22 parser-java-api/src/main/java/org/jboss/forge/parser/java/JavaType.java
View
@@ -1,22 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-@SuppressWarnings("rawtypes")
-public interface JavaType<T extends JavaSource<T>> extends JavaSource<T>,
- InterfaceCapable<T>,
- MemberHolder<T, Member>,
- FieldHolder<T>,
- MethodHolder<T>,
- GenericCapable<T>
-{
-
-}
29 parser-java-api/src/main/java/org/jboss/forge/parser/java/Member.java
View
@@ -1,29 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import org.jboss.forge.parser.Origin;
-
-/**
- * Represents a {@link JavaClass} member. (E.g.: a {@link Field} or {@link Method})
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Member<O extends JavaSource<O>, T> extends VisibilityScoped<T>, AnnotationTarget<O, T>, Origin<O>
-{
- public String getName();
-
- public boolean isFinal();
-
- public T setFinal(boolean finl);
-
- public boolean isStatic();
-
- public T setStatic(boolean statc);
-}
22 parser-java-api/src/main/java/org/jboss/forge/parser/java/MemberHolder.java
View
@@ -1,22 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface MemberHolder<O extends JavaSource<O>, T>
-{
- /**
- * Return a list of all class members (fields, methods, etc.)
- */
- public List<Member<O, ?>> getMembers();
-}
128 parser-java-api/src/main/java/org/jboss/forge/parser/java/Method.java
View
@@ -1,128 +0,0 @@
-/*
- * Copyright 2012-2013 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-import org.jboss.forge.parser.Origin;
-
-/**
- * Represents a Java Method.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Method<O extends JavaSource<O>> extends Abstractable<Method<O>>, Member<O, Method<O>>, Origin<O>
-{
- /**
- * Get the inner body of this {@link Method}
- */
- public String getBody();
-
- /**
- * Set the inner body of this {@link Method}
- */
- public Method<O> setBody(final String body);
-
- /**
- * Toggle this method as a constructor. If true, and the name of the {@link Method} is not the same as the name of
- * its parent {@link JavaClass} , update the name of the to match.
- */
- public Method<O> setConstructor(final boolean constructor);
-
- /**
- * Return true if this {@link Method} is a constructor for the class in which it is defined.
- */
- public boolean isConstructor();
-
- /**
- * Set the name of this {@link Method}
- */
- public Method<O> setName(final String name);
-
- /**
- * Get the return type of this {@link Method} or return null if the return type is void.
- */
- public String getReturnType();
-
- /**
- * Get the fully qualified return type of this {@link Method} or return null if the return type is void.
- */
- public String getQualifiedReturnType();
-
- /**
- * Get the return {@link Type} of this {@link Method} or return null if the return type is void.
- */
- public Type<O> getReturnTypeInspector();
-
- /**
- * Set this {@link Method} to return the given type.
- */
- public Method<O> setReturnType(final Class<?> type);
-
- /**
- * Set this {@link Method} to return the given type.
- */
- public Method<O> setReturnType(final String type);
-
- /**
- * Set this {@link Method} to return the given {@link JavaSource} type.
- */
- public Method<O> setReturnType(JavaSource<?> type);
-
- /**
- * Return true if this {@link Method} has a return type of 'void'
- */
- public boolean isReturnTypeVoid();
-
- /**
- * Set this {@link Method} to return 'void'
- */
- public Method<O> setReturnTypeVoid();
-
- /**
- * Set this {@link Method}'s parameters.
- */
- public Method<O> setParameters(String string);
-
- /**
- * Get a list of this {@link Method}'s parameters.
- */
- public List<Parameter<O>> getParameters();
-
- /**
- * Convert this {@link Method} into a string representing its unique signature.
- */
- public String toSignature();
-
- /**
- * Add a thrown {@link Exception} to this method's signature.
- */
- public Method<O> addThrows(String type);
-
- /**
- * Add a thrown {@link Exception} to this method's signature.
- */
- public Method<O> addThrows(Class<? extends Exception> type);
-
- /**
- * Get a list of qualified (if possible) {@link Exception} class names thrown by this method.
- */
- public List<String> getThrownExceptions();
-
- /**
- * Remove a thrown {@link Exception} to this method's signature.
- */
- public Method<O> removeThrows(String type);
-
- /**
- * Remove a thrown {@link Exception} to this method's signature.
- */
- public Method<O> removeThrows(Class<? extends Exception> type);
-
-}
85 parser-java-api/src/main/java/org/jboss/forge/parser/java/MethodHolder.java
View
@@ -1,85 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-@SuppressWarnings("rawtypes")
-public interface MethodHolder<O extends JavaSource<O>> extends MemberHolder<O, Member>
-{
- /**
- * Add an uninitialized {@link Method} declaration to this {@link O} instance. This {@link Method} will be a stub
- * until further modified.
- */
- public Method<O> addMethod();
-
- /**
- * Add a new {@link Method} declaration to this {@link O} instance, using the given {@link String} as the method
- * declaration.
- * <p/>
- * <strong>For example:</strong><br>
- * <code>Method m = javaClass.addMethod("public String method() {return \"hello!\";}")</code>
- */
- public Method<O> addMethod(final String method);
-
- /**
- * Return true if this {@link O} has a method with the given name and zero parameters; otherwise return false.
- */
- public boolean hasMethod(final Method<O> name);
-
- /**
- * Return true if this {@link O} has a method with signature matching the given method's signature.
- */
- public boolean hasMethodSignature(final Method<?> method);
-
- /**
- * Return true if this {@link O} has a method with the given name and zero parameters; otherwise return false.
- */
- public boolean hasMethodSignature(final String name);
-
- /**
- * Return true if this {@link O} has a method with the given name and signature types; otherwise return false.
- */
- public boolean hasMethodSignature(final String name, String... paramTypes);
-
- /**
- * Return true if this {@link O} has a method with the given name and signature types; otherwise return false.
- */
- public boolean hasMethodSignature(final String name, Class<?>... paramTypes);
-
- /**
- * Return the {@link Method} with the given name and zero parameters; otherwise return null.
- */
- public Method<O> getMethod(final String name);
-
- /**
- * Return the {@link Method} with the given name and signature types; otherwise return null.
- */
- public Method<O> getMethod(final String name, String... paramTypes);
-
- /**
- * Return the {@link Method} with the given name and signature types; otherwise return null.
- */
- public Method<O> getMethod(final String name, Class<?>... paramTypes);
-
- /**
- * Get a {@link List} of all {@link Method}s declared by this {@link O} instance, if any; otherwise, return an empty
- * {@link List}
- */
- public List<Method<O>> getMethods();
-
- /**
- * Remove the given {@link Method} declaration from this {@link O} instance, if it exists; otherwise, do nothing.
- */
- public O removeMethod(final Method<O> method);
-
-}
33 parser-java-api/src/main/java/org/jboss/forge/parser/java/Named.java
View
@@ -1,33 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import java.lang.reflect.Method;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Named<T>
-{
- /**
- * Get the simple name of this {@link T} instance. (E.g: For a Java type,
- * this is be equivalent to calling,
- * <code>{@link Class#getSimpleName()}.</code> For a Java method, this would
- * be equivalent to calling {@link Method#getName()} ... and so on.
- */
- public String getName();
-
- /**
- * Set the simple-name of this {@link T} instance.
- *
- * @see #getName()
- */
- public T setName(String name);
-
-}
38 parser-java-api/src/main/java/org/jboss/forge/parser/java/Packaged.java
View
@@ -1,38 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Packaged<T>
-{
- /**
- * Get the package of this {@link T}, or return null if it is in the default
- * package.
- */
- public String getPackage();
-
- /**
- * Set this {@link T}' package.
- */
- public T setPackage(String name);
-
- /**
- * Set this {@link T} to be in the default package (removes any current
- * package declaration.)
- */
- public T setDefaultPackage();
-
- /**
- * Return whether or not this {@link T} is in the default package.
- */
- public boolean isDefaultPackage();
-
-}
20 parser-java-api/src/main/java/org/jboss/forge/parser/java/Parameter.java
View
@@ -1,20 +0,0 @@
-/*
- * Copyright 2012-2013 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Parameter<O extends JavaSource<O>> extends AnnotationTarget<O, Parameter<O>>
-{
- String getName();
-
- String getType();
-
- Type<?> getTypeInspector();
-}
16 parser-java-api/src/main/java/org/jboss/forge/parser/java/SourceType.java
View
@@ -1,16 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public enum SourceType
-{
- CLASS, INTERFACE, ENUM, ANNOTATION
-}
21 parser-java-api/src/main/java/org/jboss/forge/parser/java/SyntaxError.java
View
@@ -1,21 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-/**
- * Describes a syntax problem in a {@link JavaClass}.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface SyntaxError
-{
- /**
- * Get a textual description of the type of problem encountered.
- */
- public String getDescription();
-}
40 parser-java-api/src/main/java/org/jboss/forge/parser/java/Type.java
View
@@ -1,40 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-import java.util.List;
-
-import org.jboss.forge.parser.Origin;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface Type<O extends JavaSource<O>> extends Origin<O>
-{
- public abstract List<Type<O>> getTypeArguments();
-
- public abstract String getName();
-
- public abstract String getQualifiedName();
-
- public abstract Type<O> getParentType();
-
- public abstract boolean isArray();
-
- public abstract int getArrayDimensions();
-
- public abstract boolean isParameterized();
-
- public abstract boolean isPrimitive();
-
- public abstract boolean isQualified();
-
- public abstract boolean isWildcard();
-
-
-}
21 parser-java-api/src/main/java/org/jboss/forge/parser/java/ValuePair.java
View
@@ -1,21 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java;
-
-/**
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface ValuePair
-{
- String getName();
-
- String getLiteralValue();
-
- String getStringValue();
-}
86 parser-java-api/src/main/java/org/jboss/forge/parser/java/Visibility.java
View
@@ -1,86 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-import org.jboss.forge.parser.java.util.Assert;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public enum Visibility
-{
- PUBLIC("public"),
- PROTECTED("protected"),
- PRIVATE("private"),
- PACKAGE_PRIVATE("");
-
- private Visibility(String scope)
- {
- this.scope = scope;
- }
-
- private String scope;
-
- /**
- * private, public, protected, package private("")
- */
- public String scope()
- {
- return scope;
- }
-
- public static Visibility getFrom(VisibilityScoped<?> target)
- {
- Assert.notNull(target, "VisibilityScoped<T> target must not be null.");
-
- if (target.isPackagePrivate())
- return PACKAGE_PRIVATE;
- if (target.isPrivate())
- return PRIVATE;
- if (target.isPublic())
- return PUBLIC;
- if (target.isProtected())
- return PROTECTED;
-
- else
- {
- throw new IllegalStateException(VisibilityScoped.class.getSimpleName()
- + " target does not comply with visibility scoping. Must be one of " + Visibility.values() + "[ "
- + target + "]");
- }
- }
-
- @Override
- public String toString()
- {
- return scope;
- }
-
- public static <T extends VisibilityScoped<?>> T set(T target, Visibility scope)
- {
- Assert.notNull(target, "VisibilityScoped<T> target must not be null.");
- Assert.notNull(scope, "Visibility scope must not be null");
-
- if (PRIVATE.equals(scope))
- target.setPrivate();
- else if (PACKAGE_PRIVATE.equals(scope))
- target.setPackagePrivate();
- else if (PROTECTED.equals(scope))
- target.setProtected();
- else if (PUBLIC.equals(scope))
- target.setPublic();
-
- else
- {
- throw new IllegalStateException("Unknown Visibility scope.");
- }
-
- return target;
- }
-}
35 parser-java-api/src/main/java/org/jboss/forge/parser/java/VisibilityScoped.java
View
@@ -1,35 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public interface VisibilityScoped<T>
-{
- boolean isPackagePrivate();
-
- T setPackagePrivate();
-
- boolean isPublic();
-
- T setPublic();
-
- boolean isPrivate();
-
- T setPrivate();
-
- boolean isProtected();
-
- T setProtected();
-
- Visibility getVisibility();
-
- T setVisibility(Visibility scope);
-}
38 parser-java-api/src/main/java/org/jboss/forge/parser/java/util/Assert.java
View
@@ -1,38 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java.util;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public class Assert
-{
- public static void isTrue(boolean condition, String message)
- {
- if (!condition)
- {
- throw new IllegalStateException(message);
- }
- }
-
- public static void isFalse(boolean condition, String message)
- {
- if (condition)
- {
- throw new IllegalStateException(message);
- }
- }
-
- public static void notNull(Object object, String message) throws IllegalStateException
- {
- if (object == null)
- {
- throw new IllegalStateException(message);
- }
- }
-}
118 parser-java-api/src/main/java/org/jboss/forge/parser/java/util/Refactory.java
View
@@ -1,118 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.jboss.forge.parser.java.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.jboss.forge.parser.java.Field;
-import org.jboss.forge.parser.java.JavaClass;
-import org.jboss.forge.parser.java.Method;
-
-/**
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public class Refactory
-{
- public static void createGetterAndSetter(final JavaClass clazz, final Field<JavaClass> field)
- {
- if (!clazz.hasField(field))
- {
- throw new IllegalArgumentException("Entity did not contain the given field [" + field + "]");
- }
-
- clazz.getMethods();
-
- String fieldName = field.getName();
- String methodNameSuffix = Strings.capitalize(fieldName);
- clazz.addMethod().setReturnType(field.getTypeInspector().toString()).setName("get" + methodNameSuffix)
- .setPublic()
- .setBody("return this." + fieldName + ";");
-
- if (!field.isFinal())
- {
- clazz.addMethod().setReturnTypeVoid().setName("set" + methodNameSuffix).setPublic()
- .setParameters("final " + field.getTypeInspector().toString() + " " + fieldName)
- .setBody("this." + fieldName + " = " + fieldName + ";");
- }
- }
-
- public static void createHashCodeAndEquals(final JavaClass clazz)
- {
- clazz.addMethod(
- "public boolean equals(Object that) { " +
- "if (this == that) { return true; } " +
- "if (that == null) { return false; } " +
- "if (getClass() != that.getClass()) { return false; } " +
- "if (id != null) { return id.equals((("
- + clazz.getName() + ") that).id); } " +
- "return super.equals(that); " +
- "}")
- .addAnnotation(Override.class);
-
- clazz.addMethod(
- "public int hashCode() { " +
- "if (id != null) { return id.hashCode(); } " +
- "return super.hashCode(); }")
- .addAnnotation(Override.class);
- }
-
- public static void createToStringFromFields(final JavaClass clazz)
- {
- List<Field<JavaClass>> fields = clazz.getFields();
- createToStringFromFields(clazz, fields);
- }
-
- public static void createToStringFromFields(final JavaClass clazz, final Field<JavaClass>... fields)
- {
- createToStringFromFields(clazz, Arrays.asList(fields));
- }
-
- public static void createToStringFromFields(final JavaClass clazz, final List<Field<JavaClass>> fields)
- {
- Method<JavaClass> method = clazz.addMethod().setName("toString").setReturnType(String.class)
- .setPublic();
- method.addAnnotation(Override.class);
-
- List<String> list = new ArrayList<String>();
-
- String delimeter = "\n";
- for (Field<JavaClass> field : fields)
- {
- if (clazz.hasField(field))
- {
- StringBuilder line = new StringBuilder();
-
- if (!field.isPrimitive())
- if (field.isType(String.class))
- {
- line.append("if(").append(field.getName()).append(" != null && !").append(field.getName())
- .append(".trim().isEmpty())\n");
- }
- else
- {
- line.append("if(").append(field.getName()).append(" != null)\n");
- }
-
- boolean isFirst = list.isEmpty();
-
- line.append(" result += ").append(isFirst ? "\"" : "\", ");
- line.append(field.getName()).append(": \" + ").append(field.getName()).append(";");
-
- list.add(line.toString());
- }
- }
-
- String body = "String result = getClass().getSimpleName()+\" \";\n" +
- Strings.join(list, delimeter) + "\n" +
- "return result;";
- method.setBody(body);
- }
-}
414 parser-java-api/src/main/java/org/jboss/forge/parser/java/util/Strings.java
View
@@ -1,414 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Eclipse Public License version 1.0, available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.jboss.forge.parser.java.util;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-
-/**
- * String utilities.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public class Strings
-{
- /**
- * Capitalize the given String: "input" -> "Input"
- */
- public static String capitalize(final String input)
- {
- if ((input == null) || (input.length() == 0))
- {
- return input;
- }
- return input.substring(0, 1).toUpperCase() + input.substring(1);
- }
-
- public static String unquote(final String value)
- {
- String result = null;
- if (value != null)
- {
- result = value.replaceAll("\"(.*)\"", "$1");
- }
- return result;
- }
-
- public static String enquote(final String value)
- {
- String result = null;
- if (value != null)
- {
- result = "\"" + value + "\"";
- }
- return result;
- }
-
- public static String join(final Collection<?> collection, final String delimiter)
- {
- StringBuffer buffer = new StringBuffer();
- Iterator<?> iter = collection.iterator();
- while (iter.hasNext())
- {
- buffer.append(iter.next());
- if (iter.hasNext())
- {
- buffer.append(delimiter);
- }
- }
- return buffer.toString();
- }
-
- public static boolean isNullOrEmpty(final String string)
- {
- return (string == null) || string.isEmpty();
- }
-
- public static boolean isTrue(final String value)
- {
- return value == null ? false : "true".equalsIgnoreCase(value.trim());
- }
-
- public static boolean areEqual(final String left, final String right)
- {
- if ((left == null) && (right == null))
- {
- return true;
- }
- else if ((left == null) || (right == null))
- {
- return false;
- }
- return left.equals(right);
- }
-
- public static boolean areEqualTrimmed(final String left, final String right)
- {
- if ((left != null) && (right != null))
- {
- return left.trim().equals(right.trim());
- }
- return areEqual(left, right);
- }
-
- public static String stripQuotes(String value)
- {
- if ((value != null) && ((value.startsWith("'") && value.endsWith("'"))
- || (value.startsWith("\"") && value.endsWith("\"")))
- && (value.length() > 2))
- {
- value = value.substring(1, value.length() - 2);
- }
- return value;
- }
-
- public static String uncapitalize(final String input)
- {
- if ((input == null) || (input.length() == 0))
- {
- return input;
- }
- return input.substring(0, 1).toLowerCase() + input.substring(1);
- }
-
- /**
- * <p>
- * Find the Levenshtein distance between two Strings.
- * </p>
- *
- * <p>
- * This is the number of changes needed to change one String into another, where each change is a single character
- * modification (deletion, insertion or substitution).
- * </p>
- *
- * <p>
- * The previous implementation of the Levenshtein distance algorithm was from <a
- * href="http://www.merriampark.com/ld.htm">http://www.merriampark.com/ld.htm</a>
- * </p>
- *
- * <p>
- * Chas Emerick has written an implementation in Java, which avoids an OutOfMemoryError which can occur when my Java
- * implementation is used with very large strings.<br>
- * This implementation of the Levenshtein distance algorithm is from <a
- * href="http://www.merriampark.com/ldjava.htm">http://www.merriampark.com/ldjava.htm</a>
- * </p>
- *
- * <pre>
- * StringUtils.getLevenshteinDistance(null, *) = IllegalArgumentException
- * StringUtils.getLevenshteinDistance(*, null) = IllegalArgumentException
- * StringUtils.getLevenshteinDistance("","") = 0
- * StringUtils.getLevenshteinDistance("","a") = 1
- * StringUtils.getLevenshteinDistance("aaapppp", "") = 7
- * StringUtils.getLevenshteinDistance("frog", "fog") = 1
- * StringUtils.getLevenshteinDistance("fly", "ant") = 3
- * StringUtils.getLevenshteinDistance("elephant", "hippo") = 7
- * StringUtils.getLevenshteinDistance("hippo", "elephant") = 7
- * StringUtils.getLevenshteinDistance("hippo", "zzzzzzzz") = 8
- * StringUtils.getLevenshteinDistance("hello", "hallo") = 1
- * </pre>
- *
- * @param s the first String, must not be null
- * @param t the second String, must not be null
- * @return result distance
- * @throws IllegalArgumentException if either String input {@code null}
- */
- public static int getLevenshteinDistance(CharSequence s, CharSequence t)
- {
- if (s == null || t == null)
- {
- throw new IllegalArgumentException("Strings must not be null");
- }
-
- /*
- * The difference between this impl. and the previous is that, rather than creating and retaining a matrix of size
- * s.length() + 1 by t.length() + 1, we maintain two single-dimensional arrays of length s.length() + 1. The
- * first, d, is the 'current working' distance array that maintains the newest distance cost counts as we iterate
- * through the characters of String s. Each time we increment the index of String t we are comparing, d is copied
- * to p, the second int[]. Doing so allows us to retain the previous cost counts as required by the algorithm
- * (taking the minimum of the cost count to the left, up one, and diagonally up and to the left of the current
- * cost count being calculated). (Note that the arrays aren't really copied anymore, just switched...this is
- * clearly much better than cloning an array or doing a System.arraycopy() each time through the outer loop.)
- *
- * Effectively, the difference between the two implementations is this one does not cause an out of memory
- * condition when calculating the LD over two very large strings.
- */
-
- int n = s.length(); // length of s
- int m = t.length(); // length of t
-
- if (n == 0)
- {
- return m;
- }
- else if (m == 0)
- {
- return n;
- }
-
- if (n > m)
- {
- // swap the input strings to consume less memory
- CharSequence tmp = s;
- s = t;
- t = tmp;
- n = m;
- m = t.length();
- }
-
- int p[] = new int[n + 1]; // 'previous' cost array, horizontally
- int d[] = new int[n + 1]; // cost array, horizontally
- int _d[]; // placeholder to assist in swapping p and d
-
- // indexes into strings s and t
- int i; // iterates through s
- int j; // iterates through t
-
- char t_j; // jth character of t
-
- int cost; // cost
-
- for (i = 0; i <= n; i++)
- {
- p[i] = i;
- }
-
- for (j = 1; j <= m; j++)
- {
- t_j = t.charAt(j - 1);
- d[0] = j;
-
- for (i = 1; i <= n; i++)
- {
- cost = s.charAt(i - 1) == t_j ? 0 : 1;
- // minimum of cell to the left+1, to the top+1, diagonally left and up +cost
- d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] + cost);
- }
-
- // copy current distance counts to 'previous row' distance counts
- _d = p;
- p = d;
- d = _d;
- }
-
- // our last action in the above loop was to switch d and p, so p now
- // actually has the most recent cost counts
- return p[n];
- }
-
- /**
- * <p>
- * Find the Levenshtein distance between two Strings if it's less than or equal to a given threshold.
- * </p>
- *
- * <p>
- * This is the number of changes needed to change one String into another, where each change is a single character
- * modification (deletion, insertion or substitution).
- * </p>
- *
- * <p>
- * This implementation follows from Algorithms on Strings, Trees and Sequences by Dan Gusfield and Chas Emerick's
- * implementation of the Levenshtein distance algorithm from <a
- * href="http://www.merriampark.com/ld.htm">http://www.merriampark.com/ld.htm</a>
- * </p>
- *
- * <pre>
- * StringUtils.getLevenshteinDistance(null, *, *) = IllegalArgumentException