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;
}
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());
}
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);
}
Aggregations