本文整理汇总了Java中com.github.javaparser.ast.expr.ArrayInitializerExpr类的典型用法代码示例。如果您正苦于以下问题:Java ArrayInitializerExpr类的具体用法?Java ArrayInitializerExpr怎么用?Java ArrayInitializerExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArrayInitializerExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了ArrayInitializerExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
@Override
public void visit(final ArrayInitializerExpr n, final Object arg) {
printer.printLn("ArrayInitializerExpr");
printJavaComment(n.getComment(), arg);
printer.print("{");
if (n.getValues() != null) {
printer.print(" ");
for (final Iterator<Expression> i = n.getValues().iterator(); i.hasNext(); ) {
final Expression expr = i.next();
expr.accept(this, arg);
if (i.hasNext()) {
printer.print(", ");
}
}
printer.print(" ");
}
printer.print("}");
}
示例2: visit
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
@Override
public JCTree visit(final ArrayInitializerExpr n, final Object arg) {
//ARG0: JCExpression elemtype
// This is for the type of elements in, e.g., int[][] a = {{1,2},{3,4}};
// Field not necessary
JCExpression arg0 = null;
//ARG1: List<JCExpression> dims
// Field not necessary.
List<JCExpression> arg1 = List.<JCExpression>nil();
//ARG2: List<JCExpression> elems
List<JCExpression> arg2 = List.<JCExpression>nil();
if (n.getValues() != null) {
for (final Expression expr : n.getValues()) {
arg2 = arg2.append((JCExpression) expr.accept(this, arg));
}
}
return new AJCNewArray(make.NewArray(arg0, arg1, arg2), null);
}
示例3: parseArrayInitializerExpression
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
/**
*
* @param arryInEx
* a github javaparser ArrayInitializerExpression
* @param attributes
* the list of attributes of the class,
* to potentially get a type from the name
* @param lineNumber
* the starting line number of the parse method or constructor
* @return
* an Array literal structure
*/
private ArrayLit parseArrayInitializerExpression(ArrayInitializerExpr arryInEx, List<Attribute> attributes, int lineNumber) {
ArrayLit arryLit = new ArrayLit();
ArrayType arrayType = new ArrayType();
List<Integer> dimensions = new ArrayList<>();
if (arryInEx.getValues() != null) {
dimensions.addAll(ParserUtils.extractDimensions(arryInEx.getValues()));
}
arrayType.setDimensions(dimensions);
arryLit.setType(arrayType);
List<Expr> elements = new ArrayList<>();
if (arryInEx.getValues() != null) {
for (Expression expr : arryInEx.getValues()) {
elements.add(parseExpression(expr, attributes, lineNumber));
}
}
arryLit.setElements(elements);
return arryLit;
}
示例4: visitChildren
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
private void visitChildren(Node node, List<ArrayInitializerExpr> arrayInitializerExprs,
Map<String, String> scanedNames, Set<String> scanedImputs,
Map<String, Pattern> scanedRefeWrap, final String... fileName) {
// int level = 0;
// Node parent = node.getParentNode();
// while (parent != null) {
// parent = parent.getParentNode();
// level++;
// }
// if (level > 0 && fileName.length > 0 && fileName[0].endsWith("TeacherManager.java")) {
// if (node instanceof ClassOrInterfaceDeclaration) {
// ClassOrInterfaceDeclaration real = (ClassOrInterfaceDeclaration) node;
// }
// }
List<Node> children = node.getChildrenNodes();
if (Utils.hasLength(children)) {
//不能使用 for (Node node2 : children)
for (int i = 0; i < children.size(); i++) {
Node child = children.get(i);
visit(child, arrayInitializerExprs, scanedNames, scanedImputs, scanedRefeWrap, false, fileName);
}
}
}
示例5: readFile
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
private String readFile(BeanInfo beanInfo, Map<String, String> scanedNames, Set<String> scanedImputs,
Map<String, Pattern> scanedRefeWrap, final String... fileName) {
//logger.info(beanInfo.cu.toString());
List<ArrayInitializerExpr> arrayInitializerExprs = new LinkedList<>();
visit(beanInfo.cu, arrayInitializerExprs, scanedNames, scanedImputs, scanedRefeWrap, false, fileName);
String source = beanInfo.cu.toString();
for (ArrayInitializerExpr arrayInitializerExpr : arrayInitializerExprs) {
String arryExpress = arrayInitializerExpr.toString();
StringBuilder sb = new StringBuilder(arryExpress.length());
int idx = arryExpress.indexOf('{');
int lastIdx = arryExpress.lastIndexOf('}');
sb.append(arryExpress, 0, idx).append('[').append(arryExpress, idx + 1, lastIdx).append(']')
.append(arryExpress, lastIdx + 1, arryExpress.length());
source = source.replace(arryExpress, sb.toString());
}
return source;
}
示例6: getInputOrOutputSocketBody
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
private BlockStmt getInputOrOutputSocketBody(List<DefinedParamType> paramTypes,
ClassOrInterfaceType socketType, String
inputOrOutputPostfix) {
List<Expression> passedExpressions = new ArrayList<>();
for (DefinedParamType inputParam : paramTypes) {
if (inputParam.isIgnored()) {
continue;
}
passedExpressions.add(getSocketListParam(inputParam, socketType, inputOrOutputPostfix));
}
BlockStmt returnStatement = new BlockStmt(
Arrays.asList(new ReturnStmt(
new ArrayCreationExpr(socketType, 1, new ArrayInitializerExpr(passedExpressions)))
)
);
return returnStatement;
}
示例7: visit
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void visit(@Nullable MethodDeclaration methodDec,
@Nullable List<String> groupNames) {
if (null == methodDec || null == groupNames)
throw GlobalUtils
.createNotInitializedException("classorinterfacedeclaration");
else {
if (methodDec.getName().equals("runTest")) {
List<Expression> groups = new ArrayList<Expression>();
for (int i = 1; i < groupNames.size(); i++) {
groups.add(new StringLiteralExpr(groupNames.get(i)));
}
List<MemberValuePair> testAnnoParams = new ArrayList<MemberValuePair>();
testAnnoParams.add(new MemberValuePair("groups",
new ArrayInitializerExpr(groups)));
NormalAnnotationExpr testAnno = new NormalAnnotationExpr(
ASTHelper.createNameExpr("Test"), testAnnoParams);
methodDec.getAnnotations().add(testAnno);
}
}
}
示例8: getVisitorFactory
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
@Override
public Function<PrettyPrinterConfiguration, PrettyPrintVisitor> getVisitorFactory() {
return configuration -> new PrettyPrintVisitor(configuration) {
@Override
public void visit(ArrayInitializerExpr n, Void arg) {
if (arrayLiteralMembersOnSeparateLines) {
if (configuration.isPrintJavaDoc()) {
n.getComment().ifPresent(c -> c.accept(this, arg));
}
printer.print("{");
if (!isNullOrEmpty(n.getValues())) {
printer.println();
printer.indent();
for (final Iterator<Expression> i = n.getValues().iterator(); i.hasNext(); ) {
final Expression expr = i.next();
expr.accept(this, arg);
if (i.hasNext()) {
printer.println(",");
}
}
printer.println();
printer.unindent();
}
printer.print("}");
} else {
super.visit(n, arg);
}
}
};
}
示例9: visit
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
@Override public Node visit(final ArrayCreationExpr n, final A arg) {
n.setType((Type) n.getType().accept(this, arg));
if (n.getDimensions() != null) {
final List<Expression> dimensions = n.getDimensions();
if (dimensions != null) {
for (int i = 0; i < dimensions.size(); i++) {
dimensions.set(i, (Expression) dimensions.get(i).accept(this, arg));
}
removeNulls(dimensions);
}
} else {
n.setInitializer((ArrayInitializerExpr) n.getInitializer().accept(this, arg));
}
return n;
}
示例10: createDomainValueExpression
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
/**
* Creates a domain value expression given a list of expressions.
*
* @return The expression for the domain.
*/
private Expression createDomainValueExpression(Expression... expressions) {
return new ArrayCreationExpr(type.toBoxedType(), 1,
new ArrayInitializerExpr(
Arrays.asList(expressions)
)
);
}
示例11: visit
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
@Override public Boolean visit(final ArrayInitializerExpr n1, final Node arg) {
final ArrayInitializerExpr n2 = (ArrayInitializerExpr) arg;
if (!nodesEquals(n1.getValues(), n2.getValues())) {
return false;
}
return true;
}
示例12: visit
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
@Override
public Node visit(ArrayCreationExpr _n, Object _arg) {
Type<?> type_ = cloneNodes(_n.getType(), _arg);
List<ArrayCreationLevel> levels_ = visit(_n.getLevels(), _arg);
ArrayInitializerExpr initializer_ = cloneNodes(_n.getInitializer(), _arg);
ArrayCreationExpr r = new ArrayCreationExpr(_n.getRange(), type_, levels_, initializer_);
Comment comment = cloneNodes(_n.getComment(), _arg);
r.setComment(comment);
return r;
}
示例13: visit
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
@Override public void visit(final ArrayInitializerExpr n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getValues() != null) {
for (final Expression expr : n.getValues()) {
expr.accept(this, arg);
}
}
}
示例14: visit
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
@Override public Node visit(final ArrayCreationExpr n, final A arg) {
visitComment(n, arg);
n.setType((Type) n.getType().accept(this, arg));
final List<ArrayCreationLevel> values = n.getLevels();
for (int i = 0; i < values.size(); i++) {
values.set(i, (ArrayCreationLevel) values.get(i).accept(this, arg));
}
removeNulls(values);
if (n.getInitializer() != null) {
n.setInitializer((ArrayInitializerExpr) n.getInitializer().accept(this, arg));
}
return n;
}
示例15: generateCompilationUnitFromCloudFormationSpec
import com.github.javaparser.ast.expr.ArrayInitializerExpr; //导入依赖的package包/类
static CompilationUnit generateCompilationUnitFromCloudFormationSpec(CloudFormationSpecification spec,
ArrayInitializerExpr jsonSubTypesArrayExpr) {
if (spec.getResourceType().size() != 1) {
throw new RuntimeException("Expected exactly 1 resource per file");
}
Map.Entry<String, ResourceTypeSpecification> resourceTypeNameAndSpec =
spec.getResourceType().entrySet().iterator().next();
// resourceCanonicalName is a name like "AWS::EC2::Instance", used in the JsonSubTypes.Type annotation and
// Javadoc
String resourceCanonicalName = resourceTypeNameAndSpec.getKey();
// resourceClassName is a shortened form, like "EC2Instance", to serve as the name of the generated Java
// class
String resourceClassName = resourceCanonicalName.substring("AWS::".length()).replace("::", "");
CompilationUnit compilationUnit = new CompilationUnit();
compilationUnit.setPackageDeclaration("com.salesforce.cf2pojo.model")
.addImport(JsonProperty.class);
final ClassOrInterfaceDeclaration resourceClass = compilationUnit.addClass(resourceClassName);
// The class declaration is something like "public class EC2Instance extends
// ResourceBase<EC2Instance.Properties>"
resourceClass.setName(resourceClassName).addModifier(Modifier.PUBLIC)
.addExtendedType(String.format("ResourceBase<%s.Properties>", resourceClassName));
// Add an @Generated annotation to the class
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
resourceClass.addAndGetAnnotation(Generated.class)
.addPair("value", surroundWithQuotes(GenerateTask.class.getCanonicalName()))
.addPair("date", surroundWithQuotes(dateFormat.format(new Date())));
// Add constructor that initializes the properties field to a new Properties object
resourceClass.addConstructor(Modifier.PUBLIC).setBody(new BlockStmt(NodeList.nodeList(
new ExpressionStmt(
new AssignExpr(new NameExpr("properties"),
new ObjectCreationExpr(null, JavaParser.parseClassOrInterfaceType("Properties"),
new NodeList<>()), AssignExpr.Operator.ASSIGN)))));
// Generate the Properties nested class
ResourceTypeSpecification resourceSpec = resourceTypeNameAndSpec.getValue();
ClassOrInterfaceDeclaration resourcePropertiesClass = generatePropertiesClassFromTypeSpec("Properties",
compilationUnit, resourceCanonicalName, resourceSpec);
resourceClass.addMember(resourcePropertiesClass);
// Add a @JsonSubTypes.Type annotation for this resource type to ResourceBase class
jsonSubTypesArrayExpr.getValues().add(new NormalAnnotationExpr()
.addPair("value", resourceClassName + ".class")
.addPair("name", surroundWithQuotes(resourceCanonicalName))
.setName("JsonSubTypes.Type"));
// Generate nested classes for any subproperties of this resource type (e.g.,
// "EC2Instance.BlockDeviceMapping"). These are found in the "PropertyTypes" section of the spec file.
if (spec.getPropertyTypes() != null) {
for (Map.Entry<String, PropertyTypeSpecification> propertyTypeSpecEntry :
spec.getPropertyTypes().entrySet()) {
String subpropertyClassName = substringAfterFinalPeriod(propertyTypeSpecEntry.getKey());
ClassOrInterfaceDeclaration subpropertyClass = generatePropertiesClassFromTypeSpec(
subpropertyClassName, compilationUnit, propertyTypeSpecEntry.getKey(),
propertyTypeSpecEntry.getValue());
// Add the generated subproperty class as a static nested class of the resource class
resourceClass.addMember(subpropertyClass);
}
}
return compilationUnit;
}