content, final int mods) {
throw new UnsupportedOperationException("Interfaces cannot have constructors");
}
boolean supportsCompactInitOnly() {
return false;
}
boolean methodCanHaveBody(final int mods) {
return false;
}
public Kind getItemKind() {
return Kind.INTERFACE;
}
public String getName() {
return super.getName();
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAnnotatable.java 0000664 0000000 0000000 00000002717 12500061542 0026333 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.lang.annotation.Annotation;
/**
* A program element which can be annotated.
*
* @author David M. Lloyd
*/
public interface JAnnotatable {
/**
* Add an annotation.
*
* @param type the type of the annotation to add
* @return the new annotation
*/
JAnnotation annotate(String type);
/**
* Add an annotation.
*
* @param type the type of the annotation to add
* @return the new annotation
*/
JAnnotation annotate(JType type);
/**
* Add an annotation.
*
* @param type the type of the annotation to add
* @return the new annotation
*/
JAnnotation annotate(Class extends Annotation> type);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAnnotation.java 0000664 0000000 0000000 00000012051 12500061542 0026205 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.lang.annotation.Annotation;
/**
* An annotation.
*
* @author David M. Lloyd
*/
public interface JAnnotation {
/**
* Set the "value" property of this annotation. To set an array of values, see {@link JExprs#array(JExpr...)}.
*
* @param expr the annotation value
* @return this annotation
*/
JAnnotation value(JExpr expr);
/**
* Set the "value" property of this annotation to a string.
*
* @param literal the annotation value string
* @return this annotation
*/
JAnnotation value(String literal);
/**
* Set the "value" property of this annotation to a nested annotation of the given type.
*
* @param type the annotation type
* @return the nested annotation
*/
JAnnotation annotationValue(String type);
/**
* Set the "value" property of this annotation to a nested annotation of the given type.
*
* @param type the annotation type
* @return the nested annotation
*/
JAnnotation annotationValue(JType type);
/**
* Set the "value" property of this annotation to a nested annotation of the given type.
*
* @param type the annotation type
* @return the nested annotation
*/
JAnnotation annotationValue(Class extends Annotation> type);
/**
* Set the "value" property of this annotation to an array of nested annotations of the given type.
*
* @param type the annotation array element type
* @return the nested annotation
*/
JAnnotationArray annotationArrayValue(String type);
/**
* Set the "value" property of this annotation to an array of nested annotations of the given type.
*
* @param type the annotation array element type
* @return the nested annotation
*/
JAnnotationArray annotationArrayValue(JType type);
/**
* Set the "value" property of this annotation to an array of nested annotations of the given type.
*
* @param type the annotation array element type
* @return the nested annotation
*/
JAnnotationArray annotationArrayValue(Class extends Annotation> type);
/**
* Set the named property of this annotation. To set an array of values, see {@link JExprs#array(JExpr...)}.
*
* @param name the annotation property name
* @param expr the annotation value
* @return this annotation
*/
JAnnotation value(String name, JExpr expr);
/**
* Set the named property of this annotation to a string.
*
* @param name the annotation property name
* @param literal the annotation value string
* @return this annotation
*/
JAnnotation value(String name, String literal);
/**
* Set the named property of this annotation to a nested annotation of the given type.
*
* @param type the annotation type
* @return the nested annotation
*/
JAnnotation annotationValue(String name, String type);
/**
* Set the named property of this annotation to a nested annotation of the given type.
*
* @param type the annotation type
* @return the nested annotation
*/
JAnnotation annotationValue(String name, JType type);
/**
* Set the named property of this annotation to a nested annotation of the given type.
*
* @param type the annotation type
* @return the nested annotation
*/
JAnnotation annotationValue(String name, Class extends Annotation> type);
/**
* Set the named property of this annotation to an array of nested annotations of the given type.
*
* @param type the annotation array element type
* @return the nested annotation
*/
JAnnotationArray annotationArrayValue(String name, String type);
/**
* Set the named property of this annotation to an array of nested annotations of the given type.
*
* @param type the annotation array element type
* @return the nested annotation
*/
JAnnotationArray annotationArrayValue(String name, JType type);
/**
* Set the named property of this annotation to an array of nested annotations of the given type.
*
* @param type the annotation array element type
* @return the nested annotation
*/
JAnnotationArray annotationArrayValue(String name, Class extends Annotation> type);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAnnotationArray.java 0000664 0000000 0000000 00000001772 12500061542 0027214 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* An array of annotations.
*
* @author David M. Lloyd
*/
public interface JAnnotationArray {
/**
* Add an annotation of the array's type to the array.
* @return the new annotation
*/
JAnnotation add();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAnonymousClassDef.java 0000664 0000000 0000000 00000001763 12500061542 0027500 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* An anonymous class definition. Anonymous classes have characteristics of both constructor calls and class
* definitions.
*
* @author David M. Lloyd
*/
public interface JAnonymousClassDef extends JCall, JClassDef {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JArrayExpr.java 0000664 0000000 0000000 00000002274 12500061542 0026016 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* An array expression, which can have more values added to it.
*/
public interface JArrayExpr extends JExpr {
// originals
/**
* Add an element to this array. Returns this array.
*
* @param value the value to add
* @return this array expression
*/
JArrayExpr add(JExpr value);
/**
* Get the current number of elements added to this array.
*
* @return the number of elements
*/
int elementCount();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JAssignableExpr.java 0000664 0000000 0000000 00000010031 12500061542 0026776 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* An expression which is assignable (that is, is a valid "lvalue").
*
* @author David M. Lloyd
*/
public interface JAssignableExpr extends JExpr, JStatement {
// assign
/**
* Combine this expression with another using the binary {@code =} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr assign(JExpr e1);
/**
* Combine this expression with another using the binary {@code +=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr addAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code -=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr subAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code *=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr mulAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code /=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr divAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code %=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr modAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code &=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr andAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code |=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr orAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code ^=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr xorAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code >>=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr shrAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code >>>=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr lshrAssign(JExpr e1);
/**
* Combine this expression with another using the binary {@code <<=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr shlAssign(JExpr e1);
// inc/dec
/**
* Apply the postfix {@code ++} operator to this expression.
*
* @return the new expression
*/
JExpr postInc();
/**
* Apply the postfix {@code --} operator to this expression.
*
* @return the new expression
*/
JExpr postDec();
/**
* Apply the prefix {@code ++} operator to this expression.
*
* @return the new expression
*/
JExpr preInc();
/**
* Apply the prefix {@code --} operator to this expression.
*
* @return the new expression
*/
JExpr preDec();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JBlock.java 0000664 0000000 0000000 00000044256 12500061542 0025141 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import javax.lang.model.element.ExecutableElement;
/**
* A block of code, to which statements may be added.
*
* @author David M. Lloyd
*/
public interface JBlock extends JStatement, JCommentable {
/**
* Insert a blank line at this point.
*
* @return this block
*/
JBlock blankLine();
/**
* Create a nested sub-block at this point.
*
* @param braces the rule for adding braces
* @return the nested block
*/
JBlock block(Braces braces);
// program flow
/**
* Insert an {@code if} statement at this point.
*
* @param cond the {@code if} condition
* @return the {@code if} statement
*/
JIf _if(JExpr cond);
/**
* Insert a {@code while} statement at this point.
*
* @param cond the {@code while} condition
* @return the {@code while} statement
*/
JBlock _while(JExpr cond);
/**
* Insert a {@code do}/{@code while} statement at this point.
*
* @param cond the {@code while} condition
* @return the {@code while} statement
*/
JBlock _do(JExpr cond);
/**
* Add a label at this point, which may be used for future branch instructions.
*
* @param name the label name
* @return the label
*/
JLabel label(String name);
/**
* Add a label at this point whose unique name is automatically generated.
*
* @return the label
*/
JLabel anonLabel();
/**
* Create a forward label that can be named and attached later.
*
* @return the forward label
*/
JLabel forwardLabel();
/**
* Name and attach a forward label.
*
* @param label the label to name and attach
* @param name the label name
* @return the attached label
*/
JLabel label(JLabel label, String name);
/**
* Name and attach a forward label as anonymous.
*
* @param label the label to name and attach
* @return the attached label
*/
JLabel anonLabel(JLabel label);
/**
* Insert a {@code continue} statement at this point.
*
* @return the statement
*/
JStatement _continue();
/**
* Insert a labelled {@code continue} statement at this point.
*
* @param label the label
* @return the statement
*/
JStatement _continue(JLabel label);
/**
* Insert a {@code break} statement at this point.
*
* @return the statement
*/
JStatement _break();
/**
* Insert a labelled {@code break} statement at this point.
*
* @param label the label
* @return the statement
*/
JStatement _break(JLabel label);
/**
* Insert a "for-each" style {@code for} loop at this point.
*
* @param mods the item variable modifiers
* @param type the item variable type
* @param name the item variable name
* @param iterable the iterable or array expression
* @return the body of the {@code for} loop
*/
JBlock forEach(int mods, String type, String name, JExpr iterable);
/**
* Insert a "for-each" style {@code for} loop at this point.
*
* @param mods the item variable modifiers
* @param type the item variable type
* @param name the item variable name
* @param iterable the iterable or array expression
* @return the body of the {@code for} loop
*/
JBlock forEach(int mods, JType type, String name, JExpr iterable);
/**
* Insert a "for-each" style {@code for} loop at this point.
*
* @param mods the item variable modifiers
* @param type the item variable type
* @param name the item variable name
* @param iterable the iterable or array expression
* @return the body of the {@code for} loop
*/
JBlock forEach(int mods, Class> type, String name, JExpr iterable);
/**
* Insert a {@code for} loop at this point.
*
* @return the {@code for} loop
*/
JFor _for();
/**
* Insert a {@code switch} statement at this point.
*
* @param expr the {@code switch} expression
* @return the {@code switch} statement
*/
JSwitch _switch(JExpr expr);
/**
* Insert a {@code return} statement at this point.
*
* @param expr the expression to return
* @return the statement
*/
JStatement _return(JExpr expr);
/**
* Insert a {@code void} {@code return} statement at this point.
*
* @return the statement
*/
JStatement _return();
// assert
/**
* Insert an {@code assert} statement at this point.
*
* @param expr the expression to assert
* @return the statement
*/
JStatement _assert(JExpr expr);
/**
* Insert an {@code assert} statement at this point with a message.
*
* @param expr the expression to assert
* @param message the assertion message
* @return the statement
*/
JStatement _assert(JExpr expr, JExpr message);
// constructor invocations
/**
* Insert a {@code this()} call at this point.
*
* @return the call
*/
JCall callThis();
/**
* Insert a {@code super()} call at this point.
*
* @return the call
*/
JCall callSuper();
// expression
/**
* Insert an expression statement at this point. Expressions which are invalid statements may generate an
* error at the time this method is called, or at compile time.
*
* @param expr the expression to add
* @return the statement
*/
JStatement add(JExpr expr);
// invocations
/**
* Insert a method invocation at this point.
*
* Note that these two invocations are identical:
*
* {@code
block.call(element);
block.add(JExprs.call(element));
}
*
* @param element the program element whose name to use
* @return the method call
*/
JCall call(ExecutableElement element);
/**
* Insert a method invocation at this point.
*
* @param obj the expression upon which to invoke
* @param element the program element whose name to use
* @return the method call
*/
JCall call(JExpr obj, ExecutableElement element);
/**
* Insert a method invocation at this point.
*
* Note that these two invocations are identical:
*
* {@code
block.call(methodName);
block.add(JExprs.call(methodName));
}
*
* @param name the method name
* @return the method call
*/
JCall call(String name);
/**
* Insert a method invocation at this point.
*
* @param obj the expression upon which to invoke
* @param name the method name
* @return the method call
*/
JCall call(JExpr obj, String name);
/**
* Insert a type-qualified static method invocation at this point.
*
* @param element the program element whose name and type to use
* @return the method call
*/
JCall callStatic(ExecutableElement element);
/**
* Insert a type-qualified static method invocation at this point.
*
* @param type the type upon which to invoke
* @param name the method name
* @return the method call
*/
JCall callStatic(String type, String name);
/**
* Insert a type-qualified static method invocation at this point.
*
* @param type the type upon which to invoke
* @param name the method name
* @return the method call
*/
JCall callStatic(JType type, String name);
/**
* Insert a type-qualified static method invocation at this point.
*
* @param type the type upon which to invoke
* @param name the method name
* @return the method call
*/
JCall callStatic(Class> type, String name);
// raw construction
/**
* Insert an object construction statement at this point.
*
* @param type the type to instantiate
* @return the constructor call
*/
JCall _new(String type);
/**
* Insert an object construction statement at this point.
*
* @param type the type to instantiate
* @return the constructor call
*/
JCall _new(JType type);
/**
* Insert an object construction statement at this point.
*
* @param type the type to instantiate
* @return the constructor call
*/
JCall _new(Class> type);
/**
* Insert an object construction statement for an anonymous class at this point.
*
* @param type the type to instantiate
* @return the anonymous class definition
*/
JAnonymousClassDef _newAnon(String type);
/**
* Insert an object construction statement for an anonymous class at this point.
*
* @param type the type to instantiate
* @return the anonymous class definition
*/
JAnonymousClassDef _newAnon(JType type);
/**
* Insert an object construction statement for an anonymous class at this point.
*
* @param type the type to instantiate
* @return the anonymous class definition
*/
JAnonymousClassDef _newAnon(Class> type);
// local class definition
/**
* Insert a local class definition at this point.
*
* @param mods the class modifiers
* @param name the local class name
* @return the local class definition
*/
JClassDef _class(int mods, String name);
// synch
/**
* Insert a {@code synchronized} block at this point.
*
* @param synchExpr the lock expression
* @return the {@code synchronized} block
*/
JBlock _synchronized(JExpr synchExpr);
// assignment
/**
* Insert an assignment ({@code =}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement assign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code +=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement addAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code -=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement subAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code *=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement mulAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code /=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement divAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code %=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement modAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code &=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement andAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code |=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement orAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code ^=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement xorAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code >>=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement shrAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code >>>=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement lshrAssign(JAssignableExpr target, JExpr e1);
/**
* Insert an assignment ({@code <<=}) expression at this point.
*
* @param target the assignment target
* @param e1 the expression to apply
* @return the statement
*/
JStatement shlAssign(JAssignableExpr target, JExpr e1);
// inc/dec
/**
* Insert a postfix {@code ++} expression at this point.
*
* @param target the target expression
* @return the statement
*/
JStatement postInc(JAssignableExpr target);
/**
* Insert a postfix {@code --} expression at this point.
*
* @param target the target expression
* @return the statement
*/
JStatement postDec(JAssignableExpr target);
/**
* Insert a prefix {@code ++} expression at this point.
*
* @param target the target expression
* @return the statement
*/
JStatement preInc(JAssignableExpr target);
/**
* Insert a prefix {@code --} expression at this point.
*
* @param target the target expression
* @return the statement
*/
JStatement preDec(JAssignableExpr target);
// empty
/**
* Insert an empty statement at this point (just a semicolon).
*
* @return the statement
*/
JStatement empty();
// exceptions
/**
* Insert a {@code throw} statement at this point.
*
* @param expr the expression to throw
* @return the statement
*/
JStatement _throw(JExpr expr);
/**
* Insert a {@code try} block at this point.
*
* @return the {@code try} block
*/
JTry _try();
// declarations
/**
* Insert a local variable declaration at this point.
*
* @param mods the variable modifiers
* @param type the local variable type
* @param name the local variable name
* @param value the local variable's initializer expression
* @return the local variable declaration
*/
JVarDeclaration var(int mods, String type, String name, JExpr value);
/**
* Insert a local variable declaration at this point.
*
* @param mods the variable modifiers
* @param type the local variable type
* @param name the local variable name
* @param value the local variable's initializer expression
* @return the local variable declaration
*/
JVarDeclaration var(int mods, JType type, String name, JExpr value);
/**
* Insert a local variable declaration at this point.
*
* @param mods the variable modifiers
* @param type the local variable type
* @param name the local variable name
* @param value the local variable's initializer expression
* @return the local variable declaration
*/
JVarDeclaration var(int mods, Class> type, String name, JExpr value);
/**
* Insert a local variable declaration at this point.
*
* @param mods the variable modifiers
* @param type the local variable type
* @param name the local variable name
* @return the local variable declaration
*/
JVarDeclaration var(int mods, String type, String name);
/**
* Insert a local variable declaration at this point.
*
* @param mods the variable modifiers
* @param type the local variable type
* @param name the local variable name
* @return the local variable declaration
*/
JVarDeclaration var(int mods, JType type, String name);
/**
* Insert a local variable declaration at this point.
*
* @param mods the variable modifiers
* @param type the local variable type
* @param name the local variable name
* @return the local variable declaration
*/
JVarDeclaration var(int mods, Class> type, String name);
/**
* Insert a local variable declaration at this point with a generated name.
*
* @param type the local variable type
* @param value the local variable's initializer expression
* @return the local variable expression
*/
JExpr tempVar(String type, JExpr value);
/**
* Insert a local variable declaration at this point with a generated name.
*
* @param type the local variable type
* @param value the local variable's initializer expression
* @return the local variable expression
*/
JExpr tempVar(JType type, JExpr value);
/**
* Insert a local variable declaration at this point with a generated name.
*
* @param type the local variable type
* @param value the local variable's initializer expression
* @return the local variable expression
*/
JExpr tempVar(Class> type, JExpr value);
/**
* Generate a temporary variable name.
*
* @return the generated name
*/
String tempName();
/**
* Braces mode.
*
* @apiviz.exclude
*/
enum Braces {
/**
* Braces are optional and won't be rendered unless forced.
*/
OPTIONAL,
/**
* Braces are only required if the block contains more or less than one statement.
*/
IF_MULTILINE,
/**
* Braces should always be used.
*/
REQUIRED,
;
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JCall.java 0000664 0000000 0000000 00000003505 12500061542 0024752 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A method or constructor call.
*
* @author David M. Lloyd
*/
public interface JCall extends JExpr, JSimpleArgs {
/**
* Use the "diamond" {@code <>} syntax to specify inferred type arguments.
*
* @return this call
*/
JCall diamond();
/**
* Add a type argument to this call.
*
* @param type the type to add
* @return this call
*/
JCall typeArg(JType type);
/**
* Add a type argument to this call.
*
* @param type the type to add
* @return this call
*/
JCall typeArg(String type);
/**
* Add a type argument to this call.
*
* @param type the type to add
* @return this call
*/
JCall typeArg(Class> type);
/**
* Add an actual parameter argument to this call.
*
* @param expr the argument expression
* @return this call
*/
JCall arg(JExpr expr);
/**
* Get the type arguments defined thus far.
*
* @return the type arguments
*/
JType[] typeArguments();
JExpr[] arguments();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JCatch.java 0000664 0000000 0000000 00000002702 12500061542 0025117 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A {@code catch} branch for a {@code try} block.
*
* @author David M. Lloyd
*/
public interface JCatch extends JTry {
/**
* Add another type option to this catch branch.
*
* @param orType the alternative type
* @return this catch block
*/
JCatch or(JType orType);
/**
* Add another type option to this catch branch.
*
* @param orType the alternative type
* @return this catch block
*/
JCatch or(String orType);
/**
* Add another type option to this catch branch.
*
* @param orType the alternative type
* @return this catch block
*/
JCatch or(Class extends Throwable> orType);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JClassDef.java 0000664 0000000 0000000 00000005532 12500061542 0025565 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A type definition, which can be a class, interface, annotation type, etc.
*
* @author David M. Lloyd
*/
public interface JClassDef extends JAnnotatable, JDocCommentable, JGenericDef, JClassDefSection {
/**
* Add a blank line at this point of the type.
*
* @return this type definition
*/
JClassDef blankLine();
/**
* Add an {@code extends} type to this type.
*
* @param name the type name
* @return this type definition
*/
JClassDef _extends(String name);
/**
* Add an {@code extends} type to this type.
*
* @param type the type
* @return this type definition
*/
JClassDef _extends(JType type);
/**
* Add an {@code extends} type to this type.
*
* @param clazz the type
* @return this type definition
*/
JClassDef _extends(Class> clazz);
/**
* Add one or more {@code implements} type(s) to this type.
*
* @param name the type name
* @return this type definition
*/
JClassDef _implements(String... name);
/**
* Add one or more {@code implements} type(s) to this type.
*
* @param type the type
* @return this type definition
*/
JClassDef _implements(JType... type);
/**
* Add one or more {@code implements} type(s) to this type.
*
* @param clazz the type
* @return this type definition
*/
JClassDef _implements(Class>... clazz);
/**
* Get the erased type corresponding to this type definition.
*
* @return the erased type
*/
JType erasedType();
/**
* Get a generic type for this type definition, where the type arguments are the same as the type parameters of this
* type (as defined at the time this method is called).
*
* @return the generic type
*/
JType genericType();
/**
* Add an enum constant. If the class being defined is not an enum, an exception is thrown.
*
* @param name the constant name
* @return the call for enum construction
*/
JEnumConstant _enum(String name);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JClassDefSection.java 0000664 0000000 0000000 00000012225 12500061542 0027107 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2015 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A section of a class definition, to which members, comments, and blank lines may be added.
*
* @author David M. Lloyd
*/
public interface JClassDefSection extends JCommentable {
/**
* Create a section at this point, into which additional items may be added.
*
* @return the new section to add
*/
JClassDefSection section();
/**
* Add a blank line at this point of the type.
*
* @return this type definition
*/
JClassDefSection blankLine();
/**
* Add a "raw" initialization block to this type definition.
*
* @return the initialization block
*/
JBlock init();
/**
* Add a static initialization block to this type definition.
*
* @return the static initialization block
*/
JBlock staticInit();
/**
* Add a field to this type.
*
* @param mods the modifiers
* @param type the field type
* @param name the field name
* @return the field declaration
*/
JVarDeclaration field(int mods, JType type, String name);
/**
* Add a field to this type.
*
* @param mods the modifiers
* @param type the field type
* @param name the field name
* @param init the field assigned value
* @return the field declaration
*/
JVarDeclaration field(int mods, JType type, String name, JExpr init);
/**
* Add a field to this type.
*
* @param mods the modifiers
* @param type the field type
* @param name the field name
* @return the field declaration
*/
JVarDeclaration field(int mods, Class> type, String name);
/**
* Add a field to this type.
*
* @param mods the modifiers
* @param type the field type
* @param name the field name
* @param init the field assigned value
* @return the field declaration
*/
JVarDeclaration field(int mods, Class> type, String name, JExpr init);
/**
* Add a field to this type.
*
* @param mods the modifiers
* @param type the field type
* @param name the field name
* @return the field declaration
*/
JVarDeclaration field(int mods, String type, String name);
/**
* Add a field to this type.
*
* @param mods the modifiers
* @param type the field type
* @param name the field name
* @param init the field assigned value
* @return the field declaration
*/
JVarDeclaration field(int mods, String type, String name, JExpr init);
/**
* Add a method to this type.
*
* @param mods the modifiers
* @param returnType the method return type
* @param name the method name
* @return the method definition
*/
JMethodDef method(int mods, JType returnType, String name);
/**
* Add a method to this type.
*
* @param mods the modifiers
* @param returnType the method return type
* @param name the method name
* @return the method definition
*/
JMethodDef method(int mods, Class> returnType, String name);
/**
* Add a method to this type.
*
* @param mods the modifiers
* @param returnType the method return type
* @param name the method name
* @return the method definition
*/
JMethodDef method(int mods, String returnType, String name);
/**
* Add a constructor to this type.
*
* @param mods the modifiers
* @return the constructor definition
*/
JMethodDef constructor(int mods);
/**
* Add a nested class to this type.
*
* @param mods the class modifiers
* @param name the class name
* @return the nested class
*/
JClassDef _class(int mods, String name);
/**
* Add a nested enum to this type.
*
* @param mods the enum modifiers
* @param name the enum name
* @return the nested enum
*/
JClassDef _enum(int mods, String name);
/**
* Add a nested interface to this type.
*
* @param mods the interface modifiers
* @param name the interface name
* @return the nested interface
*/
JClassDef _interface(int mods, String name);
/**
* Add a nested annotation interface to this type.
*
* @param mods the annotation interface modifiers
* @param name the annotation interface name
* @return the nested annotation interface
*/
JClassDef annotationInterface(int mods, String name);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JClassDefSectionImpl.java 0000664 0000000 0000000 00000010400 12500061542 0027722 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2015 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
/**
* @author David M. Lloyd
*/
class JClassDefSectionImpl implements JClassDefSection, ClassContent {
private final Sectionable sectionable;
private final ArrayList content = new ArrayList<>();
JClassDefSectionImpl(final Sectionable sectionable) {
this.sectionable = sectionable;
}
C add(C item) {
content.add(item);
return item;
}
public JClassDefSection section() {
return add(new JClassDefSectionImpl(sectionable));
}
public JClassDefSection blankLine() {
add(BlankLine.getInstance());
return this;
}
public JBlock init() {
return sectionable.init(content);
}
public JBlock staticInit() {
return sectionable.staticInit(content);
}
public JVarDeclaration field(final int mods, final JType type, final String name) {
return sectionable.field(content, mods, type, name, null);
}
public JVarDeclaration field(final int mods, final JType type, final String name, final JExpr init) {
return sectionable.field(content, mods, type, name, init);
}
public JVarDeclaration field(final int mods, final Class> type, final String name) {
return field(mods, JTypes.typeOf(type), name);
}
public JVarDeclaration field(final int mods, final Class> type, final String name, final JExpr init) {
return field(mods, JTypes.typeOf(type), name, init);
}
public JVarDeclaration field(final int mods, final String type, final String name) {
return field(mods, JTypes.typeNamed(type), name);
}
public JVarDeclaration field(final int mods, final String type, final String name, final JExpr init) {
return field(mods, JTypes.typeNamed(type), name, init);
}
public JMethodDef method(final int mods, final JType returnType, final String name) {
return sectionable.method(content, mods, returnType, name);
}
public JMethodDef method(final int mods, final Class> returnType, final String name) {
return method(mods, JTypes.typeOf(returnType), name);
}
public JMethodDef method(final int mods, final String returnType, final String name) {
return method(mods, JTypes.typeNamed(returnType), name);
}
public JMethodDef constructor(final int mods) {
return sectionable.constructor(content, mods);
}
public JClassDef _class(final int mods, final String name) {
return sectionable._class(content, mods, name);
}
public JClassDef _enum(final int mods, final String name) {
return sectionable._enum(content, mods, name);
}
public JClassDef _interface(final int mods, final String name) {
return sectionable._interface(content, mods, name);
}
public JClassDef annotationInterface(final int mods, final String name) {
return sectionable.annotationInterface(content, mods, name);
}
public JComment lineComment() {
return add(new LineJComment());
}
public JComment blockComment() {
return add(new BlockJComment());
}
public void write(final SourceFileWriter writer) throws IOException {
Iterator iterator = content.iterator();
if (iterator.hasNext()) {
iterator.next().write(writer);
while (iterator.hasNext()) {
writer.nl();
iterator.next().write(writer);
}
}
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JClassItem.java 0000664 0000000 0000000 00000020752 12500061542 0025766 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2015 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static java.lang.Integer.signum;
import java.util.Comparator;
import java.util.EnumSet;
/**
* An item contained within a class.
*
* @author David M. Lloyd
*/
public interface JClassItem {
/**
* Get the kind of item.
*
* @return the item kind
*/
Kind getItemKind();
/**
* Get the modifiers of this item.
*
* @return the modifiers
* @see JMod
*/
int getModifiers();
/**
* Determine whether this item has all of the modifiers specified by the given bitwise-OR-joined argument.
*
* @param mods the modifier(s)
* @return {@code true} if all of the modifiers are present, {@code false} otherwise
*/
boolean hasAllModifiers(int mods);
/**
* Determine whether this item has any of the modifiers specified by the given bitwise-OR-joined argument.
*
* @param mods the modifier(s)
* @return {@code true} if any if the modifiers are present, {@code false} otherwise
*/
boolean hasAnyModifier(int mods);
/**
* Get the name of this element, if there is one.
*
* @return the name, or {@code null} if there is none
*/
String getName();
Comparator SMART_NAME_SORT = new Comparator() {
private int rankOf(JClassItem item) {
return item.getItemKind().ordinal();
}
public int compare(final JClassItem o1, final JClassItem o2) {
int r1, r2;
r1 = rankOf(o1);
r2 = rankOf(o2);
if (r1 != r2) return signum(r2 - r1);
String n1, n2;
n1 = o1.getName();
n2 = o2.getName();
if (o1.getItemKind() == Kind.METHOD) {
boolean s1 = o1.hasAllModifiers(JMod.STATIC);
boolean s2 = o2.hasAllModifiers(JMod.STATIC);
if (s1 != s2) {
return s1 ? -1 : 1;
}
String p1, p2;
int v1, v2;
boolean f1 = true, f2 = true;
if (n1.startsWith("get")) {
v1 = 0;
p1 = n1.substring(3);
} else if (n1.startsWith("is")) {
v1 = 0;
p1 = n1.substring(2);
} else if (n1.startsWith("set")) {
v1 = 1;
p1 = n1.substring(3);
} else {
f1 = false;
v1 = 0;
p1 = n1;
}
if (n2.startsWith("get")) {
v2 = 0;
p2 = n2.substring(3);
} else if (n2.startsWith("is")) {
v2 = 0;
p2 = n2.substring(2);
} else if (n2.startsWith("set")) {
v2 = 2;
p2 = n2.substring(3);
} else {
f2 = false;
v2 = 0;
p2 = n2;
}
if (f1 != f2) {
return f1 ? -1 : 1;
}
int m = p1.compareTo(p2);
return m != 0 ? m : signum(v2 - v1);
} else if (o1.getItemKind() == Kind.FIELD) {
boolean s1 = o1.hasAllModifiers(JMod.STATIC);
boolean s2 = o2.hasAllModifiers(JMod.STATIC);
return s1 != s2 ? s1 ? -1 : 1 : n1.compareTo(n2);
}
if (n1 != null && n2 != null) {
return n1.compareTo(n2);
}
return 0;
}
};
/**
* The kind of class item.
*/
enum Kind {
/**
* A line comment. The item will implement {@link JComment}.
*/
LINE_COMMENT,
/**
* A block comment. The item will implement {@link JComment}.
*/
BLOCK_COMMENT,
/**
* A blank line.
*/
BLANK_LINE,
/**
* An enum constant. The item will implement {@link JEnumConstant}.
*/
ENUM_CONSTANT,
/**
* A field. The item will implement {@link JVarDeclaration}.
*/
FIELD,
/**
* An initialization block. The item will implement {@link JBlock}. The block may be static; examine
* the modifiers to make this determination.
*/
INIT_BLOCK,
/**
* A constructor. The item will implement {@link JMethodDef}.
*/
CONSTRUCTOR,
/**
* A constructor. The item will implement {@link JMethodDef}.
*/
METHOD,
/**
* A nested enum. The item will implement {@link JClassDef}.
*/
ENUM,
/**
* A nested annotation interface. The item will implement {@link JClassDef}.
*/
ANNOTATION_INTERFACE,
/**
* A nested interface. The item will implement {@link JClassDef}.
*/
INTERFACE,
/**
* A nested class. The item will implement {@link JClassDef}.
*/
CLASS,
;
private static final int fullSize = Kind.values().length;
/**
* Determine whether the given set is fully populated (or "full"), meaning it contains all possible values.
*
* @param set the set
*
* @return {@code true} if the set is full, {@code false} otherwise
*/
public static boolean isFull(final EnumSet set) {
return set != null && set.size() == fullSize;
}
/**
* Determine whether this instance is equal to one of the given instances.
*
* @param v1 the first instance
*
* @return {@code true} if one of the instances matches this one, {@code false} otherwise
*/
public boolean in(final Kind v1) {
return this == v1;
}
/**
* Determine whether this instance is equal to one of the given instances.
*
* @param v1 the first instance
* @param v2 the second instance
*
* @return {@code true} if one of the instances matches this one, {@code false} otherwise
*/
public boolean in(final Kind v1, final Kind v2) {
return this == v1 || this == v2;
}
/**
* Determine whether this instance is equal to one of the given instances.
*
* @param v1 the first instance
* @param v2 the second instance
* @param v3 the third instance
*
* @return {@code true} if one of the instances matches this one, {@code false} otherwise
*/
public boolean in(final Kind v1, final Kind v2, final Kind v3) {
return this == v1 || this == v2 || this == v3;
}
/**
* Determine whether this instance is equal to one of the given instances.
*
* @param v1 the first instance
* @param v2 the second instance
* @param v3 the third instance
* @param v4 the fourth instance
*
* @return {@code true} if one of the instances matches this one, {@code false} otherwise
*/
public boolean in(final Kind v1, final Kind v2, final Kind v3, final Kind v4) {
return this == v1 || this == v2 || this == v3 || this == v4;
}
/**
* Determine whether this instance is equal to one of the given instances.
*
* @param values the possible values
*
* @return {@code true} if one of the instances matches this one, {@code false} otherwise
*/
public boolean in(final Kind... values) {
if (values != null) for (Kind value : values) {
if (this == value) return true;
}
return false;
}
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JComment.java 0000664 0000000 0000000 00000011127 12500061542 0025500 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A source comment or tag body.
*
* @author David M. Lloyd
*/
public interface JComment {
/**
* Add some text to the end of this comment. No formatting or line breaks are inserted.
*
* @param text the text to add
* @return this comment
*/
JComment text(String text);
/**
* Add a non-trailing space. If no content follows, the space will be omitted.
*
* @return this comment
*/
JComment sp();
/**
* Add a newline.
*
* @return this comment
*/
JComment nl();
/**
* Add a type name to the end of this comment. If the type is imported, it will emit as a simple name, otherwise
* it will emit as a qualified name.
*
* @param type the type name to add
* @return this comment
*/
JComment typeName(JType type);
/**
* Add a comment sub-block at this location. The block has no visual representation but allows text to be inserted
* at the point of the block even after more content was appended after it.
*
* @return the comment sub-block
*/
JComment block();
/**
* Add an inline doc tag with simple content.
*
* @param tag the tag name (without the leading {@code @} sign)
* @param body the complete tag body
* @return this comment
*/
JComment inlineDocTag(String tag, String body);
/**
* Add an inline doc tag.
*
* @param tag the tag name (without the leading {@code @} sign)
* @return the body of the doc tag
*/
JComment inlineDocTag(String tag);
/**
* Add an inline code tag.
*
* @return the code tag content
*/
JComment code();
/**
* Add the {@code {@docRoot}} tag at this position.
*
* @return this comment
*/
JComment docRoot();
/**
* Add an inline {@code @link} to a type.
*
* @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font
* @param targetType the target type to link to
* @return the body of the link tag
*/
JComment linkType(boolean plain, JType targetType);
/**
* Add an inline {@code @link} to a field of a type.
*
* @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font
* @param targetType the target type to link to
* @param targetField the target field to link to
* @return the body of the link tag
*/
JComment linkField(boolean plain, JType targetType, String targetField);
/**
* Add an inline {@code @link} to a constructor.
*
* @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font
* @param targetType the target type to link to
* @param targetConstructorArgumentTypes the argument types of the constructor to link to
* @return the body of the link tag
*/
JComment linkConstructor(boolean plain, JType targetType, JType... targetConstructorArgumentTypes);
/**
* Add an inline {@code @link} to a method.
*
* @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font
* @param targetType the target type to link to
* @param targetMethod the name of the method to link to
* @param targetMethodArgumentTypes the argument types of the method to link to
* @return the body of the link tag
*/
JComment linkMethod(boolean plain, JType targetType, String targetMethod, JType... targetMethodArgumentTypes);
/**
* Add an inline {@code @link} to a method.
*
* @param plain {@code true} to render in plain font, {@code false} to render in {@code monospace} font
* @param methodDef the method to link to
* @return the body of the link tag
*/
JComment linkMethod(boolean plain, JMethodDef methodDef);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JCommentable.java 0000664 0000000 0000000 00000002175 12500061542 0026327 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A program element which can have comments attached to it.
*
* @author David M. Lloyd
*/
public interface JCommentable {
/**
* Add a line comment.
*
* @return the line comment body
*/
JComment lineComment();
/**
* Add a block comment.
*
* @return the block comment body
*/
JComment blockComment();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JDeparser.java 0000664 0000000 0000000 00000003434 12500061542 0025645 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* The main entry point for this library. Use this class to construct a collection of source files which can be
* generated and stored.
*
* @author David M. Lloyd
*/
public final class JDeparser {
private JDeparser() {
}
/**
* Create a new source generation collection.
*
* @param filer the filer to use to store generated sources
* @param format the formatting preferences to use for these sources
* @return the source collection
*/
public static JSources createSources(final JFiler filer, final FormatPreferences format) {
return new ImplJSources(filer, format);
}
/**
* Drop all thread-local caches. This can be done to save memory or avoid GC problems after source generation
* has been completed. Call within a {@code finally} block to ensure that resources are released regardless of
* the outcome of intervening operations.
*/
public static void dropCaches() {
JExprs.cache.remove();
JTypes.cache.remove();
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JDocComment.java 0000664 0000000 0000000 00000004515 12500061542 0026131 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A JavaDoc comment.
*
* @author David M. Lloyd
*/
public interface JDocComment extends JHtmlComment {
/** {@inheritDoc} */
JDocComment text(String text);
/** {@inheritDoc} */
JDocComment block();
/** {@inheritDoc} */
JDocComment inlineDocTag(String tag, String body);
/** {@inheritDoc} */
JComment inlineDocTag(String tag);
/** {@inheritDoc} */
JDocComment sp();
/** {@inheritDoc} */
JDocComment nl();
/** {@inheritDoc} */
JDocComment p();
/** {@inheritDoc} */
JDocComment br();
/** {@inheritDoc} */
JDocComment typeName(JType type);
/** {@inheritDoc} */
JDocComment docRoot();
/** {@inheritDoc} */
JDocComment value(JType type, String fieldName);
/**
* Add a block tag.
*
* @param tag the tag name
* @return the block tag comment block
*/
JHtmlComment docTag(String tag);
/**
* Add a block tag.
*
* @param tag the tag name
* @param firstWord the tag body first word
* @return the block tag comment block
*/
JHtmlComment docTag(String tag, String firstWord);
/**
* Add a {@code @return} tag.
*
* @return the tag body
*/
JHtmlComment _return();
/**
* Add a {@code @throws} tag.
*
* @param exceptionType the type of exception
* @return the tag body
*/
JHtmlComment _throws(JType exceptionType);
/**
* Add a {@code @param} tag.
*
* @param name the parameter name
* @return the tag body
*/
JHtmlComment param(String name);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JDocCommentable.java 0000664 0000000 0000000 00000002325 12500061542 0026752 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A program element which can have a documentation tag associated with it.
*
* @author David M. Lloyd
*/
public interface JDocCommentable extends JCommentable {
/**
* Get or create the doc comment for this element.
*
* @return the doc comment body
*/
JDocComment docComment();
/**
* Mark this program element as deprecated.
*
* @return the deprecation tag body
*/
JComment deprecated();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JEnumConstant.java 0000664 0000000 0000000 00000002200 12500061542 0026504 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* An enum constant definition.
*
* @author David M. Lloyd
*/
public interface JEnumConstant extends JSimpleArgs, JAnnotatable, JDocCommentable {
/** {@inheritDoc} */
JEnumConstant arg(JExpr expr);
/**
* Add an implementation body to this enum constant.
*
* @return the implementation class definition
*/
JClassDef body();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JExpr.java 0000664 0000000 0000000 00000025064 12500061542 0025021 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
/**
* A modelled expression. Constructed complex expressions are reusable (their contents will be copied at every
* use site). The minimum number of parentheses will automatically be added as needed. For convenience methods to
* construct common expressions, also see the {@link JExprs} class.
*
* @author David M. Lloyd
*/
public interface JExpr {
/**
* The constant expression for {@code false}.
*/
JExpr FALSE = new BooleanJExpr(false);
/**
* The constant expression for {@code true}.
*/
JExpr TRUE = new BooleanJExpr(true);
/**
* The constant expression for {@code this}.
*/
JExpr THIS = new KeywordJExpr($KW.THIS);
/**
* The constant expression for {@code null}.
*/
JExpr NULL = new KeywordJExpr($KW.NULL);
/**
* The constant expression for the integer zero.
*/
JExpr ZERO = new IntegerJExpr(0, 10);
/**
* The constant expression for the integer one.
*/
JExpr ONE = new IntegerJExpr(1, 10);
// arithmetic
/**
* Combine this expression with another using the binary {@code +} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr plus(JExpr e1);
/**
* Combine this expression with another using the binary {@code -} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr minus(JExpr e1);
/**
* Combine this expression with another using the binary {@code *} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr times(JExpr e1);
/**
* Combine this expression with another using the binary {@code /} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr div(JExpr e1);
/**
* Combine this expression with another using the binary {@code %} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr mod(JExpr e1);
/**
* Negate this expression using the unary {@code -} operator.
*
* @return the new expression
*/
JExpr neg();
// bitwise
/**
* Combine this expression with another using the binary {@code &} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr band(JExpr e1);
/**
* Combine this expression with another using the binary {@code |} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr bor(JExpr e1);
/**
* Combine this expression with another using the binary {@code ^} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr bxor(JExpr e1);
/**
* Combine this expression with another using the binary {@code >>} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr shr(JExpr e1);
/**
* Combine this expression with another using the binary {@code >>>} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr lshr(JExpr e1);
/**
* Combine this expression with another using the binary {@code <<} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr shl(JExpr e1);
/**
* Invert this expression using the unary {@code ~} operator.
*
* @return the new expression
*/
JExpr comp();
// logic
/**
* Combine this expression with another using the binary {@code &&} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr and(JExpr e1);
/**
* Combine this expression with another using the binary {@code ||} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr or(JExpr e1);
/**
* Invert this expression using the unary {@code !} operator.
*
* @return the new expression
*/
JExpr not();
// equality
/**
* Combine this expression with another using the binary {@code ==} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr eq(JExpr e1);
/**
* Combine this expression with another using the binary {@code !=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr ne(JExpr e1);
// range
/**
* Combine this expression with another using the binary {@code <} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr lt(JExpr e1);
/**
* Combine this expression with another using the binary {@code >} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr gt(JExpr e1);
/**
* Combine this expression with another using the binary {@code <=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr le(JExpr e1);
/**
* Combine this expression with another using the binary {@code >=} operator.
*
* @param e1 the other expression
* @return the combined expression
*/
JExpr ge(JExpr e1);
// ternary
/**
* Combine this expression with two others using the ternary {@code ? :} operator.
*
* @param ifTrue the {@code true} expression branch
* @param ifFalse the {@code false} expression branch
* @return the combined expression
*/
JExpr cond(JExpr ifTrue, JExpr ifFalse);
// paren
/**
* Explicitly wrap this expression in parentheses.
*
* @return the wrapped expression
*/
JExpr paren();
// instance
/**
* Get a type-testing expression using the {@code instanceof} operator.
*
* @param type the type to test
* @return the expression
*/
JExpr _instanceof(String type);
/**
* Get a type-testing expression using the {@code instanceof} operator.
*
* @param type the type to test
* @return the expression
*/
JExpr _instanceof(JType type);
/**
* Get a type-testing expression using the {@code instanceof} operator.
*
* @param type the type to test
* @return the expression
*/
JExpr _instanceof(Class> type);
// cast
/**
* Get an expression which is a cast of this expression to the given type.
*
* @param type the type to cast to
* @return the expression
*/
JExpr cast(String type);
/**
* Get an expression which is a cast of this expression to the given type.
*
* @param type the type to cast to
* @return the expression
*/
JExpr cast(JType type);
/**
* Get an expression which is a cast of this expression to the given type.
*
* @param type the type to cast to
* @return the expression
*/
JExpr cast(Class> type);
// invoke
/**
* Call the given method on this expression.
*
* @param name the method name
* @return the method call
*/
JCall call(String name);
// construct inner
/**
* Get an expression to construct a new inner class instance of this instance expression.
*
* @param type the inner class type to construct
* @return the {@code new} constructor call
*/
JCall _new(String type);
/**
* Get an expression to construct a new inner class instance of this instance expression.
*
* @param type the inner class type to construct
* @return the {@code new} constructor call
*/
JCall _new(JType type);
/**
* Get an expression to construct a new inner class instance of this instance expression.
*
* @param type the inner class type to construct
* @return the {@code new} constructor call
*/
JCall _new(Class> type);
/**
* Construct a new anonymous subclass of the given type, which must be an inner class of the type of this
* expression.
*
* @param type the type of object to construct
* @return the anonymous subclass definition
*/
JAnonymousClassDef _newAnon(String type);
/**
* Construct a new anonymous subclass of the given type, which must be an inner class of the type of this
* expression.
*
* @param type the type of object to construct
* @return the anonymous subclass definition
*/
JAnonymousClassDef _newAnon(JType type);
/**
* Construct a new anonymous subclass of the given type, which must be an inner class of the type of this
* expression.
*
* @param type the type of object to construct
* @return the anonymous subclass definition
*/
JAnonymousClassDef _newAnon(Class> type);
// field
/**
* Get a field of this object instance.
*
* @param name the field name
* @return the expression
*/
JAssignableExpr field(String name);
/**
* Get a field of this object instance (shorthand for {@link #field(String)}.
*
* @param name the field name
* @return the expression
*/
JAssignableExpr $v(String name);
// array
/**
* Get an element of this array expression.
*
* @param idx the array index expression
* @return the array dereference expression
*/
JAssignableExpr idx(JExpr idx);
/**
* Get an element of this array expression.
*
* @param idx the array index
* @return the array dereference expression
*/
JExpr idx(int idx);
/**
* Get the {@code length} expression of this array expression.
*
* @return the {@code length} expression
*/
JExpr length();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JExprs.java 0000664 0000000 0000000 00000023073 12500061542 0025202 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.util.LinkedHashMap;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
/**
* The factory for generating simple expressions.
*/
public final class JExprs {
private JExprs() {}
/**
* Generate an {@code int} value in decimal base.
*
* @param val the value
* @return the value expression
*/
public static JExpr decimal(int val) {
return new IntegerJExpr(val, 10);
}
/**
* Generate a {@code long} value in decimal base.
*
* @param val the value
* @return the value expression
*/
public static JExpr decimal(long val) {
return new LongJExpr(val, 10);
}
/**
* Generate a {@code float} value in decimal base.
*
* @param val the value
* @return the value expression
*/
public static JExpr decimal(float val) {
return new DecimalFloatJExpr(val);
}
/**
* Generate a {@code double} value in decimal base.
*
* @param val the value
* @return the value expression
*/
public static JExpr decimal(double val) {
return new DecimalDoubleJExpr(val);
}
/**
* Generate an {@code int} value in hexadecimal base.
*
* @param val the value
* @return the value expression
*/
public static JExpr hex(int val) {
return new IntegerJExpr(val, 16);
}
/**
* Generate a {@code long} value in hexadecimal base.
*
* @param val the value
* @return the value expression
*/
public static JExpr hex(long val) {
return new LongJExpr(val, 16);
}
/**
* Generate a {@code float} value in hexadecimal base.
*
* @param val the value
* @return the value expression
*/
public static JExpr hex(float val) {
return new HexFloatJExpr(val);
}
/**
* Generate a {@code double} value in hexadecimal base.
*
* @param val the value
* @return the value expression
*/
public static JExpr hex(double val) {
return new HexDoubleJExpr(val);
}
/**
* Generate an {@code int} value in binary base.
*
* @param val the value
* @return the value expression
*/
public static JExpr binary(int val) {
return new IntegerJExpr(val, 2);
}
/**
* Generate a {@code long} value in binary base.
*
* @param val the value
* @return the value expression
*/
public static JExpr binary(long val) {
return new LongJExpr(val, 2);
}
/**
* Generate a string constant value.
*
* @param string the string
* @return the string expression
*/
public static JExpr str(String string) {
return new StringJExpr(string);
}
/**
* Generate a {@code char} value constant.
*
* @param val the value
* @return the value expression
*/
public static JExpr ch(int val) {
return new CharJExpr(val);
}
/**
* Generate a method call expression to the given element.
*
* @param element the method to call
* @return the method call
*/
public static JCall call(final ExecutableElement element) {
final ElementKind kind = element.getKind();
if (kind == ElementKind.METHOD) {
final String name = element.getSimpleName().toString();
return call(name);
}
throw new IllegalArgumentException("Unsupported element for call: " + element);
}
/**
* Generate a method call expression to the given method name.
*
* @param name the name of the method to call
* @return the method call
*/
public static JCall call(String name) {
return new DirectJCall(name);
}
/**
* Generate a method call expression to a method on the given static type.
*
* @param type the type to call against
* @param name the name of the method to call
* @return the method call
*/
public static JCall callStatic(final String type, final String name) {
return callStatic(JTypes.typeNamed(type), name);
}
/**
* Generate a method call expression to a method on the given static type.
*
* @param type the type to call against
* @param name the name of the method to call
* @return the method call
*/
public static JCall callStatic(final JType type, final String name) {
return new StaticJCall(type, name);
}
/**
* Generate a method call expression to a method on the given static type.
*
* @param type the type to call against
* @param name the name of the method to call
* @return the method call
*/
public static JCall callStatic(final Class> type, final String name) {
return callStatic(JTypes.typeOf(type), name);
}
/**
* Return a name expression. This method is a shortcut for {@link #name(String)}.
*
* @param name the name
* @return the expression
*/
public static JAssignableExpr $v(String name) {
return name(name);
}
/**
* Return a name expression from an annotation processor parameter declaration.
*
* @param paramDeclaration the method parameter
* @return the expression
*/
public static JAssignableExpr $v(JParamDeclaration paramDeclaration) {
return name(paramDeclaration.name());
}
/**
* Return a name expression from an annotation processor variable declaration.
*
* @param varDeclaration the variable declaration
* @return the expression
*/
public static JAssignableExpr $v(JVarDeclaration varDeclaration) {
return name(varDeclaration.name());
}
static final ThreadLocal> cache = new CachingThreadLocal<>();
/**
* Return a name expression.
*
* @param name the name
* @return the expression
*/
public static JAssignableExpr name(String name) {
final LinkedHashMap map = cache.get();
JAssignableExpr ret = map.get(name);
if (ret == null) {
map.put(name, ret = new NameJExpr(name));
}
return ret;
}
/**
* Return a name expression from an annotation processor parameter declaration.
*
* @param paramDeclaration the method parameter
* @return the expression
*/
public static JAssignableExpr name(JParamDeclaration paramDeclaration) {
return name(paramDeclaration.name());
}
/**
* Return a name expression from an annotation processor variable declaration.
*
* @param varDeclaration the variable declaration
* @return the expression
*/
public static JAssignableExpr name(JVarDeclaration varDeclaration) {
return name(varDeclaration.name());
}
/**
* Return a new array expression. The array is initially empty.
*
* @return an array expression
*/
public static JArrayExpr array() {
return new PlainJArrayExpr();
}
/**
* Return a new array expression. The array is initially filled with the given members.
*
* @param members the initial members of the array
* @return an array expression
*/
public static JArrayExpr array(JExpr... members) {
return new PlainJArrayExpr(members);
}
/**
* Return a new array expression. The array is initially filled with the given strings.
*
* @param members the initial members of the array
* @return an array expression
*/
public static JArrayExpr array(String... members) {
final JExpr[] exprs = new JExpr[members.length];
for (int i = 0; i < members.length; i++) {
exprs[i] = str(members[i]);
}
return new PlainJArrayExpr(exprs);
}
/**
* Return a new array expression. The array is initially filled with the given integers.
*
* @param members the initial members of the array
* @return an array expression
*/
public static JArrayExpr array(int... members) {
final JExpr[] exprs = new JExpr[members.length];
for (int i = 0; i < members.length; i++) {
exprs[i] = decimal(members[i]);
}
return new PlainJArrayExpr(exprs);
}
/**
* Return a new array expression. The array is initially filled with the given integers.
*
* @param members the initial members of the array
* @return an array expression
*/
public static JArrayExpr array(long... members) {
final JExpr[] exprs = new JExpr[members.length];
for (int i = 0; i < members.length; i++) {
exprs[i] = decimal(members[i]);
}
return new PlainJArrayExpr(exprs);
}
/**
* Return a lambda expression. The expression is initially empty.
*
* @return the lambda expression
*/
public static JLambda lambda() {
return new JLambdaImpl();
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JFiler.java 0000664 0000000 0000000 00000007442 12500061542 0025144 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import javax.annotation.processing.Filer;
/**
* A file manager for writing out source files.
*
* @author David M. Lloyd
*/
public abstract class JFiler {
/**
* Get an instance which uses an underlying {@link javax.annotation.processing.Filer}.
*
* @param filer the annotation processing filer
* @return the JDeparser filer
*/
public static JFiler newInstance(final Filer filer) {
return new JFiler() {
public OutputStream openStream(final String packageName, final String fileName) throws IOException {
// Create the FQCN
final StringBuilder sb = new StringBuilder(packageName);
if (sb.charAt(sb.length() -1) != '.') {
sb.append('.');
}
sb.append(fileName);
return filer.createSourceFile(sb).openOutputStream();
}
};
}
/**
* Get an instance which writes to the filesystem.
*
* @param target the target source path
* @return the JDeparser filer
*/
public static JFiler newInstance(final File target) {
return new JFiler() {
public OutputStream openStream(final String packageName, final String fileName) throws IOException {
final File dir = new File(target, packageName.replace('.', File.separatorChar));
dir.mkdirs();
return new FileOutputStream(new File(dir, fileName + ".java"));
}
};
}
/**
* Construct a new instance.
*/
protected JFiler() {
}
private String encoding = "utf-8";
/**
* Get the file encoding to use.
*
* @return the file encoding
*/
public String getEncoding() {
return encoding;
}
/**
* Set the file encoding to use.
*
* @param encoding the file encoding
*/
public void setEncoding(final String encoding) {
this.encoding = encoding;
}
/**
* Open an output stream for writing the given file.
*
* @param packageName the package name
* @param fileName the file name
* @return the output stream
* @throws IOException if an error occurs during write
*/
public abstract OutputStream openStream(String packageName, String fileName) throws IOException;
/**
* Open a writer for the given file. The default implementation calls {@link #openStream(String, String)} and wraps
* the result with an {@link OutputStreamWriter} using the configured file encoding.
*
* @param packageName the package name
* @param fileName the file name
* @return the writer
* @throws IOException if an error occurs during write
*/
public Writer openWriter(String packageName, String fileName) throws IOException {
return new OutputStreamWriter(openStream(packageName, fileName), encoding);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JFor.java 0000664 0000000 0000000 00000005001 12500061542 0024616 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A {@code for} loop.
*
* @author David M. Lloyd
*/
public interface JFor extends JBlock {
/**
* Add a loop initializer.
*
* @param mods the modifiers for the initializer variable declaration
* @param type the type of the initializer variables
* @param name the name of the first initializer variable
* @param value the initial value for the first initializer variable
* @return the initializer variable declaration
*/
JVarDeclaration init(int mods, String type, String name, JExpr value);
/**
* Add a loop initializer.
*
* @param mods the modifiers for the initializer variable declaration
* @param type the type of the initializer variables
* @param name the name of the first initializer variable
* @param value the initial value for the first initializer variable
* @return the initializer variable declaration
*/
JVarDeclaration init(int mods, JType type, String name, JExpr value);
/**
* Add a loop initializer.
*
* @param mods the modifiers for the initializer variable declaration
* @param type the type of the initializer variables
* @param name the name of the first initializer variable
* @param value the initial value for the first initializer variable
* @return the initializer variable declaration
*/
JVarDeclaration init(int mods, Class> type, String name, JExpr value);
/**
* Add a test expression.
*
* @param expr the test expression
* @return this {@code for} loop
*/
JFor test(JExpr expr);
/**
* Add an update expression.
*
* @param updateExpr the update expression
* @return this {@code for} loop
*/
JFor update(JExpr updateExpr);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JGenericDef.java 0000664 0000000 0000000 00000002331 12500061542 0026066 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A generic type or method definition.
*
* @author David M. Lloyd
*/
public interface JGenericDef {
/**
* Define a type parameter.
*
* @param name the type parameter name
* @return the type parameter definition
*/
JTypeParamDef typeParam(String name);
/**
* Get all the type parameters defined at the time of invocation.
*
* @return the type parameters
*/
JTypeParamDef[] typeParams();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JHtmlComment.java 0000664 0000000 0000000 00000004616 12500061542 0026332 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A comment that supports HTML content.
*
* @author David M. Lloyd
*/
public interface JHtmlComment extends JComment {
/** {@inheritDoc} */
JHtmlComment block();
/** {@inheritDoc} */
JHtmlComment text(String text);
/** {@inheritDoc} */
JHtmlComment inlineDocTag(String tag, String body);
/** {@inheritDoc} */
JHtmlComment sp();
/** {@inheritDoc} */
JHtmlComment nl();
/** {@inheritDoc} */
JHtmlComment typeName(JType type);
/** {@inheritDoc} */
JHtmlComment docRoot();
/**
* Add a paragraph separator.
*
* @return this HTML comment
*/
JHtmlComment p();
/**
* Add a line separator.
*
* @return this HTML comment
*/
JHtmlComment br();
/**
* Add a {@code @value} inline tag.
*
* @param type the value type
* @param fieldName the value field name
* @return this HTML comment
*/
JHtmlComment value(JType type, String fieldName);
/**
* Add an HTML link ({@code <a>} tag).
*
* @param url the URL to link to
* @return the link tag body
*/
JHtmlTag htmlLink(String url);
/**
* Add an HTML tag. The given tag should be a valid HTML 4 or 5 tag.
*
* @param tag the HTML tag
* @param newLine {@code true} to add a newline after the opening tag and before the closing tag
* @return the tag body
*/
JHtmlTag htmlTag(String tag, boolean newLine);
/**
* Add an inline {@code @code} tag within a {@code } block.
*
* @return the preformatted code block content
*/
JComment preformattedCode();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JHtmlTag.java 0000664 0000000 0000000 00000001674 12500061542 0025444 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* @author David M. Lloyd
*/
public interface JHtmlTag extends JHtmlComment {
JHtmlTag attribute(String name);
JHtmlTag attribute(String name, String value);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JIf.java 0000664 0000000 0000000 00000002322 12500061542 0024431 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* An {@code if} statement.
*
* @author David M. Lloyd
*/
public interface JIf extends JBlock {
/**
* Get the {@code else} condition block.
*
* @return the {@code else} block
*/
JBlock _else();
/**
* Add an {@code if} statement to the {@code else} block.
*
* @param cond the subsequent {@code if} condition
* @return the subsequent {@code if} statement
*/
JIf elseIf(JExpr cond);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JLabel.java 0000664 0000000 0000000 00000002110 12500061542 0025105 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A source label. Labels may be defined when created, or defined later on.
*
* @author David M. Lloyd
*/
public interface JLabel {
/**
* Get the label name. If the label is anonymous, or not defined yet, an exception is thrown.
*
* @return the label name
*/
String name();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JLambda.java 0000664 0000000 0000000 00000004246 12500061542 0025262 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2015 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A Java 8 lambda.
*
* @author David M. Lloyd
*/
public interface JLambda extends JExpr {
/**
* Add a declared-type parameter to this lambda.
*
* @param type the parameter type
* @param name the parameter name
* @return this lambda
*/
JLambda param(JType type, String name);
/**
* Add a declared-type parameter to this lambda.
*
* @param typeName the parameter type name
* @param name the parameter name
* @return this lambda
*/
JLambda param(String typeName, String name);
/**
* Add a declared-type parameter to this lambda.
*
* @param type the parameter type
* @param name the parameter name
* @return this lambda
*/
JLambda param(Class> type, String name);
/**
* Add an inferred-type parameter to this lambda. If one parameter is inferred, all will be, despite any declared
* parameter type.
*
* @param name the parameter name
* @return this lambda
*/
JLambda param(String name);
/**
* Get the lambda body as a block. Clears any expression body.
*
* @return the lambda body
*/
JBlock body();
/**
* Set the lambda body as an expression. Clears any block body or previously set expression body.
*
* @param expr the expression body of this lambda
* @return this lambda
*/
JLambda body(JExpr expr);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JLambdaImpl.java 0000664 0000000 0000000 00000010022 12500061542 0026071 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2015 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
/**
* @author David M. Lloyd
*/
class JLambdaImpl extends AbstractJExpr implements JLambda {
private BasicJBlock blockBody;
private AbstractJExpr exprBody;
private boolean hasInferred;
private ArrayList params;
JLambdaImpl() {
super(Prec.METHOD_CALL);
}
public JLambda param(final JType type, final String name) {
if (name != null) {
if (type == null) {
hasInferred = true;
}
if (params == null) {
params = new ArrayList<>();
}
params.add(new Param(type, name));
}
return this;
}
public JLambda param(final String typeName, final String name) {
return param(JTypes.typeNamed(typeName), name);
}
public JLambda param(final Class> type, final String name) {
return param(JTypes.typeOf(type), name);
}
public JLambda param(final String name) {
return param((JType) null, name);
}
public JBlock body() {
exprBody = null;
if (blockBody == null) {
blockBody = new BasicJBlock(null, JBlock.Braces.REQUIRED);
}
return blockBody;
}
public JLambda body(JExpr expression) {
blockBody = null;
exprBody = AbstractJExpr.of(expression);
return this;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write(Tokens.$PUNCT.PAREN.OPEN);
if (params == null) {
writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL_EMPTY);
} else {
writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL);
final Iterator iterator = params.iterator();
while (iterator.hasNext()) {
final Param param = iterator.next();
if (!hasInferred) {
writer.write(param.type);
writer.sp();
}
writer.writeEscaped(param.name);
if (iterator.hasNext()) {
writer.write(Tokens.$PUNCT.COMMA);
writer.write(FormatPreferences.Space.AFTER_COMMA);
}
}
writer.write(FormatPreferences.Space.WITHIN_PAREN_METHOD_CALL);
}
writer.write(Tokens.$PUNCT.PAREN.CLOSE);
writer.write(FormatPreferences.Space.AROUND_ARROW);
writer.write(Tokens.$PUNCT.BINOP.ARROW);
writer.write(FormatPreferences.Space.AROUND_ARROW);
if (exprBody != null) {
exprBody.write(writer);
} else if (blockBody != null) {
blockBody.write(writer, null);
} else {
writer.write(Tokens.$PUNCT.BRACE.OPEN);
writer.write(FormatPreferences.Space.WITHIN_BRACES_EMPTY);
writer.write(Tokens.$PUNCT.BRACE.CLOSE);
}
}
static class Param {
private final JType type;
private final String name;
public Param(final JType type, final String name) {
this.type = type;
this.name = name;
}
public JType getType() {
return type;
}
public String getName() {
return name;
}
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JMethodDef.java 0000664 0000000 0000000 00000012455 12500061542 0025742 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A method or constructor definition.
*
* @author David M. Lloyd
*/
public interface JMethodDef extends JGenericDef, JAnnotatable, JDocCommentable {
/**
* A default method body for a JDK 8+ interface method.
*
* @return the method body
*/
JBlock _default();
/**
* A default value for an annotation method.
*
* @param expr the value
* @return this method definition
*/
JMethodDef _default(JExpr expr);
/**
* Get the method body.
*
* @return the method body
*/
JBlock body();
/**
* Get the {@code @return} doc comment block.
*
* @return the comment block
*/
JComment returnsDoc();
/**
* Add a parameter to this method.
*
* @param mods the parameter modifiers
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration param(int mods, JType type, String name);
/**
* Add a parameter to this method.
*
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration param(JType type, String name);
/**
* Add a parameter to this method.
*
* @param mods the parameter modifiers
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration param(int mods, String type, String name);
/**
* Add a parameter to this method.
*
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration param(String type, String name);
/**
* Add a parameter to this method.
*
* @param mods the parameter modifiers
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration param(int mods, Class> type, String name);
/**
* Add a parameter to this method.
*
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration param(Class> type, String name);
/**
* Add a vararg parameter to this method.
*
* @param mods the parameter modifiers
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration varargParam(int mods, JType type, String name);
/**
* Add a vararg parameter to this method.
*
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration varargParam(JType type, String name);
/**
* Add a vararg parameter to this method.
*
* @param mods the parameter modifiers
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration varargParam(int mods, String type, String name);
/**
* Add a vararg parameter to this method.
*
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration varargParam(String type, String name);
/**
* Add a vararg parameter to this method.
*
* @param mods the parameter modifiers
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration varargParam(int mods, Class> type, String name);
/**
* Add a vararg parameter to this method.
*
* @param type the parameter type
* @param name the parameter name
* @return the parameter declaration
*/
JParamDeclaration varargParam(Class> type, String name);
/**
* Get the list of parameters defined thus far.
*
* @return the parameter list
*/
JParamDeclaration[] params();
/**
* Get a {@code @throws} doc comment block.
*
* @param type the exception type
* @return the doc comment block
*/
JComment _throws(String type);
/**
* Get a {@code @throws} doc comment block.
*
* @param type the exception type
* @return the doc comment block
*/
JComment _throws(JType type);
/**
* Get a {@code @throws} doc comment block.
*
* @param type the exception type
* @return the doc comment block
*/
JComment _throws(Class extends Throwable> type);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JMod.java 0000664 0000000 0000000 00000017422 12500061542 0024621 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static java.lang.Integer.bitCount;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
/**
* The set of modifiers for types and members.
*/
public final class JMod {
/**
* The {@code abstract} modifier.
*/
public static final int ABSTRACT = 1 << 0;
/**
* The {@code final} modifier.
*/
public static final int FINAL = 1 << 1;
/**
* The {@code native} modifier.
*/
public static final int NATIVE = 1 << 2;
/**
* The {@code private} modifier.
*/
public static final int PRIVATE = 1 << 3;
/**
* The {@code protected} modifier.
*/
public static final int PROTECTED = 1 << 4;
/**
* The {@code public} modifier.
*/
public static final int PUBLIC = 1 << 5;
/**
* The {@code static} modifier.
*/
public static final int STATIC = 1 << 6;
/**
* The {@code strictfp} modifier.
*/
public static final int STRICTFP = 1 << 7;
/**
* The {@code synchronized} modifier.
*/
public static final int SYNCHRONIZED= 1 << 8;
/**
* The {@code transient} modifier.
*/
public static final int TRANSIENT = 1 << 9;
/**
* The {@code volatile} modifier.
*/
public static final int VOLATILE = 1 << 10;
/**
* The {@code default} modifier found in Java 8 and later.
*/
public static final int DEFAULT = 1 << 11;
static final int PRIVATE_BITS = ~((1 << 12) - 1);
static final int INNER = 1 << 30;
static final int VARARGS = 1 << 31;
/**
* Test to see if exactly one modifier of the given set is present in the test value.
*
* @param set the set of modifiers to test against
* @param test the modifier set to test
* @return {@code true} if exactly one of {@code set} is present in {@code test}, {@code false} otherwise
*/
public static boolean oneIsSet(int set, int test) {
return bitCount(set & test) == 1;
}
/**
* Test to see if all modifiers in the given set are present in the test value.
*
* @param set the set of modifiers to test against
* @param test the modifier set to test
* @return {@code true} if all the modifiers in {@code set} are present in {@code test}, {@code false} otherwise
*/
public static boolean allAreSet(int set, int test) {
return (set & test) == test;
}
/**
* Test to see if all modifiers in the given set are absent in the test value.
*
* @param set the set of modifiers to test against
* @param test the modifier set to test
* @return {@code true} if all the modifiers in {@code set} are absent in {@code test}, {@code false} otherwise
*/
public static boolean allAreClear(int set, int test) {
return (set & test) == 0;
}
/**
* Test to see if any of the modifiers in the given set are present in the test value.
*
* @param set the set of modifiers to test against
* @param test the modifier set to test
* @return {@code true} if any of the modifiers in {@code set} are present in {@code test}, {@code false} otherwise
*/
public static boolean anyAreSet(int set, int test) {
return (set & test) != 0;
}
/**
* Test to see if any of the modifiers in the given set are absent in the test value.
*
* @param set the set of modifiers to test against
* @param test the modifier set to test
* @return {@code true} if any of the modifiers in {@code set} are absent in {@code test}, {@code false} otherwise
*/
public static boolean anyAreClear(int set, int test) {
return (set & test) != test;
}
/**
* Returns an integer which results in the appropriate modifier based on the element.
*
* @param element the element to check the modifiers on
*
* @return an integer representing the modifiers
*/
public static int of(final Element element) {
int result = 0;
for (Modifier modifier : element.getModifiers()) {
switch (modifier.name()) {
case "ABSTRACT": {
result = result | ABSTRACT;
break;
}
case "FINAL": {
result = result | FINAL;
break;
}
case "NATIVE": {
result = result | NATIVE;
break;
}
case "PRIVATE": {
result = result | PRIVATE;
break;
}
case "PROTECTED": {
result = result | PROTECTED;
break;
}
case "PUBLIC": {
result = result | PUBLIC;
break;
}
case "STATIC": {
result = result | STATIC;
break;
}
case "STRICTFP": {
result = result | STRICTFP;
break;
}
case "SYNCHRONIZED": {
result = result | SYNCHRONIZED;
break;
}
case "TRANSIENT": {
result = result | TRANSIENT;
break;
}
case "VOLATILE": {
result = result | VOLATILE;
break;
}
case "DEFAULT": {
result = result | DEFAULT;
break;
}
}
}
if (element instanceof ExecutableElement && ((ExecutableElement) element).isVarArgs()) {
result = result | VARARGS;
}
return result;
}
static void write(final SourceFileWriter writer, final int mods) throws IOException {
if (allAreSet(mods, PUBLIC)) {
writer.write($KW.PUBLIC);
}
if (allAreSet(mods, PROTECTED)) {
writer.write($KW.PROTECTED);
}
if (allAreSet(mods, PRIVATE)) {
writer.write($KW.PRIVATE);
}
if (allAreSet(mods, ABSTRACT)) {
writer.write($KW.ABSTRACT);
}
if (allAreSet(mods, STATIC)) {
writer.write($KW.STATIC);
}
if (allAreSet(mods, FINAL)) {
writer.write($KW.FINAL);
}
if (allAreSet(mods, TRANSIENT)) {
writer.write($KW.TRANSIENT);
}
if (allAreSet(mods, VOLATILE)) {
writer.write($KW.VOLATILE);
}
if (allAreSet(mods, SYNCHRONIZED)) {
writer.write($KW.SYNCHRONIZED);
}
if (allAreSet(mods, NATIVE)) {
writer.write($KW.NATIVE);
}
if (allAreSet(mods, STRICTFP)) {
writer.write($KW.STRICTFP);
}
if (allAreSet(mods, DEFAULT)) {
writer.write($KW.DEFAULT);
}
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JPackageInfoFile.java 0000664 0000000 0000000 00000001657 12500061542 0027054 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A {@code package-info.java} file definition.
*
* @author David M. Lloyd
*/
public interface JPackageInfoFile extends JDocCommentable, JAnnotatable {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JParamDeclaration.java 0000664 0000000 0000000 00000003037 12500061542 0027305 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A parameter declaration.
*
* @author David M. Lloyd
*/
public interface JParamDeclaration extends JAnnotatable {
/**
* Get the parameter type.
*
* @return the parameter type
*/
JType type();
/**
* Get the parameter name.
*
* @return the parameter name
*/
String name();
/**
* Get the parameter modifiers.
*
* @return the parameter modifiers
*/
int mods();
/**
* Determine whether the parameter is a vararg parameter.
*
* @return {@code true} if the parameter is vararg, {@code false} otherwise
*/
boolean varargs();
/**
* Get the {@code @param} JavaDoc block for this parameter.
*
* @return the comment block
*/
JComment doc();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JSimpleArgs.java 0000664 0000000 0000000 00000002243 12500061542 0026143 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A program element which supports simple arguments.
*
* @author David M. Lloyd
*/
public interface JSimpleArgs {
/**
* Add an argument.
*
* @param expr the argument expression
* @return this program element
*/
JSimpleArgs arg(JExpr expr);
/**
* Get the arguments defined thus far.
*
* @return the arguments
*/
JExpr[] arguments();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JSourceFile.java 0000664 0000000 0000000 00000006366 12500061542 0026147 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A source file.
*
* @author David M. Lloyd
*/
public interface JSourceFile extends JCommentable {
/**
* Add a type import to this source file.
*
* @param type the type to import
* @return this source file
*/
JSourceFile _import(String type);
/**
* Add a type import to this source file.
*
* @param type the type to import
* @return this source file
*/
JSourceFile _import(JType type);
/**
* Add a type import to this source file.
*
* @param type the type to import
* @return this source file
*/
JSourceFile _import(Class> type);
/**
* Add a static member import to this source file.
*
* @param type the type to import from
* @param member the member name
* @return this source file
*/
JSourceFile importStatic(String type, String member);
/**
* Add a static member import to this source file.
*
* @param type the type to import from
* @param member the member name
* @return this source file
*/
JSourceFile importStatic(JType type, String member);
/**
* Add a static member import to this source file.
*
* @param type the type to import from
* @param member the member name
* @return this source file
*/
JSourceFile importStatic(Class> type, String member);
/**
* Add a blank line to this source file. If sorting is enabled, blank lines may be lost.
*
* @return this source file
*/
JSourceFile blankLine();
/**
* Add a class definition to this source file.
*
* @param mods the modifiers
* @param name the class name
* @return the class definition
*/
JClassDef _class(int mods, String name);
/**
* Add an enum definition to this source file.
*
* @param mods the modifiers
* @param name the enum name
* @return the enum definition
*/
JClassDef _enum(int mods, String name);
/**
* Add an interface definition to this source file.
*
* @param mods the modifiers
* @param name the interface name
* @return the interface definition
*/
JClassDef _interface(int mods, String name);
/**
* Add an annotation interface definition to this source file.
*
* @param mods the modifiers
* @param name the annotation interface name
* @return the annotation interface definition
*/
JClassDef annotationInterface(int mods, String name);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JSources.java 0000664 0000000 0000000 00000003037 12500061542 0025522 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* A repository of source files.
*
* @author David M. Lloyd
*/
public interface JSources {
/**
* Create a source file.
*
* @param packageName the package name of the source file
* @param fileName the source file name (excluding {@code .java} suffix)
* @return the source file
*/
JSourceFile createSourceFile(String packageName, String fileName);
/**
* Create a {@code package-info.java} file.
*
* @param packageName the package name
* @return the source file
*/
JDocCommentable createPackageInfoFile(String packageName);
/**
* Write the source files.
*
* @throws IOException if a write operation fails
*/
void writeSources() throws IOException;
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JStatement.java 0000664 0000000 0000000 00000001605 12500061542 0026042 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A statement in a program.
*
* @author David M. Lloyd
*/
public interface JStatement extends JCommentable {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JSwitch.java 0000664 0000000 0000000 00000002544 12500061542 0025342 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A {@code switch} statement.
*
* @author David M. Lloyd
*/
public interface JSwitch extends JStatement {
/**
* Add a switch case.
*
* @param expr the case expression
* @return a sub-block for the case logic
*/
JBlock _case(JExpr expr);
/**
* Add a switch case for an {@code enum} constant.
*
* @param constName the constant name
* @return a sub-block for the case logic
*/
JBlock _case(String constName);
/**
* Add the default block.
*
* @return the default sub-block
*/
JBlock _default();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JTry.java 0000664 0000000 0000000 00000007203 12500061542 0024654 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A {@code try} block.
*
* @author David M. Lloyd
*/
public interface JTry extends JBlock {
/**
* Add a resource for {@code try}-with-resources constructs.
*
* @param mods the resource variable modifiers
* @param type the resource variable type
* @param var the resource variable name
* @param init the resource variable initialization value
* @return the variable declaration
*/
JVarDeclaration with(int mods, String type, String var, JExpr init);
/**
* Add a resource for {@code try}-with-resources constructs.
*
* @param mods the resource variable modifiers
* @param type the resource variable type
* @param var the resource variable name
* @param init the resource variable initialization value
* @return the variable declaration
*/
JVarDeclaration with(int mods, JType type, String var, JExpr init);
/**
* Add a resource for {@code try}-with-resources constructs.
*
* @param mods the resource variable modifiers
* @param type the resource variable type
* @param var the resource variable name
* @param init the resource variable initialization value
* @return the variable declaration
*/
JVarDeclaration with(int mods, Class extends AutoCloseable> type, String var, JExpr init);
/**
* Add a {@code catch} block.
*
* @param mods the catch block modifiers
* @param type the exception type
* @param var the exception variable name
* @return the {@code catch} sub-block
*/
JCatch _catch(int mods, String type, String var);
/**
* Add a {@code catch} block.
*
* @param mods the catch block modifiers
* @param type the exception type
* @param var the exception variable name
* @return the {@code catch} sub-block
*/
JCatch _catch(int mods, Class extends Throwable> type, String var);
/**
* Add a {@code catch} block.
*
* @param mods the catch block modifiers
* @param type the exception type
* @param var the exception variable name
* @return the {@code catch} sub-block
*/
JCatch _catch(int mods, JType type, String var);
/**
* Add a {@code catch} for an ignored exception.
*
* @param type the exception type
* @return this {@code try} block
*/
JTry ignore(String type);
/**
* Add a {@code catch} for an ignored exception.
*
* @param type the exception type
* @return this {@code try} block
*/
JTry ignore(Class extends Throwable> type);
/**
* Add a {@code catch} for an ignored exception.
*
* @param type the exception type
* @return this {@code try} block
*/
JTry ignore(JType type);
/**
* Add the {@code finally} block for this {@code try}.
*
* @return the {@code finally} sub-block
*/
JBlock _finally();
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JType.java 0000664 0000000 0000000 00000015771 12500061542 0025030 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import javax.lang.model.element.ExecutableElement;
/**
* A type specification. See also {@link JTypes}.
*
* @author David M. Lloyd
*/
public interface JType {
/**
* An empty array of types.
*/
JType[] NONE = new JType[0];
/**
* A special type that always renders to the type of the class it is encountered in.
*/
JType THIS = new ThisJType();
/**
* The {@code void} type.
*/
JType VOID = new PrimitiveJType("void", "Void");
/**
* The {@code boolean} primitive type.
*/
JType BOOLEAN = new PrimitiveJType("boolean", "Boolean");
/**
* The {@code float} primitive type.
*/
JType FLOAT = new PrimitiveJType("float", "Float");
/**
* The {@code double} primitive type.
*/
JType DOUBLE = new PrimitiveJType("double", "Double");
/**
* The {@code char} primitive type.
*/
JType CHAR = new PrimitiveJType("char", "Char");
/**
* The {@code byte} primitive type.
*/
JType BYTE = new PrimitiveJType("byte", "Byte");
/**
* The {@code short} primitive type.
*/
JType SHORT = new PrimitiveJType("short", "Short");
/**
* The {@code int} primitive type.
*/
JType INT = new PrimitiveJType("int", "Integer");
/**
* The {@code long} primitive type.
*/
JType LONG = new PrimitiveJType("long", "Long");
/**
* The type of {@code java.lang.Object}.
*/
JType OBJECT = new ReferenceJType("java.lang", "Object");
/**
* The wildcard type of {@code extends Object>}, also known as {@code >}.
*/
JType WILDCARD = OBJECT.wildcardExtends();
/**
* Get the simple name of this type.
*
* @return the type's simple name
*/
String simpleName();
/**
* An expression of the form {@code ThisType.class}.
*
* @return the expression
*/
JExpr _class();
/**
* An expression of the form {@code ThisType.this}. If the type is an array type, an exception is thrown.
*
* @return the expression
*/
JExpr _this();
/**
* An expression of the form {@code ThisType.super}. If the type is an array type, an exception is thrown.
*
* @return the expression
*/
JExpr _super();
/**
* An array of this type.
*
* @return the array type
*/
JType array();
/**
* Construct a new instance of this non-array type. If the type is an array type, an exception is thrown.
*
* @return the construction call
*/
JCall _new();
/**
* Construct a new instance of this array type. If the type is not an array type, an exception is thrown.
*
* @param dim the array size
* @return the construction call
*/
JExpr _new(JExpr dim);
/**
* Construct a new instance of this array type. If the type is not an array type, an exception is thrown.
*
* @param dim the array size
* @return the construction call
*/
JExpr _new(int dim);
/**
* Create a new array of this type which is inline-initialized.
*
* @return the array, initially with zero elements
*/
JArrayExpr _newArray();
/**
* Construct a new anonymous subclass of this type.
*
* @return the anonymous subclass definition
*/
JAnonymousClassDef _newAnon();
/**
* This type, with the given generic type arguments.
*
* @param args the type arguments
* @return the generic type
*/
JType typeArg(String... args);
/**
* This type, with the given generic type arguments.
*
* @param args the type arguments
* @return the generic type
*/
JType typeArg(JType... args);
/**
* This type, with the given generic type arguments.
*
* @param args the type arguments
* @return the generic type
*/
JType typeArg(Class>... args);
/**
* Get the type arguments of this type.
*
* @return the type arguments of this type
*/
JType[] typeArgs();
/**
* The primitive-boxed version of this type.
*
* @return the boxed version of this type
*/
JType box();
/**
* The primitive-unboxed version of this type.
*
* @return the unboxed version of this type
*/
JType unbox();
/**
* The erasure of this type.
*
* @return the erasure of this type
*/
JType erasure();
/**
* The element type, if this an array (otherwise {@code null}).
*
* @return the element type, or {@code null} if it is not an array
*/
JType elementType();
/**
* Get a wildcard that extends this type.
*
* @return the wildcard
*/
JType wildcardExtends();
/**
* Get a wildcard that this type extends.
*
* @return the wildcard
*/
JType wildcardSuper();
/**
* Get a nested type within this reference type.
*
* @param name the name of the nested type
* @return the nested type
*/
JType nestedType(String name);
/**
* Get a nested type within this reference type.
*
* @param name the name of the nested type
* @return the nested type
*/
JType $t(String name);
/**
* Look up a static field on this type.
*
* @param name the field name
* @return the field expression
*/
JAssignableExpr field(String name);
/**
* Look up a static field on this type.
*
* @param name the field name
* @return the field expression
*/
JAssignableExpr $v(String name);
/**
* Call a static method on this type.
*
* @param name the method to call
* @return the method call
*/
JCall call(String name);
/**
* Call a static method on this type.
*
* @param method the method to call
* @return the method call
*/
JCall call(ExecutableElement method);
/**
* Get a method reference of this type.
*
* @param name the method name
* @return the method reference expression
*/
JExpr methodRef(String name);
/**
* Get a method reference of this type.
*
* @param method the method element
* @return the method reference expression
*/
JExpr methodRef(ExecutableElement method);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JTypeCommentContent.java 0000664 0000000 0000000 00000002220 12500061542 0027667 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class JTypeCommentContent implements CommentContent {
private final JType type;
JTypeCommentContent(final JType type) {
this.type = type;
}
JType getType() {
return type;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write(type);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JTypeParamDef.java 0000664 0000000 0000000 00000004031 12500061542 0026413 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A type parameter definition.
*
* @author David M. Lloyd
*/
public interface JTypeParamDef {
/**
* Add an {@code extends} bound to this parameter.
*
* @param type the bound type
* @return this type parameter definition
*/
JTypeParamDef _extends(String type);
/**
* Add an {@code extends} bound to this parameter.
*
* @param type the bound type
* @return this type parameter definition
*/
JTypeParamDef _extends(JType type);
/**
* Add an {@code extends} bound to this parameter.
*
* @param type the bound type
* @return this type parameter definition
*/
JTypeParamDef _extends(Class> type);
/**
* Add a {@code super} bound to this parameter.
*
* @param type the bound type
* @return this type parameter definition
*/
JTypeParamDef _super(String type);
/**
* Add a {@code super} bound to this parameter.
*
* @param type the bound type
* @return this type parameter definition
*/
JTypeParamDef _super(JType type);
/**
* Add a {@code super} bound to this parameter.
*
* @param type the bound type
* @return this type parameter definition
*/
JTypeParamDef _super(Class> type);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JTypes.java 0000664 0000000 0000000 00000014377 12500061542 0025214 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.util.LinkedHashMap;
import java.util.List;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.type.WildcardType;
/**
* The factory for generating simple types.
*/
public final class JTypes {
private JTypes() {}
/**
* Return the erased type of a class definition.
*
* @param classDef the class definition
* @return the type
*/
public static JType $t(JClassDef classDef) {
return typeOf(classDef);
}
/**
* Return the type corresponding to the given class.
*
* @param clazz the class
* @return the type
*/
public static JType $t(Class> clazz) {
return typeOf(clazz);
}
/**
* Return a type corresponding to a class with the given name.
*
* @param name the class name
* @return the type
*/
public static JType $t(String name) {
return typeNamed(name);
}
/**
* Return the erased type of a class definition.
*
* @param classDef the class definition
* @return the type
*/
public static JType typeOf(JClassDef classDef) {
return classDef.erasedType();
}
/**
* Return the type corresponding to the given class.
*
* @param clazz the class
* @return the type
*/
public static JType typeOf(Class> clazz) {
final Class> enclosingClass = clazz.getEnclosingClass();
if (enclosingClass != null) {
return $t(enclosingClass).$t(clazz.getSimpleName());
} else {
return $t(clazz.getName());
}
}
static final ThreadLocal> cache = new CachingThreadLocal<>();
/**
* Return a type corresponding to a class with the given name.
*
* @param name the class name
* @return the type
*/
public static JType typeNamed(String name) {
if (name.endsWith("[]")) {
return typeNamed(name.substring(0, name.length() - 2)).array();
}
final LinkedHashMap map = cache.get();
JType type = map.get(name);
if (type == null) {
final int idx = name.lastIndexOf('.');
map.put(name, type = new ReferenceJType(idx == -1 ? "" : name.substring(0, idx), name.substring(idx + 1)));
}
return type;
}
/**
* Get a {@code JType} that corresponds to the given {@code TypeMirror} for annotation processors.
*
* @param typeMirror the type mirror
* @return the {@code JType}
*/
public static JType typeOf(TypeMirror typeMirror) {
if (typeMirror instanceof ArrayType) {
return typeOf(((ArrayType) typeMirror).getComponentType()).array();
} else if (typeMirror instanceof WildcardType) {
final WildcardType wildcardType = (WildcardType) typeMirror;
final TypeMirror extendsBound = wildcardType.getExtendsBound();
final TypeMirror superBound = wildcardType.getSuperBound();
return extendsBound != null ? typeOf(extendsBound).wildcardExtends() : superBound != null ? typeOf(superBound).wildcardSuper() : JType.WILDCARD;
} else if (typeMirror instanceof TypeVariable) {
final TypeVariable typeVariable = (TypeVariable) typeMirror;
final String name = typeVariable.asElement().getSimpleName().toString();
return typeNamed(name);
} else if (typeMirror instanceof DeclaredType) {
final DeclaredType declaredType = (DeclaredType) typeMirror;
final TypeElement typeElement = (TypeElement) declaredType.asElement();
final TypeMirror enclosingType = declaredType.getEnclosingType();
if (enclosingType != null && enclosingType.getKind() == TypeKind.DECLARED) {
return typeOf(enclosingType).nestedType(typeElement.getSimpleName().toString());
}
final String name = typeElement.getQualifiedName().toString();
final JType rawType = JTypes.typeNamed(name);
final List extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (typeArguments.isEmpty()) {
return rawType;
}
JType[] args = new JType[typeArguments.size()];
for (int i = 0; i < typeArguments.size(); i++) {
final TypeMirror argument = typeArguments.get(i);
args[i] = typeOf(argument);
}
return rawType.typeArg(args);
} else if (typeMirror instanceof NoType) {
switch (typeMirror.getKind()) {
case VOID: return JType.VOID;
}
// fall out
} else if (typeMirror instanceof PrimitiveType) {
switch (typeMirror.getKind()) {
case BOOLEAN: return JType.BOOLEAN;
case BYTE: return JType.BYTE;
case SHORT: return JType.SHORT;
case INT: return JType.INT;
case LONG: return JType.LONG;
case CHAR: return JType.CHAR;
case FLOAT: return JType.FLOAT;
case DOUBLE: return JType.DOUBLE;
}
// fall out
}
throw new IllegalArgumentException(String.format("Cannot find equivalent type to %s", typeMirror));
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/JVarDeclaration.java 0000664 0000000 0000000 00000003214 12500061542 0026772 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* A variable declaration.
*
* @author David M. Lloyd
*/
public interface JVarDeclaration extends JAnnotatable, JDocCommentable {
/**
* Get the variable type.
*
* @return the variable type
*/
JType type();
/**
* Get the variable name.
*
* @return the variable name
*/
String name();
/**
* Add another item to this declaration. Subsequent items always have the same type as this item.
*
* @param name the variable name
* @param init the variable initializer
* @return the subsequent declaration
*/
JVarDeclaration add(String name, JExpr init);
/**
* Add another item to this declaration. Subsequent items always have the same type as this item.
*
* @param name the variable name
* @return the subsequent declaration
*/
JVarDeclaration add(String name);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/KeywordExprJStatement.java 0000664 0000000 0000000 00000002555 12500061542 0030253 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class KeywordExprJStatement extends KeywordJStatement {
private final JExpr expr;
KeywordExprJStatement(final $KW keyword, final JExpr expr) {
super(keyword);
this.expr = expr;
}
JExpr getExpression() {
return expr;
}
public void write(final SourceFileWriter writer) throws IOException {
writeComments(writer);
writer.write(getKeyword());
writer.sp();
writer.write(expr);
writer.write($PUNCT.SEMI);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/KeywordJCall.java 0000664 0000000 0000000 00000002347 12500061542 0026322 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class KeywordJCall extends AbstractJCall {
private final $KW keyword;
KeywordJCall(final $KW keyword) {
super(Prec.METHOD_CALL);
this.keyword = keyword;
}
public void write(final SourceFileWriter writer) throws IOException {
super.writeTypeArgs(writer);
writer.write(keyword);
super.write(writer);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/KeywordJExpr.java 0000664 0000000 0000000 00000002211 12500061542 0026353 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.$KW;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class KeywordJExpr extends AbstractJExpr {
private final $KW name;
KeywordJExpr(final $KW name) {
super(0);
this.name = name;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write(name);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/KeywordJStatement.java 0000664 0000000 0000000 00000002432 12500061542 0027406 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class KeywordJStatement extends BasicJStatement implements BlockContent {
private final $KW keyword;
KeywordJStatement($KW keyword) {
this.keyword = keyword;
}
$KW getKeyword() {
return keyword;
}
public void write(final SourceFileWriter writer) throws IOException {
writeComments(writer);
writer.write(keyword);
writer.write($PUNCT.SEMI);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/LineJComment.java 0000664 0000000 0000000 00000003115 12500061542 0026306 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class LineJComment extends AbstractJComment implements ClassContent, ClassFileContent, BlockContent, JClassItem {
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped("// ");
writer.pushIndent(CommentIndentation.LINE);
try {
super.write(writer);
} finally {
writer.popIndent(CommentIndentation.LINE);
}
}
public Kind getItemKind() {
return Kind.LINE_COMMENT;
}
public int getModifiers() {
return 0;
}
public boolean hasAllModifiers(final int mods) {
return false;
}
public boolean hasAnyModifier(final int mods) {
return false;
}
public String getName() {
return null;
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/LongJExpr.java 0000664 0000000 0000000 00000002744 12500061542 0025641 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class LongJExpr extends AbstractJExpr implements JExpr {
private final long val;
private final int radix;
LongJExpr(final long val, final int radix) {
super(0);
this.val = val;
this.radix = radix;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.addWordSpace();
writer.write(Tokens.$NUMBER);
switch (radix) {
case 2:
writer.writeEscaped("0b");
break;
case 16:
writer.writeEscaped("0x");
break;
}
writer.writeEscaped(Long.toString(val, radix) + "L");
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/MethodJMethodDef.java 0000664 0000000 0000000 00000004125 12500061542 0027076 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
import org.jboss.jdeparser.FormatPreferences.Space;
/**
* @author David M. Lloyd
*/
class MethodJMethodDef extends AbstractJMethodDef implements JClassItem {
private final JType returnType;
private final String name;
MethodJMethodDef(final AbstractJClassDef clazz, final int mods, final JType returnType, final String name) {
super(clazz, mods);
this.returnType = returnType;
this.name = name;
}
JType getReturnType() {
return returnType;
}
public void write(final SourceFileWriter writer) throws IOException {
writeDocComments(writer);
writeComments(writer);
writeAnnotations(writer, Space.AFTER_ANNOTATION);
JMod.write(writer, getModifiers());
writeTypeParams(writer);
writer.write(returnType);
writer.sp();
writer.writeEscapedWord(name);
super.write(writer);
}
public String getName() {
return name;
}
public int getModifiers() {
return super.getModifiers();
}
public Kind getItemKind() {
return Kind.METHOD;
}
public boolean hasAllModifiers(final int mods) {
return (getModifiers() & mods) == mods;
}
public boolean hasAnyModifier(final int mods) {
return (getModifiers() & mods) != 0;
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/MethodRefJExpr.java 0000664 0000000 0000000 00000002432 12500061542 0026611 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class MethodRefJExpr extends AbstractJExpr {
private final AbstractJType type;
private final String name;
MethodRefJExpr(final AbstractJType type, final String name) {
super(0);
this.type = type;
this.name = name;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write(type);
writer.write(Tokens.$PUNCT.BINOP.DBL_COLON);
writer.writeEscapedWord(name);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NameJExpr.java 0000664 0000000 0000000 00000002153 12500061542 0025614 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class NameJExpr extends AbstractJAssignableExpr {
private final String name;
NameJExpr(final String name) {
super(0);
this.name = name;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped(name);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NarrowedJType.java 0000664 0000000 0000000 00000007003 12500061542 0026517 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
import java.util.Arrays;
/**
* @author David M. Lloyd
*/
class NarrowedJType extends AbstractJType {
private final AbstractJType erased;
private final JType[] args;
public NarrowedJType(final AbstractJType erased, final JType[] args) {
this.erased = erased;
this.args = args;
}
public String simpleName() {
return erased.simpleName();
}
public JExpr _class() {
return erased._class();
}
public JExpr _this() {
return erased._this();
}
public JExpr _super() {
return erased._super();
}
public JCall _new() {
return new NewJCall(this);
}
public JCall _new(final JExpr dim) {
final JCall call = erasure()._new();
for (JType arg : args) {
call.typeArg(arg);
}
return call;
}
public JType typeArg(final JType... args) {
return new NarrowedJType(erased, concat(this.args, args));
}
private static JType[] concat(JType[] a, JType[] b) {
if (a.length == 0) return b;
final int al = a.length;
final int bl = b.length;
final JType[] c = Arrays.copyOf(a, al + bl);
System.arraycopy(b, 0, c, al, bl);
return c;
}
public JType[] typeArgs() {
return args;
}
public JType erasure() {
return erased;
}
public JCall call(final String name) {
return erasure().call(name);
}
public JType nestedType(final String name) {
return erasure().nestedType(name);
}
void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
sourceFileWriter.write(erasure());
final JType[] args = this.args;
final int len = args.length;
if (len > 0) {
sourceFileWriter.write($PUNCT.ANGLE.OPEN);
JType type = args[0];
sourceFileWriter.write(type);
for (int i = 1; i < len; i ++) {
sourceFileWriter.write(FormatPreferences.Space.BEFORE_COMMA);
sourceFileWriter.write($PUNCT.COMMA);
sourceFileWriter.write(FormatPreferences.Space.AFTER_COMMA_TYPE_ARGUMENT);
type = args[i];
sourceFileWriter.write(type);
}
sourceFileWriter.write($PUNCT.ANGLE.CLOSE);
}
}
public String toString() {
final StringBuilder b = new StringBuilder(erased.toString());
b.append('<');
for (int i = 0; i < args.length; i++) {
JType arg = args[i];
b.append(arg);
if (i < args.length - 1) {
b.append(",");
}
}
b.append('>');
return b.toString();
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NestedCommentContent.java 0000664 0000000 0000000 00000001602 12500061542 0030061 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* @author David M. Lloyd
*/
class NestedCommentContent extends AbstractJComment implements CommentContent {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NestedDocCommentContent.java 0000664 0000000 0000000 00000001613 12500061542 0030511 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* @author David M. Lloyd
*/
class NestedDocCommentContent extends AbstractJDocComment implements DocCommentContent {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NestedHtmlCommentContent.java 0000664 0000000 0000000 00000001616 12500061542 0030713 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* @author David M. Lloyd
*/
class NestedHtmlCommentContent extends AbstractJHtmlComment implements HtmlCommentContent {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NestedJType.java 0000664 0000000 0000000 00000005743 12500061542 0026171 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.$PUNCT;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class NestedJType extends AbstractJType {
private final AbstractJType enclosingType;
private final String name;
private StaticRefJExpr classExpr;
private StaticRefJExpr thisExpr;
private StaticRefJExpr superExpr;
private CachingLinkedHashMap nestedTypes;
NestedJType(final AbstractJType enclosingType, final String name) {
this.enclosingType = enclosingType;
this.name = name;
}
public JExpr _class() {
StaticRefJExpr expr = classExpr;
if (expr == null) {
expr = classExpr = new StaticRefJExpr(this, "class");
}
return expr;
}
public JExpr _this() {
StaticRefJExpr expr = thisExpr;
if (expr == null) {
expr = thisExpr = new StaticRefJExpr(this, "this");
}
return expr;
}
public JExpr _super() {
StaticRefJExpr expr = superExpr;
if (expr == null) {
expr = superExpr = new StaticRefJExpr(this, "super");
}
return expr;
}
public JCall _new(final JExpr dim) {
return new NewJCall(this);
}
public JAnonymousClassDef _newAnon() {
return new ImplJAnonymousClassDef(this);
}
public String simpleName() {
return name;
}
public JType typeArg(final JType... args) {
return new NarrowedJType(this, args);
}
public JType nestedType(final String name) {
CachingLinkedHashMap nestedTypes = this.nestedTypes;
if (nestedTypes == null) {
nestedTypes = this.nestedTypes = new CachingLinkedHashMap<>();
}
NestedJType nestedType = nestedTypes.get(name);
if (nestedType == null) {
nestedTypes.put(name, nestedType = new NestedJType(this, name));
}
return nestedType;
}
public String toString() {
return "Nested type " + name + " of " + enclosingType;
}
void writeDirect(final SourceFileWriter writer) throws IOException {
enclosingType.writeDirect(writer);
writer.write($PUNCT.DOT);
writer.writeClass(name);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NewDimJArrayExpr.java 0000664 0000000 0000000 00000003203 12500061542 0027113 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class NewDimJArrayExpr extends AbstractJExpr {
private final ArrayJType type;
private final AbstractJExpr dim;
NewDimJArrayExpr(final ArrayJType type, final AbstractJExpr dim) {
super(Prec.METHOD_CALL);
this.type = type;
this.dim = dim;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write($KW.NEW);
writer.write(type.elementType());
writer.write($PUNCT.BRACKET.OPEN);
writer.write(FormatPreferences.Space.WITHIN_BRACKETS);
writer.write(dim);
writer.write(FormatPreferences.Space.WITHIN_BRACKETS);
writer.write($PUNCT.BRACKET.CLOSE);
}
public String toString() {
return "new " + type.elementType() + "[" + dim + "]";
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NewJCall.java 0000664 0000000 0000000 00000002742 12500061542 0025426 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class NewJCall extends AbstractJCall {
private final AbstractJType type;
private boolean diamond;
NewJCall(final AbstractJType type) {
super(Prec.NEW);
this.type = type;
}
public JCall diamond() {
diamond = true;
return this;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write(Tokens.$KW.NEW);
writer.write(type);
if (diamond) {
writer.write(Tokens.$PUNCT.ANGLE.OPEN);
writer.write(Tokens.$PUNCT.ANGLE.CLOSE);
} else {
super.writeTypeArgs(writer);
}
super.write(writer);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NewUndimJArrayExpr.java 0000664 0000000 0000000 00000002360 12500061542 0027461 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
import static org.jboss.jdeparser.FormatPreferences.Space;
import static org.jboss.jdeparser.Tokens.$KW;
class NewUndimJArrayExpr extends PlainJArrayExpr {
private final ArrayJType type;
NewUndimJArrayExpr(final ArrayJType type) {
this.type = type;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write($KW.NEW);
writer.write(type);
writer.write(Space.BEFORE_BRACE_ARRAY_INIT);
super.write(writer);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/NonTrailingSpaceContent.java 0000664 0000000 0000000 00000002240 12500061542 0030513 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class NonTrailingSpaceContent implements CommentContent {
private static final NonTrailingSpaceContent INSTANCE = new NonTrailingSpaceContent();
static NonTrailingSpaceContent getInstance() {
return INSTANCE;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.ntsp();
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ParenJExpr.java 0000664 0000000 0000000 00000002665 12500061542 0026011 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class ParenJExpr extends AbstractJExpr {
private final AbstractJExpr expr;
ParenJExpr(final AbstractJExpr expr) {
super(Prec.PAREN);
this.expr = expr;
}
AbstractJExpr getExpression() {
return expr;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write($PUNCT.PAREN.OPEN);
writer.write(FormatPreferences.Space.WITHIN_PAREN_EXPR);
writer.write(expr);
writer.write(FormatPreferences.Space.WITHIN_PAREN_EXPR);
writer.write($PUNCT.PAREN.CLOSE);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/PlainJArrayExpr.java 0000664 0000000 0000000 00000005271 12500061542 0027002 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.FormatPreferences.Space;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
/**
* @author David M. Lloyd
*/
class PlainJArrayExpr extends AbstractJExpr implements JArrayExpr {
private ArrayList members;
PlainJArrayExpr() {
super(0);
}
PlainJArrayExpr(final JExpr... members) {
super(0);
if (members != null) {
final ArrayList list = new ArrayList<>(members.length);
for (JExpr expr : members) {
if (expr != null) {
list.add(expr);
}
}
if (list.size() > 0) {
this.members = list;
}
}
}
public JArrayExpr add(final JExpr value) {
if (value != null) {
ArrayList members = this.members;
if (members == null) {
this.members = members = new ArrayList<>();
}
members.add(value);
}
return this;
}
public int elementCount() {
final ArrayList members = this.members;
return members == null ? 0 : members.size();
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write($PUNCT.BRACE.OPEN);
final ArrayList members = this.members;
if (members != null) {
final Iterator iterator = members.iterator();
if (iterator.hasNext()) {
writer.write(Space.WITHIN_BRACES_ARRAY_INIT);
writer.write(iterator.next());
while (iterator.hasNext()) {
writer.write($PUNCT.COMMA);
writer.write(iterator.next());
}
writer.write(Space.WITHIN_BRACES_ARRAY_INIT);
}
}
writer.write($PUNCT.BRACE.CLOSE);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/PlainJClassDef.java 0000664 0000000 0000000 00000002614 12500061542 0026547 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
/**
* @author David M. Lloyd
*/
class PlainJClassDef extends AbstractJClassDef implements BlockContent, JClassItem {
PlainJClassDef(final int mods, final ImplJSourceFile classFile, final String name) {
super(mods, classFile, name);
}
PlainJClassDef(final int mods, final AbstractJClassDef enclosingClass, final String name) {
super(mods, enclosingClass, name);
}
$KW designation() {
return $KW.CLASS;
}
public Kind getItemKind() {
return Kind.CLASS;
}
public String getName() {
return super.getName();
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Prec.java 0000664 0000000 0000000 00000003113 12500061542 0024651 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* @author David M. Lloyd
*/
final class Prec {
static final int PAREN = 0;
static final int ARRAY_ACCESS = 1;
static final int MEMBER_ACCESS = 1;
static final int METHOD_CALL = 1;
static final int POST_INC_DEC = 1;
static final int PRE_INC_DEC = 2;
static final int UNARY = 2;
static final int CAST = 3;
static final int NEW = 3;
static final int MULTIPLICATIVE = 4;
static final int ADDITIVE = 5;
static final int SHIFT = 6;
static final int RELATIONAL = 7;
static final int INSTANCEOF = 7;
static final int EQUALITY = 8;
static final int BIT_AND = 9;
static final int BIT_XOR = 10;
static final int BIT_OR = 11;
static final int LOG_AND = 12;
static final int LOG_OR = 13;
static final int COND = 14;
static final int ASSIGN = 15;
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/PrimitiveJType.java 0000664 0000000 0000000 00000004611 12500061542 0026710 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class PrimitiveJType extends AbstractJType {
private final String simpleName;
private final ReferenceJType boxed;
private StaticRefJExpr classExpr;
PrimitiveJType(final String simpleName, final String boxed) {
this.simpleName = simpleName;
this.boxed = boxed == null ? null : new ReferenceJType("java.lang", boxed, this);
}
public JType box() {
return boxed;
}
void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
switch (simpleName) {
case "boolean": sourceFileWriter.write($KW.BOOLEAN); return;
case "byte": sourceFileWriter.write($KW.BYTE); return;
case "short": sourceFileWriter.write($KW.SHORT); return;
case "int": sourceFileWriter.write($KW.INT); return;
case "long": sourceFileWriter.write($KW.LONG); return;
case "char": sourceFileWriter.write($KW.CHAR); return;
case "float": sourceFileWriter.write($KW.FLOAT); return;
case "double": sourceFileWriter.write($KW.DOUBLE); return;
case "void": sourceFileWriter.write($KW.VOID); return;
default: throw new IllegalStateException();
}
}
public JExpr _class() {
StaticRefJExpr expr = classExpr;
if (expr == null) {
expr = classExpr = new StaticRefJExpr(this, "class");
}
return expr;
}
public String simpleName() {
return simpleName;
}
public String toString() {
return simpleName;
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ReferenceJType.java 0000664 0000000 0000000 00000011130 12500061542 0026630 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class ReferenceJType extends AbstractJType {
private final PrimitiveJType unboxed;
private final String packageName;
private final String simpleName;
private StaticRefJExpr classExpr;
private StaticRefJExpr thisExpr;
private StaticRefJExpr superExpr;
private CachingLinkedHashMap nestedTypes;
ReferenceJType(final String packageName, final String simpleName) {
this.packageName = packageName;
this.simpleName = simpleName;
this.unboxed = null;
}
ReferenceJType(final String packageName, final String simpleName, final PrimitiveJType unboxed) {
this.packageName = packageName;
this.simpleName = simpleName;
this.unboxed = unboxed;
}
static ReferenceJType of(JType type) {
final AbstractJType type1 = AbstractJType.of(type);
if (type1 instanceof ReferenceJType) {
return (ReferenceJType) type1;
}
throw new IllegalArgumentException("Expected a reference type");
}
@Override
String qualifiedName(final SourceFileWriter writer) {
if (packageName.isEmpty()) {
return simpleName;
}
return packageName + "." + simpleName;
}
public String simpleName() {
return simpleName;
}
public JExpr _class() {
StaticRefJExpr expr = classExpr;
if (expr == null) {
expr = classExpr = new StaticRefJExpr(this, "class");
}
return expr;
}
public JExpr _this() {
StaticRefJExpr expr = thisExpr;
if (expr == null) {
expr = thisExpr = new StaticRefJExpr(this, "this");
}
return expr;
}
public JExpr _super() {
StaticRefJExpr expr = superExpr;
if (expr == null) {
expr = superExpr = new StaticRefJExpr(this, "super");
}
return expr;
}
public JCall _new() {
return new NewJCall(this);
}
public JAnonymousClassDef _newAnon() {
return new ImplJAnonymousClassDef(this);
}
public JType unbox() {
return unboxed == null ? this : unboxed;
}
void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
final ImplJSourceFile cf = sourceFileWriter.getClassFile();
final String currentPackageName = cf.getPackageName();
final boolean packageMatches = currentPackageName.equals(packageName);
if (packageMatches && cf.hasImport(simpleName())) {
// an explicit import masks the implicit import
sourceFileWriter.writeClass(qualifiedName(sourceFileWriter));
} else if (packageName.equals("java.lang") && ! sourceFileWriter.getClassFile().getSources().hasClass(currentPackageName + "." + simpleName()) || packageMatches) {
// implicit import
sourceFileWriter.writeClass(simpleName());
} else if (cf.hasImport(simpleName())) {
// explicit import
sourceFileWriter.writeClass(simpleName());
} else {
sourceFileWriter.writeClass(qualifiedName(sourceFileWriter));
}
}
public JType typeArg(final JType... args) {
if (unboxed != null) return super.typeArg(args);
return new NarrowedJType(this, args);
}
public JType nestedType(final String name) {
CachingLinkedHashMap nestedTypes = this.nestedTypes;
if (nestedTypes == null) {
nestedTypes = this.nestedTypes = new CachingLinkedHashMap<>();
}
NestedJType nestedType = nestedTypes.get(name);
if (nestedType == null) {
nestedTypes.put(name, nestedType = new NestedJType(this, name));
}
return nestedType;
}
public String toString() {
return "Reference of type " + simpleName();
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Sectionable.java 0000664 0000000 0000000 00000002747 12500061542 0026224 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2015 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.util.ArrayList;
interface Sectionable {
JBlock init(ArrayList content);
JBlock staticInit(ArrayList content);
JVarDeclaration field(ArrayList content, int mods, JType type, String name, JExpr init);
JMethodDef method(ArrayList content, int mods, JType returnType, String name);
JMethodDef constructor(ArrayList content, int mods);
JClassDef _class(ArrayList content, int mods, String name);
JClassDef _enum(ArrayList content, int mods, String name);
JClassDef _interface(ArrayList content, int mods, String name);
JClassDef annotationInterface(ArrayList content, int mods, String name);
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/SourceFileWriter.java 0000664 0000000 0000000 00000021100 12500061542 0027211 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.ListIterator;
/**
* @author David M. Lloyd
*/
class SourceFileWriter implements Flushable, Closeable {
private final FormatPreferences format;
private final CountingWriter countingWriter;
private final StringBuilder lineBuffer = new StringBuilder();
private final String lineSep;
private final ArrayDeque thisTypeStack = new ArrayDeque<>();
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") // IDEA bug http://youtrack.jetbrains.com/issue/IDEA-128168
private final ArrayList indentStack = new ArrayList<>();
private final ListIterator stackIterator = indentStack.listIterator(0);
private final Indent nextIndent = new Indent() {
public void addIndent(final Indent next, final FormatPreferences preferences, final StringBuilder lineBuffer) {
if (stackIterator.hasPrevious()) {
final Indent n = stackIterator.previous();
try {
n.addIndent(next, preferences, lineBuffer);
} finally {
stackIterator.next();
}
}
}
public void escape(final Indent next, final StringBuilder b, final int idx) {
if (stackIterator.hasPrevious()) {
final Indent n = stackIterator.previous();
try {
n.escape(this, b, idx);
} finally {
stackIterator.next();
}
}
}
public void unescaped(final Indent next, final StringBuilder b, final int idx) {
if (stackIterator.hasPrevious()) {
final Indent n = stackIterator.previous();
try {
n.unescaped(this, b, idx);
} finally {
stackIterator.next();
}
}
}
};
private Token state = $START;
private int spaceState;
private ImplJSourceFile classFile;
private static final int SS_NONE = 0;
private static final int SS_NEEDED = 1;
private static final int SS_ADDED = 2;
private static final int SS_NEEDS_INDENT = 3;
SourceFileWriter(final FormatPreferences format, final Writer writer) {
this.format = format;
this.countingWriter = new CountingWriter(writer);
// todo use preferences/config
lineSep = System.lineSeparator();
}
void nl() throws IOException {
countingWriter.write(lineBuffer);
countingWriter.write(lineSep);
lineBuffer.setLength(0);
spaceState = SS_NEEDS_INDENT;
}
/**
* Force a space if one hasn't already been added.
*
* @throws IOException etc.
*/
void sp() throws IOException {
if (spaceState == SS_NEEDS_INDENT) {
addIndent();
} else if (spaceState != SS_ADDED) {
spaceState = SS_ADDED;
lineBuffer.append(' ');
}
}
/**
* A non-trailing space.
*/
void ntsp() throws IOException {
if (spaceState == SS_NONE) spaceState = SS_NEEDED;
}
int getLine() {
return countingWriter.getLine();
}
int getColumn() {
return countingWriter.getColumn();
}
void processSpacing() throws IOException {
switch (spaceState) {
case SS_NEEDS_INDENT: {
nextIndent.addIndent(nextIndent, format, lineBuffer);
spaceState = SS_ADDED;
break;
}
case SS_NEEDED: {
sp();
break;
}
}
}
void addIndent() throws IOException {
assert spaceState == SS_NEEDS_INDENT; // it was a new line
nextIndent.addIndent(nextIndent, format, lineBuffer);
spaceState = SS_ADDED;
}
void writeEscaped(String item) throws IOException {
processSpacing();
final int idx = lineBuffer.length();
lineBuffer.append(item);
nextIndent.escape(nextIndent, lineBuffer, idx);
spaceState = SS_NONE;
}
void writeEscaped(final char item) throws IOException {
processSpacing();
final int idx = lineBuffer.length();
lineBuffer.append(item);
nextIndent.escape(nextIndent, lineBuffer, idx);
spaceState = SS_NONE;
}
void writeUnescaped(String item) throws IOException {
processSpacing();
final int idx = lineBuffer.length();
lineBuffer.append(item);
nextIndent.unescaped(nextIndent, lineBuffer, idx);
spaceState = SS_NONE;
}
void writeUnescaped(char item) throws IOException {
processSpacing();
final int idx = lineBuffer.length();
lineBuffer.append(item);
nextIndent.unescaped(nextIndent, lineBuffer, idx);
spaceState = SS_NONE;
}
void write(FormatPreferences.Space rule) throws IOException {
if (rule == null) {
return;
}
if (format.getSpaceType(rule) == FormatPreferences.SpaceType.NEWLINE) {
if (spaceState != SS_NEEDS_INDENT) {
// must not be directly after a newline
nl();
}
} else {
if (format.getSpaceType(rule) == FormatPreferences.SpaceType.SPACE) {
ntsp();
}
}
}
void writeClass(final String nameToWrite) throws IOException {
processSpacing();
addWordSpace();
writeEscaped(nameToWrite);
this.state = $WORD;
spaceState = SS_NONE;
}
void addWordSpace() throws IOException {
if (state instanceof $KW || state == $WORD || state == $NUMBER) {
ntsp();
}
}
void write(final Token state) throws IOException {
processSpacing();
state.write(this);
this.state = state;
spaceState = SS_NONE;
}
void writeEscapedWord(final String rawText) throws IOException {
writeEscaped(rawText);
this.state = $WORD;
}
public void flush() throws IOException {
countingWriter.flush();
}
public void close() throws IOException {
countingWriter.close();
}
void write(final JType type) throws IOException {
if (type != null) AbstractJType.of(type).writeDirect(this);
}
void write(final AbstractJType type) throws IOException {
if (type != null) type.writeDirect(this);
}
void write(final JExpr expr) throws IOException {
if (expr != null) AbstractJExpr.of(expr).write(this);
}
void write(final AbstractJExpr expr) throws IOException {
if (expr != null) expr.write(this);
}
void pushIndent(FormatPreferences.Indentation indentation) {
pushIndent(indentation.getIndent());
}
void pushIndent(Indent indent) {
stackIterator.add(indent);
}
void popIndent(FormatPreferences.Indentation indentation) {
popIndent(indentation.getIndent());
}
void popIndent(Indent indent) {
final Indent pop = stackIterator.previous();
stackIterator.remove();
assert pop == indent;
}
AbstractJType getThisType() {
return thisTypeStack.peek();
}
void pushThisType(final AbstractJType thisType) {
thisTypeStack.push(thisType);
}
void popThisType(final AbstractJType thisType) {
final AbstractJType pop = thisTypeStack.pop();
assert pop == thisType;
}
void setClassFile(final ImplJSourceFile classFile) {
this.classFile = classFile;
}
Token getState() {
return state;
}
ImplJSourceFile getClassFile() {
return classFile;
}
FormatPreferences getFormat() {
return format;
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/SourceWriter.java 0000664 0000000 0000000 00000001645 12500061542 0026425 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
abstract class SourceWriter {
abstract void writeRaw(int ch) throws IOException;
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/StaticInitJBlock.java 0000664 0000000 0000000 00000003201 12500061542 0027116 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class StaticInitJBlock extends BasicJBlock implements ClassContent, JClassItem {
StaticInitJBlock() {
super(null, Braces.REQUIRED);
}
public void write(final SourceFileWriter writer) throws IOException {
writeComments(writer);
writer.write($KW.STATIC);
super.write(writer, FormatPreferences.Space.BEFORE_BRACE_METHOD);
}
public Kind getItemKind() {
return Kind.INIT_BLOCK;
}
public int getModifiers() {
return JMod.STATIC;
}
public boolean hasAllModifiers(final int mods) {
return (mods & JMod.STATIC) == mods;
}
public boolean hasAnyModifier(final int mods) {
return (mods & JMod.STATIC) != 0;
}
public String getName() {
return null;
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/StaticJCall.java 0000664 0000000 0000000 00000002450 12500061542 0026120 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class StaticJCall extends AbstractMethodJCall {
private final JType type;
StaticJCall(final JType type, final String name) {
super(name);
this.type = type;
}
JType getType() {
return type;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write(AbstractJType.of(type));
writer.write($PUNCT.DOT);
super.write(writer);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/StaticRefJExpr.java 0000664 0000000 0000000 00000003325 12500061542 0026622 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class StaticRefJExpr extends AbstractJAssignableExpr {
private final AbstractJType type;
private final String refName;
StaticRefJExpr(final AbstractJType type, final String refName) {
super(Prec.MEMBER_ACCESS);
if (type == null) {
throw new IllegalArgumentException("type is null");
}
if (refName == null) {
throw new IllegalArgumentException("refName is null");
}
this.type = type;
this.refName = refName;
}
AbstractJType getType() {
return type;
}
String getRefName() {
return refName;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write(type);
writer.write($PUNCT.DOT);
writer.writeEscaped(refName);
}
String getName() {
return refName;
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/StringJExpr.java 0000664 0000000 0000000 00000006421 12500061542 0026204 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class StringJExpr extends AbstractJExpr {
private final String val;
StringJExpr(final String val) {
super(0);
this.val = val;
}
static final Indent ESC = new Indent() {
public void addIndent(final Indent next, final FormatPreferences preferences, final StringBuilder lineBuffer) {
next.addIndent(next, preferences, lineBuffer);
lineBuffer.append('"');
}
public void escape(final Indent next, final StringBuilder b, final int idx) {
char c;
int i = idx;
while (i < b.length()) {
c = b.charAt(i);
switch (c) {
case '"':
case '\\': {
b.insert(i, '\\');
i += 2;
break;
}
case '\n': {
b.replace(i, i + 1, "\\n");
i += 2;
break;
}
case '\r': {
b.replace(i, i + 1, "\\r");
i += 2;
break;
}
case '\t': {
b.replace(i, i + 1, "\\t");
i += 2;
break;
}
case '\b': {
b.replace(i, i + 1, "\\b");
i += 2;
break;
}
case '\f': {
b.replace(i, i + 1, "\\f");
i += 2;
break;
}
case 0: {
b.replace(i, i + 1, "\\0");
i += 2;
break;
}
default: {
i++;
}
}
}
}
public void unescaped(final Indent next, final StringBuilder b, final int idx) {
// next is escaped
next.escape(next, b, idx);
}
};
public void write(final SourceFileWriter writer) throws IOException {
writer.addWordSpace();
writer.writeEscaped('"');
writer.pushIndent(ESC);
try {
writer.writeEscaped(val);
} finally {
writer.popIndent(ESC);
}
writer.writeEscaped('"');
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/SuccessorJVarDeclaration.java 0000664 0000000 0000000 00000004257 12500061542 0030674 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.lang.annotation.Annotation;
/**
* @author David M. Lloyd
*/
class SuccessorJVarDeclaration implements JVarDeclaration {
private final FirstJVarDeclaration first;
private final String name;
private final JExpr value;
SuccessorJVarDeclaration(final FirstJVarDeclaration first, final String name, final JExpr value) {
this.first = first;
this.name = name;
this.value = value;
}
public String name() {
return name;
}
JExpr getValue() {
return value;
}
public JComment blockComment() {
return first.blockComment();
}
public JComment lineComment() {
return first.lineComment();
}
public JComment deprecated() {
return first.deprecated();
}
public JDocComment docComment() {
return first.docComment();
}
public JAnnotation annotate(final Class extends Annotation> type) {
return first.annotate(type);
}
public JAnnotation annotate(final JType type) {
return first.annotate(type);
}
public JAnnotation annotate(final String type) {
return first.annotate(type);
}
public JVarDeclaration add(final String name) {
return first.add(name);
}
public JVarDeclaration add(final String name, final JExpr init) {
return first.add(name, init);
}
public JType type() {
return first.type();
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/SynchJBlock.java 0000664 0000000 0000000 00000002763 12500061542 0026143 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class SynchJBlock extends BasicJBlock {
private final AbstractJExpr synchExpr;
SynchJBlock(final BasicJBlock parent, final AbstractJExpr synchExpr) {
super(parent, Braces.REQUIRED);
this.synchExpr = synchExpr;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.write($KW.SYNCHRONIZED);
writer.write(FormatPreferences.Space.BEFORE_PAREN_SYNCHRONIZED);
writer.write($PUNCT.PAREN.OPEN);
writer.write(synchExpr);
writer.write($PUNCT.PAREN.CLOSE);
super.write(writer, FormatPreferences.Space.BEFORE_BRACE_SYNCHRONIZE);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/ThisJType.java 0000664 0000000 0000000 00000003122 12500061542 0025643 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class ThisJType extends AbstractJType {
ThisJType() {
}
public String simpleName() {
return "<>";
}
public String toString() {
return "<>";
}
public JExpr _class() {
return new StaticRefJExpr(this, "class");
}
public JExpr _this() {
return new StaticRefJExpr(this, "this");
}
public JExpr _super() {
return new StaticRefJExpr(this, "super");
}
public JCall _new() {
return new NewJCall(this);
}
public JAnonymousClassDef _newAnon() {
return new ImplJAnonymousClassDef(this);
}
void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
sourceFileWriter.write(sourceFileWriter.getThisType());
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Token.java 0000664 0000000 0000000 00000001525 12500061542 0025045 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
/**
* @author David M. Lloyd
*/
interface Token extends Writable {
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Tokens.java 0000664 0000000 0000000 00000021300 12500061542 0025221 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.FormatPreferences.Space;
import java.io.IOException;
import java.util.Locale;
/**
* @author David M. Lloyd
*/
enum Tokens implements Token {
/**
* Cursor is at a new file.
*/
$START,
$COMMENT,
$STRING_LIT,
$WORD,
$NUMBER,
;
public void write(final SourceFileWriter writer) throws IOException {
// n/a
}
enum $PUNCT implements Token {
SEMI(';'),
DOT('.'),
Q('?'),
COLON(':'),
AT('@'),
COMMA(','),
;
private final char ch;
$PUNCT(final char ch) {
this.ch = ch;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped(ch);
}
public char getChar() {
return ch;
}
enum COMMENT implements Token {
LINE("//"),
OPEN("/*"),
CLOSE("*/"),
;
private final String str;
COMMENT(final String str) {
this.str = str;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped(str);
}
}
enum UNOP implements Token {
COMP("~"),
NOT("!"),
MINUS("-"),
PP("++"),
MM("--"),
;
private final String str;
UNOP(final String str) {
this.str = str;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped(str);
}
}
enum BINOP implements Token {
PLUS("+", Space.AROUND_ADDITIVE),
MINUS("-", Space.AROUND_ADDITIVE),
TIMES("*", Space.AROUND_MULTIPLICATIVE),
DIV("/", Space.AROUND_MULTIPLICATIVE),
MOD("%", Space.AROUND_MULTIPLICATIVE),
BAND("&", Space.AROUND_BITWISE),
BOR("|", Space.AROUND_BITWISE),
BXOR("^", Space.AROUND_BITWISE),
LAND("&&", Space.AROUND_LOGICAL),
LOR("||", Space.AROUND_LOGICAL),
SHR(">>", Space.AROUND_SHIFT),
LSHR(">>>", Space.AROUND_SHIFT),
SHL("<<", Space.AROUND_SHIFT),
EQ("==", Space.AROUND_EQUALITY),
NE("!=", Space.AROUND_EQUALITY),
LT("<", Space.AROUND_RANGE),
GT(">", Space.AROUND_RANGE),
LE("<=", Space.AROUND_RANGE),
GE(">=", Space.AROUND_RANGE),
ASSIGN("=", Space.AROUND_ASSIGN),
ASSIGN_PLUS("+=", Space.AROUND_ASSIGN),
ASSIGN_MINUS("-=", Space.AROUND_ASSIGN),
ASSIGN_TIMES("*=", Space.AROUND_ASSIGN),
ASSIGN_DIV("/=", Space.AROUND_ASSIGN),
ASSIGN_MOD("%=", Space.AROUND_ASSIGN),
ASSIGN_BAND("&=", Space.AROUND_ASSIGN),
ASSIGN_BOR("|=", Space.AROUND_ASSIGN),
ASSIGN_BXOR("^=", Space.AROUND_ASSIGN),
ASSIGN_SHR(">>=", Space.AROUND_ASSIGN),
ASSIGN_LSHR(">>>=", Space.AROUND_ASSIGN),
ASSIGN_SHL("<<=", Space.AROUND_ASSIGN),
DBL_COLON("::", null),
ARROW("->", Space.AROUND_ARROW),
;
private final String str;
private final Space spacingRule;
BINOP(final String str, final Space spacingRule) {
this.str = str;
this.spacingRule = spacingRule;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped(str);
}
public Space getSpacingRule() {
return spacingRule;
}
}
enum PAREN implements Token {
OPEN('('),
CLOSE(')'),
;
private final char ch;
PAREN(final char ch) {
this.ch = ch;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped(ch);
}
}
enum ANGLE implements Token {
OPEN('<'),
CLOSE('>'),
;
private final char ch;
ANGLE(final char ch) {
this.ch = ch;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped(ch);
}
}
enum BRACE implements Token {
OPEN('{'),
CLOSE('}'),
;
private final char ch;
BRACE(final char ch) {
this.ch = ch;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped(ch);
}
}
enum BRACKET implements Token {
OPEN('['),
CLOSE(']'),
;
private final char ch;
BRACKET(final char ch) {
this.ch = ch;
}
public void write(final SourceFileWriter writer) throws IOException {
writer.writeEscaped(ch);
}
}
}
enum $KW implements Token {
AT_INTERFACE("@interface", null, null),
ABSTRACT(null, null),
ASSERT(null, null),
BOOLEAN(null, null),
BREAK(null, null),
BYTE(null, null),
CASE(null, null),
CATCH(Space.BEFORE_KEYWORD_CATCH, null),
CHAR(null, null),
CLASS(null, null),
CONST(null, null),
CONTINUE(null, null),
DEFAULT(null, null),
DO(null, null),
DOUBLE(null, null),
ELSE(Space.BEFORE_KEYWORD_ELSE, null),
ENUM(null, null),
EXTENDS(null, null),
FINAL(null, null),
FINALLY(Space.BEFORE_KEYWORD_FINALLY, null),
FLOAT(null, null),
FOR(null, null),
GOTO(null, null),
IF(null, null),
IMPLEMENTS(null, null),
IMPORT(null, null),
INSTANCEOF(null, null),
INT(null, null),
INTERFACE(null, null),
LONG(null, null),
NATIVE(null, null),
NEW(null, null),
PACKAGE(null, null),
PRIVATE(null, null),
PROTECTED(null, null),
PUBLIC(null, null),
RETURN(null, null),
SHORT(null, null),
STATIC(null, null),
STRICTFP(null, null),
SUPER(null, null),
SWITCH(null, null),
SYNCHRONIZED(null, null),
THIS(null, null),
THROW(null, null),
THROWS(null, null),
TRANSIENT(null, null),
TRY(null, null),
VOID(null, null),
VOLATILE(null, null),
WHILE(Space.BEFORE_KEYWORD_WHILE, null),
FALSE(null, null),
TRUE(null, null),
NULL(null, null),
;
private final String kw;
private final Space before;
private final Space after;
$KW(final Space before, final Space after) {
this.before = before;
this.after = after;
this.kw = name().toLowerCase(Locale.US);
}
$KW(final String name, final Space before, final Space after) {
this.before = before;
this.after = after;
this.kw = name;
}
String getKeyword() {
return kw;
}
public void write(final SourceFileWriter writer) throws IOException {
final Token writerState = writer.getState();
if (writerState == $WORD || writerState == $NUMBER || writerState instanceof $KW) {
writer.sp();
}
if (before != null) writer.write(before);
writer.writeEscapedWord(kw);
if (after != null) writer.write(after);
}
static Token forName(final String keyword) {
switch (keyword) {
case "@interface": return AT_INTERFACE;
default: return valueOf(keyword.toUpperCase(Locale.US));
}
}
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/TryJVarDeclaration.java 0000664 0000000 0000000 00000002447 12500061542 0027500 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
class TryJVarDeclaration extends FirstJVarDeclaration {
private final ImplJTry owner;
TryJVarDeclaration(final int mods, final JType type, final String name, final JExpr value, final ImplJTry owner) {
super(mods, type, name, value);
this.owner = owner;
}
public JVarDeclaration add(final String name, final JExpr init) {
return owner.with(mods(), type(), name, init);
}
public JVarDeclaration add(final String name) {
throw new IllegalArgumentException("Cannot add uninitialized variable to try-with-resources");
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/UnaryJExpr.java 0000664 0000000 0000000 00000003567 12500061542 0026044 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class UnaryJExpr extends AbstractJExpr {
private final $PUNCT.UNOP op;
private final AbstractJExpr expr;
private final boolean postfix;
UnaryJExpr(final $PUNCT.UNOP op, final AbstractJExpr expr) {
this(op, expr, Prec.UNARY, false);
}
UnaryJExpr(final $PUNCT.UNOP op, final AbstractJExpr expr, final int prec) {
this(op, expr, prec, false);
}
UnaryJExpr(final $PUNCT.UNOP op, final AbstractJExpr expr, final int prec, boolean postfix) {
super(prec);
this.op = op;
this.expr = expr.prec() > prec ? new ParenJExpr(expr) : expr;
this.postfix = postfix;
}
AbstractJExpr getExpression() {
return expr;
}
boolean isPostfix() {
return postfix;
}
public void write(final SourceFileWriter writer) throws IOException {
if (isPostfix()) {
writer.write(expr);
writer.write(op);
} else {
writer.write(op);
writer.write(expr);
}
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/WhileJBlock.java 0000664 0000000 0000000 00000003070 12500061542 0026117 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class WhileJBlock extends ConditionJBlock {
WhileJBlock(final BasicJBlock parent, final JExpr cond) {
super(parent, Braces.IF_MULTILINE, cond);
}
public void write(final SourceFileWriter writer) throws IOException {
writeComments(writer);
writer.write($KW.WHILE);
writer.write(FormatPreferences.Space.BEFORE_PAREN_WHILE);
writer.write($PUNCT.PAREN.OPEN);
writer.write(FormatPreferences.Space.WITHIN_PAREN_WHILE);
writer.write(getCondition());
writer.write(FormatPreferences.Space.WITHIN_PAREN_WHILE);
writer.write($PUNCT.PAREN.CLOSE);
super.write(writer, FormatPreferences.Space.BEFORE_BRACE_WHILE);
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/WildcardJType.java 0000664 0000000 0000000 00000004424 12500061542 0026473 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.Tokens.*;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
class WildcardJType extends AbstractJType {
private final AbstractJType targetType;
private final boolean extendsNotSuper;
public WildcardJType(final AbstractJType targetType, final boolean extendsNotSuper) {
this.targetType = targetType;
this.extendsNotSuper = extendsNotSuper;
}
public String simpleName() {
return targetType.simpleName();
}
public JType array() {
throw new UnsupportedOperationException("array of wildcard type not allowed");
}
public JType wildcardExtends() {
if (extendsNotSuper) return this;
throw new UnsupportedOperationException("wildcard extends of wildcard super not allowed");
}
public JType wildcardSuper() {
if (! extendsNotSuper) return this;
throw new UnsupportedOperationException("wildcard super of wildcard extends not allowed");
}
void writeDirect(final SourceFileWriter sourceFileWriter) throws IOException {
sourceFileWriter.write($PUNCT.Q);
sourceFileWriter.sp();
sourceFileWriter.write(extendsNotSuper ? $KW.EXTENDS : $KW.SUPER);
sourceFileWriter.write(getTargetType());
}
public String toString() {
return "? " + (extendsNotSuper ? "extends " : "super ") + targetType;
}
AbstractJType getTargetType() {
return targetType;
}
boolean isExtendsNotSuper() {
return extendsNotSuper;
}
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/Writable.java 0000664 0000000 0000000 00000001640 12500061542 0025534 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.IOException;
/**
* @author David M. Lloyd
*/
interface Writable {
void write(SourceFileWriter writer) throws IOException;
}
jdeparser2-2.0.0.Final/src/main/java/org/jboss/jdeparser/package-info.java 0000664 0000000 0000000 00000001646 12500061542 0026315 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* The primary package for JDeparser classes. To get started, see {@link org.jboss.jdeparser.JDeparser JDeparser}.
*
* @author David M. Lloyd
*/
package org.jboss.jdeparser;
jdeparser2-2.0.0.Final/src/test/ 0000775 0000000 0000000 00000000000 12500061542 0016343 5 ustar 00root root 0000000 0000000 jdeparser2-2.0.0.Final/src/test/java/ 0000775 0000000 0000000 00000000000 12500061542 0017264 5 ustar 00root root 0000000 0000000 jdeparser2-2.0.0.Final/src/test/java/org/ 0000775 0000000 0000000 00000000000 12500061542 0020053 5 ustar 00root root 0000000 0000000 jdeparser2-2.0.0.Final/src/test/java/org/jboss/ 0000775 0000000 0000000 00000000000 12500061542 0021173 5 ustar 00root root 0000000 0000000 jdeparser2-2.0.0.Final/src/test/java/org/jboss/jdeparser/ 0000775 0000000 0000000 00000000000 12500061542 0023152 5 ustar 00root root 0000000 0000000 jdeparser2-2.0.0.Final/src/test/java/org/jboss/jdeparser/AbstractGeneratingTestCase.java 0000664 0000000 0000000 00000005661 12500061542 0031230 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* @author David M. Lloyd
*/
public abstract class AbstractGeneratingTestCase {
private final ConcurrentMap sourceFiles = new ConcurrentHashMap<>();
private final JFiler filer = new JFiler() {
public OutputStream openStream(final String packageName, final String fileName) throws IOException {
final Key key = new Key(packageName, fileName + ".java");
if (! sourceFiles.containsKey(key)) {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
if (sourceFiles.putIfAbsent(key, stream) == null) {
return stream;
}
}
throw new IOException("Already exists");
}
};
public JFiler getFiler() {
return filer;
}
public ByteArrayInputStream openFile(String packageName, String fileName) throws FileNotFoundException {
final ByteArrayOutputStream out = sourceFiles.get(new Key(packageName, fileName));
if (out == null) throw new FileNotFoundException("No file found for package " + packageName + " file " + fileName);
return new ByteArrayInputStream(out.toByteArray());
}
static final class Key {
private final String packageName;
private final String fileName;
Key(final String packageName, final String fileName) {
this.packageName = packageName;
this.fileName = fileName;
}
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Key key = (Key) o;
return fileName.equals(key.fileName) && packageName.equals(key.packageName);
}
public int hashCode() {
int result = packageName.hashCode();
result = 31 * result + fileName.hashCode();
return result;
}
}
}
jdeparser2-2.0.0.Final/src/test/java/org/jboss/jdeparser/SimpleExampleTestCase.java 0000664 0000000 0000000 00000011424 12500061542 0030220 0 ustar 00root root 0000000 0000000 /*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.jdeparser;
import static org.jboss.jdeparser.JExprs.$v;
import static org.jboss.jdeparser.JExprs.str;
import static org.jboss.jdeparser.JMod.FINAL;
import static org.jboss.jdeparser.JMod.PUBLIC;
import static org.jboss.jdeparser.JMod.STATIC;
import static org.jboss.jdeparser.JMod.VARARGS;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Properties;
import org.junit.Test;
/**
* @author David M. Lloyd
*/
public class SimpleExampleTestCase extends AbstractGeneratingTestCase {
@Test
public void testSimple() throws IOException {
final JSources sources = JDeparser.createSources(getFiler(), new FormatPreferences(new Properties()));
final JSourceFile bazFile = sources.createSourceFile("org.foo.bar", "Baz");
bazFile._import(BigDecimal.class);
final JClassDef baz = bazFile._class(PUBLIC | FINAL, "Baz");
final JMethodDef getString = baz.method(PUBLIC | FINAL, String.class, "getString");
getString.docComment().text("Hello\nthere!");
getString.docComment().htmlTag("ul", true).attribute("class", "banana").htmlTag("li", false).text("A line item");
getString.docComment().docTag("author", "Someone");
getString._throws(IllegalStateException.class);
getString.typeParam("T")._extends(JTypes.typeOf(String.class));
baz.field(PUBLIC | STATIC | FINAL, JType.INT, "_foo", JExpr.ONE);
final JVarDeclaration field = baz.field(PUBLIC | FINAL, JType.INT, "localVar");
baz.constructor(JMod.PUBLIC).body().assign(JExprs.$v(field), JExpr.ONE);
final JParamDeclaration theTee = getString.param(FINAL, "T", "theTee");
JParamDeclaration vap = getString.param(FINAL | VARARGS, Object.class, "whatever");
final JBlock body = getString.body();
JVarDeclaration t = body.var(0, String.class, "test", JExpr.NULL);
JIf jIf = body._if(JExprs.$v(t).eq(JExpr.NULL));
jIf.assign(JExprs.$v(t), str("new Value"));
jIf._else().assign(JExprs.$v(t), str("other value"));
// Reference an enclosing class
body.var(0, JTypes.$t(Map.Entry.class).typeArg(String.class, Object.class), "mapEntry", JExpr.NULL);
bazFile._import(Map.class);
body.call(JTypes.$t(System.class).$v("out"), "println").arg(JExprs.$v(theTee));
body.add(JTypes.$t(System.class).$v("out").call("println").arg($v("theTee"))).blockComment().text("Hello\nagain!");
final JExpr tmp1 = body.tempVar(JTypes.$t(int.class), JExprs.decimal(123).plus(JExprs.decimal(456)).times(JExprs.decimal(246)));
body.var(FINAL, JTypes.$t(String.class), "foo", JExprs.str("boo")).add("bar", JExprs.str("zoo")). add("baz");
body.add(JTypes.$t(System.class).$v("out").call("println").arg(tmp1));
final JAnonymousClassDef anon = JTypes.$t(Runnable.class)._newAnon();
anon.init().add(JTypes.$t(System.class).$v("out").call("println").arg(JExprs.str("Bananas!")));
body.add(anon);
body.add(JTypes.$t(System.class).$v("out").call("println").arg(JExprs.lambda().param("foo").param("bar").body(JExprs.str("Super bananas!"))));
body.add(JTypes.$t(System.class).$v("out").call("println").arg(JExprs.lambda().param(int.class, "foo").param(int.class, "bar").body(JExprs.str("Super duper bananas!"))));
final JLambda lambda = JExprs.lambda().param(int.class, "foo").param(int.class, "bar");
final JBlock lambdaBody = lambda.body();
lambdaBody.add(JTypes.$t(System.class).$v("out").call("println").arg(JExprs.str("Bananamus Maximus!")));
body.add(JTypes.$t(System.class).$v("out").call("println").arg(lambda));
sources.writeSources();
final ByteArrayInputStream inputStream = openFile("org.foo.bar", "Baz.java");
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}