Skip to content

Commit

Permalink
Improved consistency checks; #74
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jan 17, 2020
1 parent 2292e3a commit b5cdf7e
Show file tree
Hide file tree
Showing 22 changed files with 399 additions and 98 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ A site with the links to the [API docs](http://phax.github.io/jcodemodel/) etc.

# News and noteworthy

* v3.3.1 - work in progress
* v3.4.0 - work in progress
* Added special top-level construct `JResourceDir` to represent pure resource directories ([issue #74](https://github.com/phax/jcodemodel/issues/74) from @guiguilechat)
* Added new class `JCodeModelException` as the base class for `JClassAlreadyExistsException` and the new class `JResourceAlreadyExistsException`
* Existing APIs were changed to throw `JCodeModelException` instead of `JClassAlreadyExistsException`
* v3.3.0 - 2019-11-24
* Added check for package names so that no invalid package names can be created ([issue #70](https://github.com/phax/jcodemodel/issues/70) from @guiguilechat)
* Added check to avoid creating classes existing in the "java.lang" package ([issue #71](https://github.com/phax/jcodemodel/issues/71) from @guiguilechat)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<version>1.11.0</version>
</parent>
<artifactId>jcodemodel</artifactId>
<version>3.3.1-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>jcodemodel</name>
<description>Java code generation library</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected abstract CLASSTYPE createInnerClass (final int nMods,
@Nonnull
public final CLASSTYPE _class (final int nMods,
@Nonnull final String sName,
@Nonnull final EClassType eClassType) throws JClassAlreadyExistsException
@Nonnull final EClassType eClassType) throws JCodeModelException
{
String sRealName;
if (JCodeModel.isFileSystemCaseSensitive ())
Expand Down
39 changes: 18 additions & 21 deletions src/main/java/com/helger/jcodemodel/IJClassContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,23 @@ public interface IJClassContainer <CLASSTYPE extends IJClassContainer <CLASSTYPE
* @param eClassType
* The type of class to create. May not be <code>null</code>.
* @return The created ...
* @throws JClassAlreadyExistsException
* @throws JCodeModelException
* If another class/interface/... with the same name already exists
*/
@Nonnull
CLASSTYPE _class (int nMods,
@Nonnull String sName,
@Nonnull EClassType eClassType) throws JClassAlreadyExistsException;
CLASSTYPE _class (int nMods, @Nonnull String sName, @Nonnull EClassType eClassType) throws JCodeModelException;

/**
* Add a new public class to this class/package.
*
* @param sName
* Name of class to be added to this package
* @return Newly generated class
* @throws JClassAlreadyExistsException
* @throws JCodeModelException
* If another class/interface/... with the same name already exists
*/
@Nonnull
default CLASSTYPE _class (@Nonnull final String sName) throws JClassAlreadyExistsException
default CLASSTYPE _class (@Nonnull final String sName) throws JCodeModelException
{
return _class (JMod.PUBLIC, sName);
}
Expand All @@ -124,11 +122,11 @@ default CLASSTYPE _class (@Nonnull final String sName) throws JClassAlreadyExist
* @param sName
* Name of class to be added to this package
* @return Newly generated class
* @throws JClassAlreadyExistsException
* @throws JCodeModelException
* If another class/interface/... with the same name already exists
*/
@Nonnull
default CLASSTYPE _class (final int nMods, @Nonnull final String sName) throws JClassAlreadyExistsException
default CLASSTYPE _class (final int nMods, @Nonnull final String sName) throws JCodeModelException
{
return _class (nMods, sName, EClassType.CLASS);
}
Expand All @@ -139,11 +137,11 @@ default CLASSTYPE _class (final int nMods, @Nonnull final String sName) throws J
* @param sName
* Name of interface to be added to this package
* @return Newly generated interface
* @throws JClassAlreadyExistsException
* @throws JCodeModelException
* If another class/interface/... with the same name already exists
*/
@Nonnull
default CLASSTYPE _interface (@Nonnull final String sName) throws JClassAlreadyExistsException
default CLASSTYPE _interface (@Nonnull final String sName) throws JCodeModelException
{
return _interface (JMod.PUBLIC, sName);
}
Expand All @@ -156,11 +154,11 @@ default CLASSTYPE _interface (@Nonnull final String sName) throws JClassAlreadyE
* @param sName
* Name of interface to be added to this package
* @return Newly generated interface
* @throws JClassAlreadyExistsException
* @throws JCodeModelException
* If another class/interface/... with the same name already exists
*/
@Nonnull
default CLASSTYPE _interface (final int nMods, @Nonnull final String sName) throws JClassAlreadyExistsException
default CLASSTYPE _interface (final int nMods, @Nonnull final String sName) throws JCodeModelException
{
return _class (JMod.PUBLIC, sName, EClassType.INTERFACE);
}
Expand All @@ -171,11 +169,11 @@ default CLASSTYPE _interface (final int nMods, @Nonnull final String sName) thro
* @param sName
* Name of the annotation Type declaration to be added to this package
* @return newly created Annotation Type Declaration
* @throws JClassAlreadyExistsException
* @throws JCodeModelException
* If another class/interface/... with the same name already exists
*/
@Nonnull
default CLASSTYPE _annotationTypeDeclaration (@Nonnull final String sName) throws JClassAlreadyExistsException
default CLASSTYPE _annotationTypeDeclaration (@Nonnull final String sName) throws JCodeModelException
{
return _annotationTypeDeclaration (JMod.PUBLIC, sName);
}
Expand All @@ -188,12 +186,11 @@ default CLASSTYPE _annotationTypeDeclaration (@Nonnull final String sName) throw
* @param sName
* Name of the annotation Type declaration to be added to this package
* @return newly created Annotation Type Declaration
* @throws JClassAlreadyExistsException
* @throws JCodeModelException
* If another class/interface/... with the same name already exists
*/
@Nonnull
default CLASSTYPE _annotationTypeDeclaration (final int nMods,
@Nonnull final String sName) throws JClassAlreadyExistsException
default CLASSTYPE _annotationTypeDeclaration (final int nMods, @Nonnull final String sName) throws JCodeModelException
{
return _class (nMods, sName, EClassType.ANNOTATION_TYPE_DECL);
}
Expand All @@ -204,11 +201,11 @@ default CLASSTYPE _annotationTypeDeclaration (final int nMods,
* @param sName
* Name of the enum to be added to this package
* @return newly created enum
* @throws JClassAlreadyExistsException
* @throws JCodeModelException
* If another class/interface/... with the same name already exists
*/
@Nonnull
default CLASSTYPE _enum (@Nonnull final String sName) throws JClassAlreadyExistsException
default CLASSTYPE _enum (@Nonnull final String sName) throws JCodeModelException
{
return _enum (JMod.PUBLIC, sName);
}
Expand All @@ -221,11 +218,11 @@ default CLASSTYPE _enum (@Nonnull final String sName) throws JClassAlreadyExists
* @param sName
* Name of the enum to be added to this package
* @return newly created Enum
* @throws JClassAlreadyExistsException
* @throws JCodeModelException
* If another class/interface/... with the same name already exists
*/
@Nonnull
default CLASSTYPE _enum (final int nMods, @Nonnull final String sName) throws JClassAlreadyExistsException
default CLASSTYPE _enum (final int nMods, @Nonnull final String sName) throws JCodeModelException
{
return _class (nMods, sName, EClassType.ENUM);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@
import com.helger.jcodemodel.util.JCValueEnforcer;

/**
* Indicates that the class is already created.
* Indicates that the class is already created.<br>
* Up to and including v3.3.0 this was directly derived from Exception
*
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public class JClassAlreadyExistsException extends Exception
public class JClassAlreadyExistsException extends JCodeModelException
{
private final AbstractJClass m_aExisting;

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/helger/jcodemodel/JCodeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,13 @@ public List <JResourceDir> getAllResourceDirs ()
* @param eClassType
* Class type to use (enum/class/interface/annotation)
* @return New {@link JDefinedClass}
* @exception JClassAlreadyExistsException
* @exception JCodeModelException
* When the specified class/interface was already created.
*/
@Nonnull
public JDefinedClass _class (final int nMods,
@Nonnull final String sFullyQualifiedClassName,
@Nonnull final EClassType eClassType) throws JClassAlreadyExistsException
@Nonnull final EClassType eClassType) throws JCodeModelException
{
final int nIdx = sFullyQualifiedClassName.lastIndexOf ('.');
if (nIdx < 0)
Expand All @@ -342,11 +342,11 @@ public JDefinedClass _class (final int nMods,
* @param sFullyQualifiedClassName
* FQCN
* @return New {@link JDefinedClass}
* @exception JClassAlreadyExistsException
* @exception JCodeModelException
* When the specified class/interface was already created.
*/
@Nonnull
public JDefinedClass _class (@Nonnull final String sFullyQualifiedClassName) throws JClassAlreadyExistsException
public JDefinedClass _class (@Nonnull final String sFullyQualifiedClassName) throws JCodeModelException
{
return _class (sFullyQualifiedClassName, EClassType.CLASS);
}
Expand All @@ -359,12 +359,12 @@ public JDefinedClass _class (@Nonnull final String sFullyQualifiedClassName) thr
* @param sFullyQualifiedClassName
* FQCN
* @return New {@link JDefinedClass}
* @exception JClassAlreadyExistsException
* @exception JCodeModelException
* When the specified class/interface was already created.
*/
@Nonnull
public JDefinedClass _class (final int nMods,
@Nonnull final String sFullyQualifiedClassName) throws JClassAlreadyExistsException
@Nonnull final String sFullyQualifiedClassName) throws JCodeModelException
{
return _class (nMods, sFullyQualifiedClassName, EClassType.CLASS);
}
Expand All @@ -377,12 +377,12 @@ public JDefinedClass _class (final int nMods,
* @param eClassType
* Class type to use (enum/class/interface/annotation)
* @return New {@link JDefinedClass}
* @exception JClassAlreadyExistsException
* @exception JCodeModelException
* When the specified class/interface was already created.
*/
@Nonnull
public JDefinedClass _class (@Nonnull final String sFullyQualifiedClassName,
@Nonnull final EClassType eClassType) throws JClassAlreadyExistsException
@Nonnull final EClassType eClassType) throws JCodeModelException
{
return _class (JMod.PUBLIC, sFullyQualifiedClassName, eClassType);
}
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/com/helger/jcodemodel/JCodeModelException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
* Portions Copyright 2013-2020 Philip Helger + contributors
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.helger.jcodemodel;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Base class for all code model related exception.
*
* @author Philip Helger
* @since 3.4.0
*/
public class JCodeModelException extends Exception
{
protected JCodeModelException ()
{}

public JCodeModelException (@Nonnull final String sMsg)
{
super (sMsg);
}

public JCodeModelException (@Nonnull final String sMsg, @Nullable final Throwable aCause)
{
super (sMsg, aCause);
}
}
Loading

0 comments on commit b5cdf7e

Please sign in to comment.