Changeset 10996


Ignore:
Timestamp:
02/18/06 17:37:44 (18 years ago)
Author:
piso
Message:

Reformatted source.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/CppMode.java

    r10995 r10996  
    33 *
    44 * Copyright (C) 1998-2006 Peter Graves
    5  * $Id: CppMode.java,v 1.4 2006-02-18 17:36:30 piso Exp $
     5 * $Id: CppMode.java,v 1.5 2006-02-18 17:37:44 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2424public final class CppMode extends CMode implements Constants, Mode
    2525{
    26     private static final String[] cppConditionals = {
    27         "if",
    28         "else",
    29         "do",
    30         "while",
    31         "for",
    32         "switch",
    33         "try",
    34         "catch"
     26  private static final String[] cppConditionals =
     27    {
     28      "if",
     29      "else",
     30      "do",
     31      "while",
     32      "for",
     33      "switch",
     34      "try",
     35      "catch"
    3536    };
    3637
    37     // Since this class is final, we may as well construct the singleton class
    38     // instance right away.
    39     private static CppMode mode = new CppMode();
     38  // Since this class is final, we may as well construct the singleton class
     39  // instance right away.
     40  private static CppMode mode = new CppMode();
    4041
    41     private CppMode()
    42     {
    43         super(CPP_MODE, CPP_MODE_NAME);
    44         keywords = new Keywords(this);
    45         conditionals = cppConditionals;
    46     }
     42  private CppMode()
     43  {
     44    super(CPP_MODE, CPP_MODE_NAME);
     45    keywords = new Keywords(this);
     46    conditionals = cppConditionals;
     47  }
    4748
    48     public static final Mode getMode()
    49     {
    50         return mode;
    51     }
     49  public static final Mode getMode()
     50  {
     51    return mode;
     52  }
    5253
    53     public final String getCommentStart()
    54     {
    55         return "// ";
    56     }
     54  public final String getCommentStart()
     55  {
     56    return "// ";
     57  }
    5758
    58     public final String getCommentEnd()
    59     {
    60         return null;
    61     }
     59  public final String getCommentEnd()
     60  {
     61    return null;
     62  }
    6263
    63     public final Formatter getFormatter(Buffer buffer)
    64     {
    65         return new CFormatter(buffer, LANGUAGE_CPP);
    66     }
     64  public final Formatter getFormatter(Buffer buffer)
     65  {
     66    return new CFormatter(buffer, LANGUAGE_CPP);
     67  }
    6768
    68     protected void setKeyMapDefaults(KeyMap km)
    69     {
    70         super.setKeyMapDefaults(km);
    71         km.unmapKey(':'); // No electric ':'.
    72     }
     69  protected void setKeyMapDefaults(KeyMap km)
     70  {
     71    super.setKeyMapDefaults(km);
     72    km.unmapKey(':'); // No electric ':'.
     73  }
    7374
    74     public Tagger getTagger(SystemBuffer buffer)
    75     {
    76         return new CppTagger(buffer);
    77     }
     75  public Tagger getTagger(SystemBuffer buffer)
     76  {
     77    return new CppTagger(buffer);
     78  }
    7879
    79     public boolean hasQualifiedNames()
    80     {
    81         return true;
    82     }
     80  public boolean hasQualifiedNames()
     81  {
     82    return true;
     83  }
    8384
    84     public boolean isQualifiedName(String s)
    85     {
    86         return s.indexOf("::") >= 0;
    87     }
     85  public boolean isQualifiedName(String s)
     86  {
     87    return s.indexOf("::") >= 0;
     88  }
    8889
    89     public int getCorrectIndentation(Line line, Buffer buffer)
    90     {
    91         String trim = line.trim();
    92         final char trimFirstChar = trim.length() > 0 ? trim.charAt(0) : 0;
    93         if (trimFirstChar == '}')
    94             return indentClosingBrace(line, buffer);
    95         if (trim.equals("public:") || trim.equals("private:") || trim.equals("protected:"))
    96             return 0;
    97         Line model = findModel(line);
    98         if (model == null)
    99             return 0;
    100         if (trim.startsWith(": ") || trim.startsWith(":\t")) {
    101             // start of member initialization list
    102             return model.getIndentation() + 2;
    103         }
    104         if (trim.startsWith("{")) {
    105             String modelTrim = model.trim();
    106             if (modelTrim.startsWith(": ") || modelTrim.startsWith(":\t"))
    107                 return 0;
    108         }
    109         return super.getCorrectIndentation(line, buffer);
    110     }
     90  public int getCorrectIndentation(Line line, Buffer buffer)
     91  {
     92    String trim = line.trim();
     93    final char trimFirstChar = trim.length() > 0 ? trim.charAt(0) : 0;
     94    if (trimFirstChar == '}')
     95      return indentClosingBrace(line, buffer);
     96    if (trim.equals("public:") || trim.equals("private:") || trim.equals("protected:"))
     97      return 0;
     98    Line model = findModel(line);
     99    if (model == null)
     100      return 0;
     101    if (trim.startsWith(": ") || trim.startsWith(":\t"))
     102      {
     103        // start of member initialization list
     104        return model.getIndentation() + 2;
     105      }
     106    if (trim.startsWith("{"))
     107      {
     108        String modelTrim = model.trim();
     109        if (modelTrim.startsWith(": ") || modelTrim.startsWith(":\t"))
     110          return 0;
     111      }
     112    return super.getCorrectIndentation(line, buffer);
     113  }
    111114
    112     protected int indentClosingBrace(Line line, Buffer buffer)
    113     {
    114         Position pos = matchClosingBrace(new Position(line, 0));
    115         if (!pos.getLine().trim().startsWith("{"))
    116             pos = findPreviousConditional(pos);
    117         return buffer.getIndentation(pos.getLine());
    118     }
     115  protected int indentClosingBrace(Line line, Buffer buffer)
     116  {
     117    Position pos = matchClosingBrace(new Position(line, 0));
     118    if (!pos.getLine().trim().startsWith("{"))
     119      pos = findPreviousConditional(pos);
     120    return buffer.getIndentation(pos.getLine());
     121  }
    119122}
Note: See TracChangeset for help on using the changeset viewer.