KDevelop API Documentation

java_colorizer.cpp

Go to the documentation of this file.
00001 /* $Id: java_colorizer.cpp,v 1.13 2002/12/19 22:02:39 raggi Exp $
00002  *
00003  *  This file is part of Klint
00004  *  Copyright (C) 2001 Roberto Raggi (roberto@kdevelop.org)
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; see the file COPYING.  If not, write to
00018  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  *  Boston, MA 02111-1307, USA.
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     // Java keywords
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     // default context
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     // comment context
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 
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003