Changeset 10996
- Timestamp:
- 02/18/06 17:37:44 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/j/CppMode.java
r10995 r10996 3 3 * 4 4 * Copyright (C) 1998-2006 Peter Graves 5 * $Id: CppMode.java,v 1. 4 2006-02-18 17:36:30piso Exp $5 * $Id: CppMode.java,v 1.5 2006-02-18 17:37:44 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 24 24 public final class CppMode extends CMode implements Constants, Mode 25 25 { 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" 35 36 }; 36 37 37 38 39 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(); 40 41 41 42 43 44 45 46 42 private CppMode() 43 { 44 super(CPP_MODE, CPP_MODE_NAME); 45 keywords = new Keywords(this); 46 conditionals = cppConditionals; 47 } 47 48 48 49 50 51 49 public static final Mode getMode() 50 { 51 return mode; 52 } 52 53 53 54 55 56 54 public final String getCommentStart() 55 { 56 return "// "; 57 } 57 58 58 59 60 61 59 public final String getCommentEnd() 60 { 61 return null; 62 } 62 63 63 64 65 66 64 public final Formatter getFormatter(Buffer buffer) 65 { 66 return new CFormatter(buffer, LANGUAGE_CPP); 67 } 67 68 68 69 70 71 72 69 protected void setKeyMapDefaults(KeyMap km) 70 { 71 super.setKeyMapDefaults(km); 72 km.unmapKey(':'); // No electric ':'. 73 } 73 74 74 75 76 77 75 public Tagger getTagger(SystemBuffer buffer) 76 { 77 return new CppTagger(buffer); 78 } 78 79 79 80 81 82 80 public boolean hasQualifiedNames() 81 { 82 return true; 83 } 83 84 84 85 86 87 85 public boolean isQualifiedName(String s) 86 { 87 return s.indexOf("::") >= 0; 88 } 88 89 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 } 111 114 112 113 114 115 116 117 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 } 119 122 }
Note: See TracChangeset
for help on using the changeset viewer.