View Javadoc
1   package net.sourceforge.pmd.lang.vm.util;
2   
3   import net.sourceforge.pmd.lang.vm.ast.AbstractVmNode;
4   import net.sourceforge.pmd.lang.vm.directive.Directive;
5   
6   /*
7    * Licensed to the Apache Software Foundation (ASF) under one
8    * or more contributor license agreements.  See the NOTICE file
9    * distributed with this work for additional information
10   * regarding copyright ownership.  The ASF licenses this file
11   * to you under the Apache License, Version 2.0 (the
12   * "License"); you may not use this file except in compliance
13   * with the License.  You may obtain a copy of the License at
14   *
15   *   http://www.apache.org/licenses/LICENSE-2.0
16   *
17   * Unless required by applicable law or agreed to in writing,
18   * software distributed under the License is distributed on an
19   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20   * KIND, either express or implied.  See the License for the
21   * specific language governing permissions and limitations
22   * under the License.    
23   */
24  
25  /**
26   * Convenient wrapper for LogChute functions. This implements the RuntimeLogger methods (and then some). It is hoped
27   * that use of this will fully replace use of the RuntimeLogger.
28   * 
29   * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
30   * @version $Id: Log.java 724825 2008-12-09 18:56:06Z nbubna $
31   * @since 1.5
32   */
33  public class LogUtil {
34  
35      /**
36       * Creates a string that formats the template filename with line number and column of the given Directive. We use
37       * this routine to provide a cosistent format for displaying file errors.
38       */
39      public static final String formatFileString(final Directive directive) {
40          return formatFileString(directive.getTemplateName(), directive.getLine(), directive.getColumn());
41      }
42  
43      /**
44       * Creates a string that formats the template filename with line number and column of the given Node. We use this
45       * routine to provide a cosistent format for displaying file errors.
46       */
47      public static final String formatFileString(final AbstractVmNode node) {
48          return formatFileString(node.getTemplateName(), node.getLine(), node.getColumn());
49      }
50  
51      /**
52       * Simply creates a string that formats the template filename with line number and column. We use this routine to
53       * provide a cosistent format for displaying file errors.
54       * 
55       * @param template File name of template, can be null
56       * @param linenum Line number within the file
57       * @param colnum Column number withing the file at linenum
58       */
59      public static final String formatFileString(String template, final int linenum, final int colnum) {
60          if (template == null || template.equals("")) {
61              template = "<unknown template>";
62          }
63          return template + "[line " + linenum + ", column " + colnum + "]";
64      }
65  }