Search in sources :

Example 1 with TokenRange

use of com.github.javaparser.TokenRange in project javaparser by javaparser.

the class ArrayType method wrapInArrayTypes.

/**
 * Takes lists of arrayBracketPairs, assumes the lists are ordered left to right and the pairs are ordered left to
 * right, mirroring the actual code. The type gets wrapped in ArrayTypes so that the outermost ArrayType corresponds
 * to the rightmost ArrayBracketPair.
 */
@SafeVarargs
public static Type wrapInArrayTypes(Type type, List<ArrayBracketPair>... arrayBracketPairLists) {
    for (int i = arrayBracketPairLists.length - 1; i >= 0; i--) {
        final List<ArrayBracketPair> arrayBracketPairList = arrayBracketPairLists[i];
        if (arrayBracketPairList != null) {
            for (int j = arrayBracketPairList.size() - 1; j >= 0; j--) {
                ArrayBracketPair pair = arrayBracketPairList.get(j);
                TokenRange tokenRange = null;
                if (type.getTokenRange().isPresent() && pair.getTokenRange().isPresent()) {
                    tokenRange = new TokenRange(type.getTokenRange().get().getBegin(), pair.getTokenRange().get().getEnd());
                }
                type = new ArrayType(tokenRange, type, pair.getOrigin(), pair.getAnnotations());
                if (tokenRange != null) {
                    type.setRange(tokenRange.toRange().get());
                }
            }
        }
    }
    return type;
}
Also used : ResolvedArrayType(com.github.javaparser.resolution.types.ResolvedArrayType) TokenRange(com.github.javaparser.TokenRange)

Example 2 with TokenRange

use of com.github.javaparser.TokenRange in project javaparser by javaparser.

the class LambdaExprTest method assertRange.

private void assertRange(String startToken, String endToken, Node node) {
    TokenRange tokenRange = node.getTokenRange().get();
    assertEquals(startToken, tokenRange.getBegin().asString());
    assertEquals(endToken, tokenRange.getEnd().asString());
}
Also used : TokenRange(com.github.javaparser.TokenRange)

Example 3 with TokenRange

use of com.github.javaparser.TokenRange in project javaparser by javaparser.

the class MainConstructorGenerator method generateNode.

@Override
protected void generateNode(BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
    if (nodeMetaModel.is(Node.class)) {
        return;
    }
    ConstructorDeclaration constructor = new ConstructorDeclaration().setPublic(true).setName(nodeCoid.getNameAsString()).addParameter(TokenRange.class, "tokenRange").setJavadocComment("\n     * This constructor is used by the parser and is considered private.\n     ");
    BlockStmt body = constructor.getBody();
    SeparatedItemStringBuilder superCall = new SeparatedItemStringBuilder("super(", ", ", ");");
    superCall.append("tokenRange");
    for (PropertyMetaModel parameter : nodeMetaModel.getConstructorParameters()) {
        constructor.addParameter(parameter.getTypeNameForSetter(), parameter.getName());
        if (nodeMetaModel.getDeclaredPropertyMetaModels().contains(parameter)) {
            body.addStatement(f("%s(%s);", parameter.getSetterMethodName(), parameter.getName()));
        } else {
            superCall.append(parameter.getName());
        }
    }
    body.getStatements().addFirst(parseExplicitConstructorInvocationStmt(superCall.toString()));
    body.addStatement("customInitialization();");
    addOrReplaceWhenSameSignature(nodeCoid, constructor);
    nodeCu.addImport(TokenRange.class);
}
Also used : ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) SeparatedItemStringBuilder(com.github.javaparser.utils.SeparatedItemStringBuilder) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) TokenRange(com.github.javaparser.TokenRange) PropertyMetaModel(com.github.javaparser.metamodel.PropertyMetaModel)

Aggregations

TokenRange (com.github.javaparser.TokenRange)3 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 PropertyMetaModel (com.github.javaparser.metamodel.PropertyMetaModel)1 ResolvedArrayType (com.github.javaparser.resolution.types.ResolvedArrayType)1 SeparatedItemStringBuilder (com.github.javaparser.utils.SeparatedItemStringBuilder)1