blob: b0b69c213a0a5bd9e0cd513b35ea5ea18bf73e93 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.syntax;
15
brandjone2ffd5d2017-06-27 18:14:54 +020016import java.io.IOException;
17
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010018/**
19 * Syntax node for comments.
20 */
21public final class Comment extends ASTNode {
22
23 protected final String value;
24
25 public Comment(String value) {
26 this.value = value;
27 }
28
29 public String getValue() {
30 return value;
31 }
32
33 @Override
34 public void accept(SyntaxTreeVisitor visitor) {
35 visitor.visit(this);
36 }
37
38 @Override
brandjone2ffd5d2017-06-27 18:14:54 +020039 public void prettyPrint(Appendable buffer, int indentLevel) throws IOException {
40 // We can't really print comments in the right place anyway, due to how their relative order
41 // is lost in the representation of BuildFileAST. So don't bother word-wrapping and just print
42 // it on a single line.
43 printIndent(buffer, indentLevel);
44 buffer.append("# ");
45 buffer.append(value);
46 }
47
48 @Override
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010049 public String toString() {
50 return value;
51 }
52}