00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "java_colorizer.h"
00025 #include "paragdata.h"
00026
00027 #include <qfont.h>
00028 #include <qapplication.h>
00029 #include <qsettings.h>
00030 #include <private/qrichtext_p.h>
00031
00032 static const char *java_keywords[] = {
00033
00034 "abstract",
00035 "break",
00036 "case",
00037 "catch",
00038 "class",
00039 "continue",
00040 "default",
00041 "do",
00042 "else",
00043 "extends",
00044 "false",
00045 "finally",
00046 "for",
00047 "goto",
00048 "if",
00049 "implements",
00050 "import",
00051 "instanceof",
00052 "interface",
00053 "native",
00054 "new",
00055 "null",
00056 "package",
00057 "private",
00058 "protected",
00059 "public",
00060 "return",
00061 "super",
00062 "strictfp",
00063 "switch",
00064 "synchronized",
00065 "this",
00066 "throws",
00067 "throw",
00068 "transient",
00069 "true",
00070 "try",
00071 "volatile",
00072 "while",
00073 "boolean",
00074 "byte",
00075 "char",
00076 "const",
00077 "double",
00078 "final",
00079 "float",
00080 "int",
00081 "long",
00082 "short",
00083 "static",
00084 "void",
00085 0
00086 };
00087
00088 JavaColorizer::JavaColorizer( QEditor* editor )
00089 : QSourceColorizer( editor )
00090 {
00091
00092 HLItemCollection* context0 = new HLItemCollection( 0 );
00093 context0->appendChild( new StartsWithHLItem( "//", Comment, 0 ) );
00094 context0->appendChild( new StringHLItem( "/*", Comment, 1 ) );
00095 context0->appendChild( new StringHLItem( "\"", String, 2 ) );
00096 context0->appendChild( new StringHLItem( "'", String, 3 ) );
00097 context0->appendChild( new KeywordsHLItem( java_keywords, Keyword, Normal, 0 ) );
00098 context0->appendChild( new NumberHLItem( Constant, 0 ) );
00099
00100
00101 HLItemCollection* context1 = new HLItemCollection( Comment );
00102 context1->appendChild( new StringHLItem( "*/", Comment, 0 ) );
00103
00104 HLItemCollection* context2 = new HLItemCollection( String );
00105 context2->appendChild( new StringHLItem( "\\\\", String, 2 ) );
00106 context2->appendChild( new StringHLItem( "\\\"", String, 2 ) );
00107 context2->appendChild( new StringHLItem( "\"", String, 0 ) );
00108
00109 HLItemCollection* context3 = new HLItemCollection( String );
00110 context3->appendChild( new StringHLItem( "\\\\", String, 3 ) );
00111 context3->appendChild( new StringHLItem( "\\'", String, 3 ) );
00112 context3->appendChild( new StringHLItem( "'", String, 0 ) );
00113
00114 m_items.append( context0 );
00115 m_items.append( context1 );
00116 m_items.append( context2 );
00117 m_items.append( context3 );
00118 }
00119
00120 JavaColorizer::~JavaColorizer()
00121 {
00122 }
00123
00124 int JavaColorizer::computeLevel( QTextParagraph* parag, int startLevel )
00125 {
00126 int level = startLevel;
00127
00128 ParagData* data = (ParagData*) parag->extraData();
00129 if( !data ){
00130 return startLevel;
00131 }
00132
00133 data->setBlockStart( false );
00134
00135 QValueList<Symbol> symbols = data->symbolList();
00136 QValueList<Symbol>::Iterator it = symbols.begin();
00137 while( it != symbols.end() ){
00138 Symbol sym = *it++;
00139 if( sym.ch() == '{' ){
00140 ++level;
00141 } else if( sym.ch() == '}' ){
00142 --level;
00143 }
00144 }
00145
00146 if( level > startLevel ){
00147 data->setBlockStart( true );
00148 }
00149
00150 return level;
00151 }
00152