本文整理汇总了Java中org.openide.util.Parameters.javaIdentifier方法的典型用法代码示例。如果您正苦于以下问题:Java Parameters.javaIdentifier方法的具体用法?Java Parameters.javaIdentifier怎么用?Java Parameters.javaIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.util.Parameters
的用法示例。
在下文中一共展示了Parameters.javaIdentifier方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createClass
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates a new Java class based on the provided template.
*
* @param template the template to base the new class on.
* @param targetFolder the folder the new class should be created in;
* cannot be null.
* @param className the name of the new class (a valid Java identifier);
* cannot be null.
* @param javadoc the new class's Javadoc; can be null.
* @param parameters map of named objects that are going to be used when creating the new object
* @return the FileObject for the new Java class; never null.
* @throws IOException if an error occurred while creating the class.
*/
public static FileObject createClass(String template, FileObject targetFolder, String className, final String javadoc, Map parameters) throws IOException {
Parameters.notNull("template", template); // NOI18N
Parameters.notNull("targetFolder", targetFolder); // NOI18N
Parameters.javaIdentifier("className", className); // NOI18N
FileObject classFO = createDataObjectFromTemplate(template, targetFolder, className, parameters).getPrimaryFile();
// JavaSource javaSource = JavaSource.forFileObject(classFO);
// final boolean[] commit = { false };
// ModificationResult modification = javaSource.runModificationTask(new AbstractTask<WorkingCopy>() {
// public void run(WorkingCopy copy) throws IOException {
// GenerationUtils genUtils = GenerationUtils.newInstance(copy);
// if (javadoc != null) {
// genUtils.setJavadoc(copy, mainType, javadoc);
// }
// }
// });
// if (commit[0]) {
// modification.commit();
// }
return classFO;
}
示例2: createAssignmentConstructor
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates a constructor which assigns its parameters to fields with the
* same names. For example it can be used to generate:
*
* <pre>
* public void Constructor(String field1, Object field2) {
* this.field1 = field1;
* this.field2 = field2;
* }
* </pre>
*
* @param modifiersTree the constructor modifiers.
* @param constructorName the constructor name; cannot be null.
* @param parameters the constructor parameters; cannot be null.
* @return the new constructor; never null.
*/
public MethodTree createAssignmentConstructor(ModifiersTree modifiersTree, String constructorName, List parameters) {
Parameters.notNull("modifiersTree", modifiersTree);
Parameters.javaIdentifier("constructorName", constructorName); // NOI18N
Parameters.notNull("parameters", parameters); // NOI18N
StringBuilder body = new StringBuilder(parameters.size() * 30);
body.append("{"); // NOI18N
for(int i=0; i < parameters.size();i++ ) {
VariableTree parameter = (VariableTree)parameters.get(i);
String parameterName = parameter.getName().toString();
body.append("this." + parameterName + " = " + parameterName + ";"); // NOI18N
}
body.append("}"); // NOI18N
TreeMaker make = getTreeMaker();
return make.Constructor(
modifiersTree,
Collections.<TypeParameterTree>emptyList(),
parameters,
Collections.<ExpressionTree>emptyList(),
body.toString());
}
示例3: createClass
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates a new Java class based on the provided template.
*
* @param template the template to base the new class on.
* @param targetFolder the folder the new class should be created in;
* cannot be null.
* @param className the name of the new class (a valid Java identifier);
* cannot be null.
* @param javadoc the new class's Javadoc; can be null.
* @param parameters map of named objects that are going to be used when creating the new object
* @return the FileObject for the new Java class; never null.
* @throws IOException if an error occurred while creating the class.
*/
public static FileObject createClass(String template, FileObject targetFolder, String className, final String javadoc, Map<String, ? extends Object> parameters) throws IOException {
Parameters.notNull("template", template); // NOI18N
Parameters.notNull("targetFolder", targetFolder); // NOI18N
Parameters.javaIdentifier("className", className); // NOI18N
FileObject classFO = createDataObjectFromTemplate(template, targetFolder, className, parameters).getPrimaryFile();
// JavaSource javaSource = JavaSource.forFileObject(classFO);
// final boolean[] commit = { false };
// ModificationResult modification = javaSource.runModificationTask(new AbstractTask<WorkingCopy>() {
// public void run(WorkingCopy copy) throws IOException {
// GenerationUtils genUtils = GenerationUtils.newInstance(copy);
// if (javadoc != null) {
// genUtils.setJavadoc(copy, mainType, javadoc);
// }
// }
// });
// if (commit[0]) {
// modification.commit();
// }
return classFO;
}
示例4: createAssignmentConstructor
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates a constructor which assigns its parameters to fields with the
* same names. For example it can be used to generate:
*
* <pre>
* public void Constructor(String field1, Object field2) {
* this.field1 = field1;
* this.field2 = field2;
* }
* </pre>
*
* @param modifiersTree the constructor modifiers.
* @param constructorName the constructor name; cannot be null, it's not used inside except for assertion since 2007 (or before, TODO: remove?)
* @param parameters the constructor parameters; cannot be null.
* @return the new constructor; never null.
*/
public MethodTree createAssignmentConstructor(ModifiersTree modifiersTree, String constructorName, List<VariableTree> parameters) {
Parameters.notNull("modifiersTree", modifiersTree);
Parameters.javaIdentifier("constructorName", constructorName); // NOI18N
Parameters.notNull("parameters", parameters); // NOI18N
StringBuilder body = new StringBuilder(parameters.size() * 30);
body.append("{"); // NOI18N
for (VariableTree parameter : parameters) {
String parameterName = parameter.getName().toString();
body.append("this." + parameterName + " = " + parameterName + ";"); // NOI18N
}
body.append("}"); // NOI18N
TreeMaker make = getTreeMaker();
return make.Constructor(
modifiersTree,
Collections.<TypeParameterTree>emptyList(),
parameters,
Collections.<ExpressionTree>emptyList(),
body.toString());
}
示例5: createPropertyGetterMethod
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates a new public property getter method.
*
* @param modifiersTree the method modifiers; cannot be null.
* @param propertyType the property type; cannot be null.
* @param propertyName the property name; cannot be null.
* @return the new method; never null.
*/
public MethodTree createPropertyGetterMethod(ModifiersTree modifiersTree, String propertyName, Tree propertyType) {
Parameters.notNull("modifiersTree", modifiersTree); // NOI18N
Parameters.javaIdentifier("propertyName", propertyName); // NOI18N
Parameters.notNull("propertyType", propertyType); // NOI18N
return getTreeMaker().Method(
modifiersTree,
createPropertyAccessorName(propertyName, true),
propertyType,
Collections.<TypeParameterTree>emptyList(),
Collections.<VariableTree>emptyList(),
Collections.<ExpressionTree>emptyList(),
"{ return " + propertyName + "; }", // NOI18N
null);
}
示例6: createPropertySetterMethod
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates a new public property setter method.
*
* @param modifiersTree the method modifiers; cannot be null.
* @param propertyType the property type; cannot be null.
* @param propertyName the property name; cannot be null.
* @return the new method; never null.
*/
public MethodTree createPropertySetterMethod(ModifiersTree modifiersTree, String propertyName, Tree propertyType) {
Parameters.notNull("modifiersTree", modifiersTree); // NOI18N
Parameters.javaIdentifier("propertyName", propertyName); // NOI18N
Parameters.notNull("propertyType", propertyType); // NOI18N
TreeMaker make = getTreeMaker();
return make.Method(
modifiersTree,
createPropertyAccessorName(propertyName, false),
make.PrimitiveType(TypeKind.VOID),
Collections.<TypeParameterTree>emptyList(),
Collections.singletonList(createVariable(propertyName, propertyType)),
Collections.<ExpressionTree>emptyList(),
"{ this." + propertyName + " = " + propertyName + "; }", // NOI18N
null);
}
示例7: createConstructor
import org.openide.util.Parameters; //导入方法依赖的package包/类
public MethodTree createConstructor(ModifiersTree modifiersTree, String constructorName, List parameters, String body) {
Parameters.notNull("modifiersTree", modifiersTree);
Parameters.javaIdentifier("constructorName", constructorName); // NOI18N
Parameters.notNull("parameters", parameters); // NOI18N
TreeMaker make = getTreeMaker();
return make.Constructor(
modifiersTree,
Collections.<TypeParameterTree>emptyList(),
parameters,
Collections.<ExpressionTree>emptyList(),
body);
}
示例8: createField
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates a new field.
*
* @param scope the scope in which to create the field (will be e.g. used
* to parse <code>fieldType</code>).
* @param modifiersTree the field modifiers; cannot be null.
* @param fieldType the fully-qualified name of the field type; cannot be null.
* @param fieldName the field name; cannot be null.
* @param expressionTree expression to initialize the field; can be null.
* @return the new field; never null.
*/
public VariableTree createField(TypeElement scope, ModifiersTree modifiersTree, String fieldName, String fieldType, ExpressionTree expressionTree) {
Parameters.notNull("modifiersTree", modifiersTree); // NOI18N
Parameters.javaIdentifier("fieldName", fieldName); // NOI18N
Parameters.notNull("fieldType", fieldType); // NOI18N
return getTreeMaker().Variable(
modifiersTree,
fieldName,
createType(fieldType, scope),
expressionTree);
}
示例9: createVariable
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates a new variable (a <code>VariableTree</code> with no
* modifiers nor initializer).
*
* @param scope the scope in which to create the variable (will be e.g. used
* to parse <code>variableType</code>).
* @param variableType the fully-qualified name of the variable type; cannot be null.
* @param variableName the variable name; cannot be null.
* @return the new variable; never null.
*/
public VariableTree createVariable(TypeElement scope, String variableName, String variableType) {
Parameters.javaIdentifier("variableName", variableName); // NOI18N
Parameters.notNull("variableType", variableType); // NOI18N
return createField(
scope,
createEmptyModifiers(),
variableName,
variableType,
null);
}
示例10: createAnnotationArgument
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates a new annotation argument whose value is a member of a type. For
* example it can be used to generate <code>@Target(ElementType.CONSTRUCTOR)</code>.
*
* @param argumentName the argument name; cannot be null.
* @param argumentType the fully-qualified name of the type whose member is to be invoked
* (e.g. <code>java.lang.annotations.ElementType</code> in the previous
* example); cannot be null.
* @param argumentTypeField a field of <code>argumentType</code>
* (e.g. <code>CONSTRUCTOR</code> in the previous example);
* cannot be null.
* @return the new annotation argument; never null.
*/
public ExpressionTree createAnnotationArgument(String argumentName, String argumentType, String argumentTypeField) {
Parameters.javaIdentifierOrNull("argumentName", argumentName); // NOI18N
Parameters.notNull("argumentType", argumentType); // NOI18N
Parameters.javaIdentifier("argumentTypeField", argumentTypeField); // NOI18N
TreeMaker make = getTreeMaker();
MemberSelectTree argumentValueTree = make.MemberSelect(createQualIdent(argumentType), argumentTypeField);
if (argumentName == null) {
return argumentValueTree;
} else {
return make.Assignment(make.Identifier(argumentName), argumentValueTree);
}
}
示例11: create
import org.openide.util.Parameters; //导入方法依赖的package包/类
/**
* Creates new instance of method model. None of the parameters can be null.
*
* @param name name of the method, must be valid Java identifier
* @param returnType name of return type as written in source code,
* for non-primitive types fully-qualfied name must be used,
* must contain at least one non-whitespace character
* @param body string representation of body, can be null
* @param parameters list of method parameters, can be empty
* @param exceptions list of exceptions represented by fully-qualified names of exceptions, can be empty
* @param modifiers list of modifiers of method, can be empty
* @throws NullPointerException if any of the parameters is <code>null</code>.
* @throws IllegalArgumentException if the paramter returnType does not contain at least one non-whitespace character
* or the parameter name is not a valid Java identifier
* @return immutable model of method
*/
public static MethodModel create(String name, String returnType, String body, List<Variable> parameters, List<String> exceptions, Set<Modifier> modifiers) {
Parameters.javaIdentifier("name", name);
Parameters.notWhitespace("returnType", returnType);
Parameters.notNull("parameters", parameters);
Parameters.notNull("exceptions", exceptions);
Parameters.notNull("modifiers", modifiers);
return new MethodModel(name, returnType, body, parameters, exceptions, modifiers, Collections.<Annotation>emptyList());
}