@Test void different_separator() { assertThat(packageName("package foo.bar.plop; class A{}", "/")).isEqualTo("foo/bar/plop"); }
public static String packageName(@Nullable PackageDeclarationTree packageDeclarationTree, String separator) { if(packageDeclarationTree == null) { return ""; } Deque<String> pieces = new LinkedList<>(); ExpressionTree expr = packageDeclarationTree.packageName(); while (expr.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree mse = (MemberSelectExpressionTree) expr; pieces.push(mse.identifier().name()); pieces.push(separator); expr = mse.expression(); } if (expr.is(Tree.Kind.IDENTIFIER)) { IdentifierTree idt = (IdentifierTree) expr; pieces.push(idt.name()); } StringBuilder sb = new StringBuilder(); for (String piece: pieces) { sb.append(piece); } return sb.toString(); }
PackageUtils { public static String packageName(@Nullable PackageDeclarationTree packageDeclarationTree, String separator) { if(packageDeclarationTree == null) { return ""; } Deque<String> pieces = new LinkedList<>(); ExpressionTree expr = packageDeclarationTree.packageName(); while (expr.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree mse = (MemberSelectExpressionTree) expr; pieces.push(mse.identifier().name()); pieces.push(separator); expr = mse.expression(); } if (expr.is(Tree.Kind.IDENTIFIER)) { IdentifierTree idt = (IdentifierTree) expr; pieces.push(idt.name()); } StringBuilder sb = new StringBuilder(); for (String piece: pieces) { sb.append(piece); } return sb.toString(); } }
PackageUtils { public static String packageName(@Nullable PackageDeclarationTree packageDeclarationTree, String separator) { if(packageDeclarationTree == null) { return ""; } Deque<String> pieces = new LinkedList<>(); ExpressionTree expr = packageDeclarationTree.packageName(); while (expr.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree mse = (MemberSelectExpressionTree) expr; pieces.push(mse.identifier().name()); pieces.push(separator); expr = mse.expression(); } if (expr.is(Tree.Kind.IDENTIFIER)) { IdentifierTree idt = (IdentifierTree) expr; pieces.push(idt.name()); } StringBuilder sb = new StringBuilder(); for (String piece: pieces) { sb.append(piece); } return sb.toString(); } private  PackageUtils(); }
PackageUtils { public static String packageName(@Nullable PackageDeclarationTree packageDeclarationTree, String separator) { if(packageDeclarationTree == null) { return ""; } Deque<String> pieces = new LinkedList<>(); ExpressionTree expr = packageDeclarationTree.packageName(); while (expr.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree mse = (MemberSelectExpressionTree) expr; pieces.push(mse.identifier().name()); pieces.push(separator); expr = mse.expression(); } if (expr.is(Tree.Kind.IDENTIFIER)) { IdentifierTree idt = (IdentifierTree) expr; pieces.push(idt.name()); } StringBuilder sb = new StringBuilder(); for (String piece: pieces) { sb.append(piece); } return sb.toString(); } private  PackageUtils(); static String packageName(@Nullable PackageDeclarationTree packageDeclarationTree, String separator); }
PackageUtils { public static String packageName(@Nullable PackageDeclarationTree packageDeclarationTree, String separator) { if(packageDeclarationTree == null) { return ""; } Deque<String> pieces = new LinkedList<>(); ExpressionTree expr = packageDeclarationTree.packageName(); while (expr.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree mse = (MemberSelectExpressionTree) expr; pieces.push(mse.identifier().name()); pieces.push(separator); expr = mse.expression(); } if (expr.is(Tree.Kind.IDENTIFIER)) { IdentifierTree idt = (IdentifierTree) expr; pieces.push(idt.name()); } StringBuilder sb = new StringBuilder(); for (String piece: pieces) { sb.append(piece); } return sb.toString(); } private  PackageUtils(); static String packageName(@Nullable PackageDeclarationTree packageDeclarationTree, String separator);  }