Source Code Cross Referenced for CsmResultItem.java in  » IDE-Netbeans » cnd » org » netbeans » modules » cnd » completion » cplusplus » ext » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » cnd » org.netbeans.modules.cnd.completion.cplusplus.ext 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.cnd.completion.cplusplus.ext;
0043:
0044:        import java.util.Iterator;
0045:        import org.netbeans.editor.Settings;
0046:        import org.netbeans.lib.editor.util.CharSequenceUtilities;
0047:        import org.netbeans.modules.cnd.api.model.CsmEnumerator;
0048:        import org.netbeans.modules.cnd.api.model.CsmMacro;
0049:        import org.netbeans.modules.cnd.api.model.CsmTypedef;
0050:        import org.netbeans.modules.cnd.modelutil.CsmUtilities;
0051:        import org.netbeans.modules.cnd.api.model.CsmClass;
0052:        import org.netbeans.modules.cnd.api.model.CsmDeclaration;
0053:        import org.netbeans.modules.cnd.api.model.CsmEnum;
0054:        import org.netbeans.modules.cnd.api.model.CsmField;
0055:        import org.netbeans.modules.cnd.api.model.CsmFunction;
0056:        import org.netbeans.modules.cnd.api.model.CsmNamespace;
0057:        import org.netbeans.modules.cnd.api.model.CsmObject;
0058:        import org.netbeans.modules.cnd.api.model.CsmParameter;
0059:        import org.netbeans.modules.cnd.api.model.CsmType;
0060:        import org.netbeans.modules.cnd.api.model.CsmVariable;
0061:        import org.netbeans.modules.cnd.api.model.util.CsmKindUtilities;
0062:        import java.awt.Color;
0063:        import java.awt.Component;
0064:        import java.awt.Font;
0065:        import java.awt.Graphics;
0066:        import java.awt.event.KeyEvent;
0067:        import java.util.ArrayList;
0068:        import java.util.List;
0069:        import javax.swing.text.BadLocationException;
0070:        import javax.swing.text.JTextComponent;
0071:        import org.netbeans.api.editor.completion.Completion;
0072:        import org.netbeans.api.lexer.TokenSequence;
0073:        import org.netbeans.cnd.api.lexer.CndLexerUtilities;
0074:        import org.netbeans.cnd.api.lexer.CppTokenId;
0075:        import org.netbeans.editor.BaseDocument;
0076:        import org.netbeans.editor.Formatter;
0077:        import org.netbeans.editor.SettingsNames;
0078:        import org.netbeans.editor.Utilities;
0079:        import org.netbeans.editor.ext.CompletionQuery;
0080:        import org.netbeans.editor.ext.ExtFormatter;
0081:        import org.netbeans.lib.editor.util.swing.DocumentUtilities;
0082:        import org.netbeans.modules.cnd.api.model.CsmFile;
0083:        import org.netbeans.modules.cnd.api.model.CsmInclude;
0084:        import org.netbeans.modules.cnd.api.model.CsmNamespaceAlias;
0085:        import org.netbeans.modules.cnd.api.model.CsmTemplate;
0086:        import org.netbeans.modules.cnd.api.model.services.CsmIncludeResolver;
0087:        import org.netbeans.modules.cnd.editor.api.CodeStyle;
0088:        import org.netbeans.modules.cnd.modelutil.CsmPaintComponent;
0089:        import org.netbeans.modules.cnd.modelutil.ParamStr;
0090:        import org.netbeans.spi.editor.completion.CompletionItem;
0091:        import org.netbeans.spi.editor.completion.CompletionTask;
0092:
0093:        /**
0094:         *
0095:         * @author  Vladimir Voskresensky
0096:         * after JCResultItem
0097:         */
0098:
0099:        public abstract class CsmResultItem implements 
0100:                CompletionQuery.ResultItem,
0101:                CompletionQuery.ResultItemAssociatedObject, CompletionItem {
0102:
0103:            private static boolean enableInstantSubstitution = true;
0104:
0105:            protected int selectionStartOffset = -1;
0106:            protected int selectionEndOffset = -1;
0107:
0108:            protected int substituteOffset = -1;
0109:
0110:            CsmObject associatedObject;
0111:            private static final Color KEYWORD_COLOR = Color.gray;
0112:            private static final Color TYPE_COLOR = Color.black;
0113:            private int priority;
0114:
0115:            protected CsmResultItem(CsmObject associatedObject, int priority) {
0116:                this .associatedObject = associatedObject;
0117:                this .priority = priority;
0118:            }
0119:
0120:            public abstract String getItemText();
0121:
0122:            public Object getAssociatedObject() {
0123:                return associatedObject;
0124:            }
0125:
0126:            protected static Color getTypeColor(CsmType type) {
0127:                return type.isBuiltInBased(false) ? KEYWORD_COLOR : TYPE_COLOR;
0128:            }
0129:
0130:            public void setSubstituteOffset(int substituteOffset) {
0131:                this .substituteOffset = substituteOffset;
0132:            }
0133:
0134:            public boolean substituteCommonText(JTextComponent c, int offset,
0135:                    int len, int subLen) {
0136:                // [PENDING] not enough info in parameters...
0137:                // commonText
0138:                // substituteExp
0139:                return false;
0140:            }
0141:
0142:            public boolean substituteText(JTextComponent c, int offset,
0143:                    int len, boolean shift) {
0144:                BaseDocument doc = (BaseDocument) c.getDocument();
0145:                String text = getReplaceText();
0146:
0147:                if (text != null) {
0148:                    // Update the text
0149:                    doc.atomicLock();
0150:                    try {
0151:                        CharSequence textToReplace = DocumentUtilities.getText(
0152:                                doc, offset, len);
0153:                        if (CharSequenceUtilities.textEquals(text,
0154:                                textToReplace))
0155:                            return false;
0156:
0157:                        doc.remove(offset, len);
0158:                        doc.insertString(offset, text, null);
0159:                        if (selectionStartOffset >= 0) {
0160:                            c.select(offset + selectionStartOffset, offset
0161:                                    + selectionEndOffset);
0162:                        }
0163:                    } catch (BadLocationException e) {
0164:                        // Can't update
0165:                    } finally {
0166:                        doc.atomicUnlock();
0167:                    }
0168:                }
0169:
0170:                return true;
0171:            }
0172:
0173:            public java.awt.Component getPaintComponent(javax.swing.JList list,
0174:                    boolean isSelected, boolean cellHasFocus) {
0175:                Component ret;
0176:                ret = getPaintComponent(isSelected);
0177:                if (ret == null)
0178:                    return null;
0179:                if (isSelected) {
0180:                    ret.setBackground(list.getSelectionBackground());
0181:                    ret.setForeground(list.getSelectionForeground());
0182:                } else {
0183:                    ret.setBackground(list.getBackground());
0184:                    ret.setForeground(list.getForeground());
0185:                }
0186:                ret.getAccessibleContext().setAccessibleName(getItemText());
0187:                ret.getAccessibleContext().setAccessibleDescription(
0188:                        getItemText());
0189:                return ret;
0190:            }
0191:
0192:            protected abstract Component getPaintComponent(boolean isSelected);
0193:
0194:            // CompletionItem implementation
0195:
0196:            public int getPreferredWidth(Graphics g, Font defaultFont) {
0197:                Component renderComponent = getPaintComponent(false);
0198:                renderComponent.setFont(defaultFont);
0199:                int width = renderComponent.getPreferredSize().width;
0200:                return width;
0201:            }
0202:
0203:            public void render(Graphics g, Font defaultFont,
0204:                    Color defaultColor, Color backgroundColor, int width,
0205:                    int height, boolean selected) {
0206:                Component renderComponent = getPaintComponent(selected);
0207:                renderComponent.setFont(defaultFont);
0208:                renderComponent.setForeground(defaultColor);
0209:                renderComponent.setBackground(backgroundColor);
0210:                renderComponent.setBounds(0, 0, width, height);
0211:                ((CsmPaintComponent) renderComponent).paintComponent(g);
0212:            }
0213:
0214:            protected static String getTypeName(CsmType typ) {
0215:                //        return typ.format(false);
0216:                return typ.getText().toString();
0217:            }
0218:
0219:            /**
0220:             * Used for testing only
0221:             * @return a string representation of the object.
0222:             */
0223:            public String toString() {
0224:                Component comp = getPaintComponent(false);
0225:                return comp != null ? comp.toString() : ""; //NOI18N
0226:            }
0227:
0228:            protected int convertCsmModifiers(CsmObject obj) {
0229:                return CsmUtilities.getModifiers(obj);
0230:            }
0231:
0232:            public static final String COMPLETION_SUBSTITUTE_TEXT = "completion-substitute-text"; //NOI18N
0233:
0234:            static String toAdd;
0235:
0236:            public void processKeyEvent(KeyEvent evt) {
0237:                if (evt.getID() == KeyEvent.KEY_TYPED) {
0238:                    Completion completion = Completion.get();
0239:                    switch (evt.getKeyChar()) {
0240:                    case ' ':
0241:                        if (evt.getModifiers() == 0) {
0242:                            completion.hideCompletion();
0243:                            completion.hideDocumentation();
0244:                        }
0245:                        break;
0246:                    case ';':
0247:                    case ',':
0248:                    case '+':
0249:                    case '-':
0250:                    case '=':
0251:                    case '/':
0252:                    case '*':
0253:                    case '%':
0254:                    case ':':
0255:                        completion.hideCompletion();
0256:                        completion.hideDocumentation();
0257:                        break;
0258:                    case '.':
0259:                        if (defaultAction((JTextComponent) evt.getSource(),
0260:                                Character.toString(evt.getKeyChar()))) {
0261:                            evt.consume();
0262:                            break;
0263:                        }
0264:                    }
0265:                }
0266:            }
0267:
0268:            public CharSequence getSortText() {
0269:                return getItemText();
0270:            }
0271:
0272:            public CharSequence getInsertPrefix() {
0273:                return getItemText();
0274:            }
0275:
0276:            public CompletionTask createDocumentationTask() {
0277:                return null;
0278:                //        return new AsyncCompletionTask(new JavaCompletionProvider.DocQuery(this),
0279:                //            org.netbeans.editor.Registry.getMostActiveComponent());
0280:            }
0281:
0282:            public CompletionTask createToolTipTask() {
0283:                return null;
0284:            }
0285:
0286:            public static void setEnableInstantSubstitution(boolean enable) {
0287:                CsmResultItem.enableInstantSubstitution = enable;
0288:            }
0289:
0290:            public boolean instantSubstitution(JTextComponent c) {
0291:                if (CsmResultItem.enableInstantSubstitution) {
0292:                    Completion completion = Completion.get();
0293:                    completion.hideCompletion();
0294:                    completion.hideDocumentation();
0295:                    defaultAction(c);
0296:                    return true;
0297:                } else {
0298:                    return false;
0299:                }
0300:            }
0301:
0302:            public void defaultAction(JTextComponent component) {
0303:                Completion completion = Completion.get();
0304:                completion.hideCompletion();
0305:                completion.hideDocumentation();
0306:                defaultAction(component, "");
0307:            }
0308:
0309:            boolean defaultAction(JTextComponent component, String addText) {
0310:                int substOffset = substituteOffset;
0311:                if (substOffset == -1) {
0312:                    substOffset = component.getCaret().getDot();
0313:                }
0314:                CsmResultItem.toAdd = addText;
0315:                if (substituteText(component, substOffset, component.getCaret()
0316:                        .getDot()
0317:                        - substOffset, false)) {
0318:                    CsmIncludeResolver inclResolver = CsmIncludeResolver
0319:                            .getDefault();
0320:                    BaseDocument doc = (BaseDocument) component.getDocument();
0321:                    Object ob = getAssociatedObject();
0322:                    if (CsmKindUtilities.isCsmObject(ob)) {
0323:                        CsmFile currentFile = CsmUtilities.getCsmFile(doc,
0324:                                false);
0325:                        if (!inclResolver.isObjectVisible(currentFile,
0326:                                (CsmObject) ob)) {
0327:                            String include = inclResolver.getIncludeDirective(
0328:                                    currentFile, (CsmObject) ob);
0329:
0330:                            if (include.length() != 0) {
0331:                                insertInclude(
0332:                                        component,
0333:                                        currentFile,
0334:                                        include,
0335:                                        include.charAt(include.length() - 1) == '>');
0336:                            }
0337:                        }
0338:                    } else {
0339:                        System.err.println("not yet handled object " + ob);
0340:                    }
0341:                    return true;
0342:                } else {
0343:                    return false;
0344:                }
0345:
0346:            }
0347:
0348:            // Inserts include derctive into document
0349:            private void insertInclude(JTextComponent component,
0350:                    CsmFile currentFile, String include, boolean isSystem) {
0351:                BaseDocument doc = (BaseDocument) component.getDocument();
0352:                CsmInclude lastInclude = null;
0353:                boolean isLastIncludeTypeMatch = false;
0354:                for (CsmInclude inc : currentFile.getIncludes()) {
0355:                    if (inc.isSystem() == isSystem) {
0356:                        lastInclude = inc;
0357:                        isLastIncludeTypeMatch = true;
0358:                    } else {
0359:                        if (lastInclude == null
0360:                                || (!isLastIncludeTypeMatch && !isSystem)) {
0361:                            lastInclude = inc;
0362:                        }
0363:                    }
0364:                }
0365:                doc.atomicLock();
0366:                try {
0367:                    if (lastInclude != null) {
0368:                        if (isLastIncludeTypeMatch) {
0369:                            doc.insertString(lastInclude.getEndOffset(), "\n"
0370:                                    + include, null); // NOI18N
0371:                        } else if (!isSystem) {
0372:                            doc.insertString(lastInclude.getEndOffset(), "\n\n"
0373:                                    + include, null); // NOI18N
0374:                        } else {
0375:                            doc.insertString(lastInclude.getStartOffset(),
0376:                                    include + "\n\n", null); // NOI18N
0377:                        }
0378:                    } else {
0379:                        TokenSequence<CppTokenId> ts;
0380:                        ts = CndLexerUtilities
0381:                                .getCppTokenSequence(component, 0);
0382:                        if (ts != null) {
0383:                            int offset = getIncludeOffsetFromTokenSequence(ts);
0384:                            if (offset == 0) {
0385:                                doc.insertString(offset, "\n" + include
0386:                                        + "\n\n", null); // NOI18N
0387:                            } else {
0388:                                doc.insertString(offset, "\n\n" + include
0389:                                        + "\n", null); // NOI18N
0390:                            }
0391:                        }
0392:                    }
0393:                } catch (BadLocationException e) {
0394:                    // Can't update
0395:                } finally {
0396:                    doc.atomicUnlock();
0397:                }
0398:            }
0399:
0400:            // Finds place for include insertion in case if there is no other includes in document
0401:            private int getIncludeOffsetFromTokenSequence(
0402:                    TokenSequence<CppTokenId> ts) {
0403:                ts.moveStart();
0404:                if (!ts.moveNext()) {
0405:                    return 0;
0406:                }
0407:                while (ts.token().id().equals(CppTokenId.WHITESPACE)
0408:                        || ts.token().id().equals(CppTokenId.NEW_LINE)) {
0409:                    if (!ts.moveNext()) {
0410:                        return 0;
0411:                    }
0412:                }
0413:                if (ts.token().id().equals(CppTokenId.BLOCK_COMMENT)
0414:                        || ts.token().id().equals(CppTokenId.DOXYGEN_COMMENT)) {
0415:                    if (!ts.moveNext()) {
0416:                        return 0;
0417:                    }
0418:                    int firstCommentEndOffset = ts.offset();
0419:                    int newLineNumber = 0;
0420:                    while (ts.token().id().equals(CppTokenId.WHITESPACE)
0421:                            || ts.token().id().equals(CppTokenId.NEW_LINE)) {
0422:                        if (ts.token().id().equals(CppTokenId.NEW_LINE)) {
0423:                            newLineNumber++;
0424:                        }
0425:                        if (!ts.moveNext()) {
0426:                            return 0;
0427:                        }
0428:                    }
0429:                    if (ts.token().id().equals(CppTokenId.BLOCK_COMMENT)
0430:                            || ts.token().id().equals(
0431:                                    CppTokenId.DOXYGEN_COMMENT)) {
0432:                        return firstCommentEndOffset;
0433:                    } else {
0434:                        if (newLineNumber > 1) {
0435:                            return firstCommentEndOffset;
0436:                        }
0437:                        return 0;
0438:                    }
0439:                }
0440:                return 0;
0441:            }
0442:
0443:            protected String getReplaceText() {
0444:                return getItemText();
0445:            }
0446:
0447:            public int getSortPriority() {
0448:                return this .priority;
0449:            }
0450:
0451:            public static class FileLocalVariableResultItem extends
0452:                    VariableResultItem {
0453:
0454:                public FileLocalVariableResultItem(CsmVariable fld, int priotity) {
0455:                    super (fld, priotity);
0456:                }
0457:
0458:                protected CsmPaintComponent.FieldPaintComponent createPaintComponent() {
0459:                    return new CsmPaintComponent.FileLocalVariablePaintComponent();
0460:                }
0461:            }
0462:
0463:            public static class GlobalVariableResultItem extends
0464:                    VariableResultItem {
0465:
0466:                public GlobalVariableResultItem(CsmVariable fld, int priotity) {
0467:                    super (fld, priotity);
0468:                }
0469:
0470:                protected CsmPaintComponent.FieldPaintComponent createPaintComponent() {
0471:                    return new CsmPaintComponent.GlobalVariablePaintComponent();
0472:                }
0473:            }
0474:
0475:            public static class LocalVariableResultItem extends
0476:                    VariableResultItem {
0477:
0478:                public LocalVariableResultItem(CsmVariable fld, int priotity) {
0479:                    super (fld, priotity);
0480:                }
0481:
0482:                protected CsmPaintComponent.FieldPaintComponent createPaintComponent() {
0483:                    return new CsmPaintComponent.LocalVariablePaintComponent();
0484:                }
0485:            }
0486:
0487:            public static class FieldResultItem extends VariableResultItem {
0488:
0489:                public FieldResultItem(CsmField fld, int priotity) {
0490:                    super (fld, priotity);
0491:                }
0492:
0493:                protected CsmPaintComponent.FieldPaintComponent createPaintComponent() {
0494:                    return new CsmPaintComponent.FieldPaintComponent();
0495:                }
0496:            }
0497:
0498:            public static class MacroResultItem extends CsmResultItem {
0499:                private String macName;
0500:                private List params;
0501:                private static CsmPaintComponent.MacroPaintComponent macroPaintComp = null;
0502:
0503:                public MacroResultItem(CsmMacro mac, int priotity) {
0504:                    super (mac, priotity);
0505:                    this .macName = mac.getName().toString();
0506:                    this .params = mac.getParameters();
0507:                }
0508:
0509:                private String getName() {
0510:                    return macName;
0511:                }
0512:
0513:                private List getParams() {
0514:                    return params;
0515:                }
0516:
0517:                public String getItemText() {
0518:                    return getName();
0519:                }
0520:
0521:                protected CsmPaintComponent.MacroPaintComponent createPaintComponent() {
0522:                    return new CsmPaintComponent.MacroPaintComponent();
0523:                }
0524:
0525:                public Component getPaintComponent(boolean isSelected) {
0526:                    if (macroPaintComp == null) {
0527:                        macroPaintComp = createPaintComponent();
0528:                    }
0529:                    CsmMacro mac = (CsmMacro) getAssociatedObject();
0530:                    macroPaintComp.setName(getName());
0531:                    macroPaintComp.setParams(getParams());
0532:                    macroPaintComp.setSelected(isSelected);
0533:                    return macroPaintComp;
0534:                }
0535:            }
0536:
0537:            public abstract static class VariableResultItem extends
0538:                    CsmResultItem {
0539:
0540:                private String typeName;
0541:                private Color typeColor;
0542:                private String fldName;
0543:                private int modifiers;
0544:                private boolean isDeprecated;
0545:
0546:                private static CsmPaintComponent.FieldPaintComponent fieldComponent = null;
0547:                private static CsmPaintComponent.FieldPaintComponent globVarComponent = null;
0548:                private static CsmPaintComponent.FieldPaintComponent localVarComponent = null;
0549:                private static CsmPaintComponent.FieldPaintComponent fileLocalVarComponent = null;
0550:
0551:                public VariableResultItem(CsmVariable fld, int priotity) {
0552:                    super (fld, priotity);
0553:                    this .fldName = fld.getName().toString();
0554:                    this .modifiers = convertCsmModifiers(fld);
0555:                    this .typeName = getTypeName(fld.getType());
0556:                    this .typeColor = getTypeColor(fld.getType());
0557:                }
0558:
0559:                public String getItemText() {
0560:                    return fldName;
0561:                }
0562:
0563:                abstract protected CsmPaintComponent.FieldPaintComponent createPaintComponent();
0564:
0565:                public java.awt.Component getPaintComponent(boolean isSelected) {
0566:                    CsmPaintComponent.FieldPaintComponent comp = null;
0567:                    assert (CsmKindUtilities.isCsmObject(getAssociatedObject())) : "must be csm object"; //NOI18N
0568:                    CsmObject var = (CsmObject) getAssociatedObject();
0569:                    if (CsmKindUtilities.isField(var)) {
0570:                        if (fieldComponent == null) {
0571:                            fieldComponent = createPaintComponent();
0572:                        }
0573:                        comp = fieldComponent;
0574:                    } else if (CsmKindUtilities.isGlobalVariable(var)) {
0575:                        if (globVarComponent == null) {
0576:                            globVarComponent = createPaintComponent();
0577:                        }
0578:                        comp = globVarComponent;
0579:                    } else if (CsmKindUtilities.isFileLocalVariable(var)) {
0580:                        if (fileLocalVarComponent == null) {
0581:                            fileLocalVarComponent = createPaintComponent();
0582:                        }
0583:                        comp = fileLocalVarComponent;
0584:                    } else {
0585:                        assert (CsmKindUtilities.isLocalVariable(var)) : "support only global var, local var, file local var and class fields"; //NOI18N
0586:                        if (localVarComponent == null) {
0587:                            localVarComponent = createPaintComponent();
0588:                        }
0589:                        comp = localVarComponent;
0590:                    }
0591:                    comp.setTypeName(typeName);
0592:                    comp.setName(fldName);
0593:                    comp.setTypeColor(typeColor);
0594:                    comp.setModifiers(modifiers);
0595:                    comp.setSelected(isSelected);
0596:
0597:                    return comp;
0598:                }
0599:            }
0600:
0601:            public static class FileLocalFunctionResultItem extends
0602:                    MethodResultItem {
0603:                public FileLocalFunctionResultItem(CsmFunction mtd,
0604:                        CsmCompletionExpression substituteExp, int priotity) {
0605:                    super (mtd, substituteExp, priotity);
0606:                }
0607:
0608:                protected CsmPaintComponent.ConstructorPaintComponent createPaintComponent() {
0609:                    return new CsmPaintComponent.FileLocalFunctionPaintComponent();
0610:                }
0611:            }
0612:
0613:            public static class GlobalFunctionResultItem extends
0614:                    MethodResultItem {
0615:                public GlobalFunctionResultItem(CsmFunction mtd,
0616:                        CsmCompletionExpression substituteExp, int priotity) {
0617:                    super (mtd, substituteExp, priotity);
0618:                }
0619:
0620:                protected CsmPaintComponent.ConstructorPaintComponent createPaintComponent() {
0621:                    return new CsmPaintComponent.GlobalFunctionPaintComponent();
0622:                }
0623:            }
0624:
0625:            public static class MethodResultItem extends ConstructorResultItem {
0626:
0627:                private static CsmPaintComponent.MethodPaintComponent mtdComponent = null;
0628:                private static CsmPaintComponent.MethodPaintComponent globFunComponent = null;
0629:                private String typeName;
0630:                private Color typeColor;
0631:                private String mtdName;
0632:
0633:                public MethodResultItem(CsmFunction mtd,
0634:                        CsmCompletionExpression substituteExp, int priotity) {
0635:                    super (mtd, substituteExp, priotity);
0636:                    typeName = CsmResultItem.getTypeName(mtd.getReturnType());
0637:                    mtdName = mtd.getName().toString();
0638:                    typeColor = CsmResultItem.getTypeColor(mtd.getReturnType());
0639:                }
0640:
0641:                public String getName() {
0642:                    return mtdName;
0643:                }
0644:
0645:                public String getItemText() {
0646:                    return getName();
0647:                }
0648:
0649:                public String getTypeName() {
0650:                    return typeName;
0651:                }
0652:
0653:                public void setTypeName(String typeName) {
0654:                    this .typeName = typeName;
0655:                }
0656:
0657:                public Color getTypeColor() {
0658:                    return typeColor;
0659:                }
0660:
0661:                public void setTypeColor(Color typeColor) {
0662:                    this .typeColor = typeColor;
0663:                }
0664:
0665:                protected CsmPaintComponent.ConstructorPaintComponent createPaintComponent() {
0666:                    return new CsmPaintComponent.MethodPaintComponent();
0667:                }
0668:
0669:                public Component getPaintComponent(boolean isSelected) {
0670:                    CsmPaintComponent.MethodPaintComponent comp = null;
0671:                    assert (CsmKindUtilities.isCsmObject(getAssociatedObject())) : "must be csm object"; //NOI18N
0672:                    CsmObject mtd = (CsmObject) getAssociatedObject();
0673:                    if (CsmKindUtilities.isMethod(mtd)) {
0674:                        if (mtdComponent == null) {
0675:                            mtdComponent = (CsmPaintComponent.MethodPaintComponent) createPaintComponent();
0676:                        }
0677:                        comp = mtdComponent;
0678:                    } else {
0679:                        assert (CsmKindUtilities.isGlobalFunction(mtd)) : "support only global fun and class methods"; //NOI18N
0680:                        if (globFunComponent == null) {
0681:                            globFunComponent = (CsmPaintComponent.MethodPaintComponent) createPaintComponent();
0682:                        }
0683:                        comp = globFunComponent;
0684:                    }
0685:
0686:                    comp.setName(getName());
0687:                    comp.setModifiers(getModifiers());
0688:                    comp.setTypeName(getTypeName());
0689:                    comp.setTypeColor(getTypeColor());
0690:                    comp.setParams(getParams());
0691:                    comp.setExceptions(getExceptions());
0692:                    comp.setSelected(isSelected);
0693:                    return comp;
0694:                }
0695:            }
0696:
0697:            public static class ConstructorResultItem extends CsmResultItem {
0698:
0699:                private CsmFunction ctr;
0700:                private CsmCompletionExpression substituteExp;
0701:                private List params = new ArrayList();
0702:                private List excs = new ArrayList();
0703:                private int modifiers;
0704:                private static CsmPaintComponent.ConstructorPaintComponent ctrComponent = null;
0705:                private int activeParameterIndex = -1;
0706:                private int varArgIndex = -1;
0707:
0708:                public ConstructorResultItem(CsmFunction ctr,
0709:                        CsmCompletionExpression substituteExp, int priotity) {
0710:                    super (ctr, priotity);
0711:                    this .ctr = ctr;
0712:                    this .substituteExp = substituteExp;
0713:                    this .modifiers = convertCsmModifiers(ctr);
0714:                    CsmParameter[] prms = (CsmParameter[]) ctr.getParameters()
0715:                            .toArray(new CsmParameter[0]);
0716:                    for (int i = 0; i < prms.length; i++) {
0717:                        CsmParameter prm = (CsmParameter) prms[i];
0718:                        CsmType type = prm.getType();
0719:                        if (type == null) {
0720:                            // only var args parameters could have null types
0721:                            assert (prm.isVarArgs());
0722:                            params.add(new ParamStr("", "", prm.getName()
0723:                                    .toString(), true, KEYWORD_COLOR)); //NOI18N
0724:                            varArgIndex = i;
0725:                        } else {
0726:                            // XXX may be need full name as the first param
0727:                            // FIXUP: too expensive to call getClassifier here!
0728:                            String strFullName = type.getText().toString();// type.getClassifier().getName();
0729:                            params
0730:                                    .add(new ParamStr(strFullName, type
0731:                                            .getText().toString(), prm
0732:                                            .getName().toString(), false,
0733:                                            TYPE_COLOR /*getTypeColor(type.getClassifier())*/));
0734:                        }
0735:                    }
0736:                    // TODO
0737:                    //            CsmClass excepts[] = ctr.getExceptions();
0738:                    //            for (int i=0; i<excepts.length; i++) {
0739:                    //                CsmClass ex = (CsmClass) excepts[i];
0740:                    //                excs.add(new ExcStr(ex.getName(), getTypeColor(ex)));
0741:                    //            }
0742:
0743:                }
0744:
0745:                public CsmCompletionExpression getExpression() {
0746:                    return this .substituteExp;
0747:                }
0748:
0749:                int getActiveParameterIndex() {
0750:                    return activeParameterIndex;
0751:                }
0752:
0753:                /**
0754:                 * If set to value different than -1 it marks that
0755:                 * this component renders an outer enclosing constructor/method
0756:                 * and the given index is the index of the active parameter
0757:                 * which is being completed as an inner expression.
0758:                 */
0759:                void setActiveParameterIndex(int activeParamIndex) {
0760:                    this .activeParameterIndex = activeParamIndex;
0761:                }
0762:
0763:                public int getModifiers() {
0764:                    return modifiers;
0765:                }
0766:
0767:                public String getName() {
0768:                    // TODO review the output
0769:                    return ctr.getName().toString();
0770:                }
0771:
0772:                public List getParams() {
0773:                    return params;
0774:                }
0775:
0776:                public List getExceptions() {
0777:                    return excs;
0778:                }
0779:
0780:                public int getCurrentParamIndex() {
0781:                    int idx = 0;
0782:                    if (substituteExp != null
0783:                            && substituteExp.getExpID() == CsmCompletionExpression.METHOD_OPEN) {
0784:                        idx = substituteExp.getParameterCount() - 1;
0785:                    }
0786:                    if (varArgIndex > -1 && varArgIndex < idx) {
0787:                        idx = varArgIndex;
0788:                    }
0789:                    return idx;
0790:                }
0791:
0792:                public List createParamsList() {
0793:                    List ret = new ArrayList();
0794:                    for (Iterator it = getParams().iterator(); it.hasNext();) {
0795:                        StringBuffer sb = new StringBuffer();
0796:                        ParamStr ps = (ParamStr) it.next();
0797:                        sb.append(ps.getSimpleTypeName());
0798:                        if (ps.isVarArg()) {
0799:                            sb.append("..."); // NOI18N
0800:                        } else {
0801:                            String name = ps.getName();
0802:                            if (name != null && name.length() > 0) {
0803:                                sb.append(" "); // NOI18N
0804:                                sb.append(name);
0805:                            }
0806:                        }
0807:                        if (it.hasNext()) {
0808:                            sb.append(", "); // NOI18N
0809:                        }
0810:                        ret.add(sb.toString());
0811:                    }
0812:                    return ret;
0813:                }
0814:
0815:                @Override
0816:                public boolean substituteText(JTextComponent c, int offset,
0817:                        int len, boolean shift) {
0818:
0819:                    if (true) {
0820:                        BaseDocument doc = (BaseDocument) c.getDocument();
0821:                        String text = null;
0822:                        boolean addParams = true;
0823:                        //            CsmCompletionExpression exp = substituteExp;
0824:                        //            while(exp != null) {
0825:                        ////                if (exp.getExpID() == CsmCompletionExpression.IMPORT) {
0826:                        ////                    addParams = false;
0827:                        ////                    break;
0828:                        ////                }
0829:                        //                exp = exp.getParent();
0830:                        //            }
0831:
0832:                        switch ((substituteExp != null) ? substituteExp
0833:                                .getExpID() : -1) {
0834:                        case CsmCompletionExpression.METHOD:
0835:                            // no subst
0836:                            break;
0837:
0838:                        case CsmCompletionExpression.METHOD_OPEN:
0839:                            int parmsCnt = params.size();
0840:                            if (parmsCnt == 0) {
0841:                                if (getActiveParameterIndex() == -1) { // not showing active parm
0842:                                    try {
0843:                                        int fnwpos = Utilities
0844:                                                .getFirstNonWhiteFwd(doc,
0845:                                                        offset + len);
0846:                                        if (fnwpos > -1
0847:                                                && doc.getChars(fnwpos, 1)[0] == ')') { // NOI18N
0848:                                            text = doc.getText(offset + len,
0849:                                                    fnwpos + 1 - offset - len);
0850:                                            len = fnwpos + 1 - offset;
0851:                                        }
0852:                                    } catch (BadLocationException e) {
0853:                                    }
0854:                                    if (text == null) {
0855:                                        text = ")";
0856:                                    } // NOI18N
0857:                                }
0858:
0859:                            } else { // one or more parameters
0860:                                int activeParamIndex = getActiveParameterIndex();
0861:                                if (activeParamIndex != -1) { // Active parameter being shown
0862:                                    boolean substed = false;
0863:                                    if (activeParamIndex < parmsCnt) {
0864:                                        String paramName = ((ParamStr) params
0865:                                                .get(activeParamIndex))
0866:                                                .getName();
0867:                                        if (paramName != null) {
0868:                                            try {
0869:                                                // Fill in the parameter's name
0870:                                                doc.insertString(c
0871:                                                        .getCaretPosition(),
0872:                                                        paramName, null);
0873:                                                substed = true;
0874:                                            } catch (BadLocationException e) {
0875:                                                // Can't insert
0876:                                            }
0877:                                        }
0878:                                    }
0879:                                    return substed;
0880:                                }
0881:                                int ind = substituteExp.getParameterCount() - 1;
0882:                                boolean addSpace = CodeStyle.getDefault(doc)
0883:                                        .spaceAfterComma();
0884:                                try {
0885:                                    if (addSpace
0886:                                            && (ind == 0 || (offset > 0 && Character
0887:                                                    .isWhitespace(DocumentUtilities
0888:                                                            .getText(doc,
0889:                                                                    offset - 1,
0890:                                                                    1)
0891:                                                            .charAt(0))))) {
0892:                                        addSpace = false;
0893:                                    }
0894:                                } catch (BadLocationException e) {
0895:                                }
0896:
0897:                                boolean isVarArg = parmsCnt > 0 ? ((ParamStr) params
0898:                                        .get(parmsCnt - 1)).isVarArg()
0899:                                        : false;
0900:                                if (ind < parmsCnt || isVarArg) {
0901:                                    text = addSpace ? " " : ""; // NOI18N
0902:                                }
0903:                            }
0904:                            break;
0905:
0906:                        default:
0907:                            text = getItemText();
0908:                            boolean addSpace = CodeStyle.getDefault(doc)
0909:                                    .spaceBeforeMethodCallParen();//getFormatSpaceBeforeParenthesis();
0910:                            boolean addClosingParen = false;
0911:                            Formatter f = doc.getFormatter();
0912:                            if (f instanceof  ExtFormatter) {
0913:                                Object o = ((ExtFormatter) f)
0914:                                        .getSettingValue(SettingsNames.PAIR_CHARACTERS_COMPLETION);
0915:                                o = Settings
0916:                                        .getValue(
0917:                                                doc.getKitClass(),
0918:                                                SettingsNames.PAIR_CHARACTERS_COMPLETION);
0919:                                if ((o instanceof  Boolean)
0920:                                        && ((Boolean) o).booleanValue()) {
0921:                                    addClosingParen = true;
0922:                                }
0923:                            }
0924:
0925:                            if (addParams) {
0926:                                String paramsText = null;
0927:                                try {
0928:                                    int fnwpos = Utilities.getFirstNonWhiteFwd(
0929:                                            doc, offset + len);
0930:                                    if (fnwpos > -1
0931:                                            && fnwpos <= Utilities.getRowEnd(
0932:                                                    doc, offset + len)
0933:                                            && doc.getChars(fnwpos, 1)[0] == '(') { // NOI18N
0934:                                        paramsText = doc.getText(offset + len,
0935:                                                fnwpos + 1 - offset - len);
0936:                                        if (addSpace && paramsText.length() < 2) {
0937:                                            text += ' ';
0938:                                        } // NOI18N
0939:                                        len = fnwpos + 1 - offset;
0940:                                        text += paramsText;
0941:                                        toAdd = null; // do not add '.', ',', ';'
0942:                                    }
0943:                                } catch (BadLocationException e) {
0944:                                }
0945:                                if (paramsText == null) {
0946:                                    if (addSpace) {
0947:                                        text += ' '; // NOI18N
0948:                                    }
0949:                                    text += '('; // NOI18N
0950:                                    if (params.size() > 0) {
0951:                                        selectionStartOffset = selectionEndOffset = text
0952:                                                .length();
0953:                                        Completion completion = Completion
0954:                                                .get();
0955:                                        completion.hideCompletion();
0956:                                        completion.hideDocumentation();
0957:                                        completion.showToolTip();
0958:                                    }
0959:                                    if (addClosingParen) {
0960:                                        text += ")";
0961:                                    } // NOI18N
0962:                                } else {
0963:                                    try {
0964:                                        int fnwpos = Utilities
0965:                                                .getFirstNonWhiteFwd(doc,
0966:                                                        offset + len);
0967:                                        if (fnwpos > -1
0968:                                                && doc.getChars(fnwpos, 1)[0] == ')') { // NOI18N
0969:                                            paramsText = doc.getText(offset
0970:                                                    + len, fnwpos + 1 - offset
0971:                                                    - len);
0972:                                            len = fnwpos + 1 - offset;
0973:                                            if (params.size() > 0) {
0974:                                                selectionStartOffset = selectionEndOffset = text
0975:                                                        .length();
0976:                                            }
0977:                                            text += paramsText;
0978:                                        }
0979:                                    } catch (BadLocationException e) {
0980:                                    }
0981:                                }
0982:                            }
0983:                            break;
0984:                        }
0985:
0986:                        if (text != null) {
0987:                            if (toAdd != null && !toAdd.equals("\n")
0988:                                    && !"(".equals(toAdd)) // NOI18N
0989:                            {
0990:                                text += toAdd;
0991:                            }
0992:                            // Update the text
0993:                            doc.atomicLock();
0994:                            try {
0995:                                CharSequence textToReplace = DocumentUtilities
0996:                                        .getText(doc, offset, len);
0997:                                if (CharSequenceUtilities.textEquals(text,
0998:                                        textToReplace)) {
0999:                                    c.setCaretPosition(offset + len);
1000:                                    return false;
1001:                                }
1002:                                doc.remove(offset, len);
1003:                                doc.insertString(offset, text, null);
1004:                                if (selectionStartOffset >= 0) {
1005:                                    c.select(offset + selectionStartOffset,
1006:                                            offset + selectionEndOffset);
1007:                                } else if ("(".equals(toAdd)) { // NOI18N
1008:                                    int index = text.lastIndexOf(')');
1009:                                    if (index > -1) {
1010:                                        c.setCaretPosition(offset + index);
1011:                                    }
1012:                                }
1013:                            } catch (BadLocationException e) {
1014:                                // Can't update
1015:                            } finally {
1016:                                doc.atomicUnlock();
1017:                            }
1018:                            return true;
1019:                        } else {
1020:                            return false;
1021:                        }
1022:                    }
1023:                    return false;
1024:                }
1025:
1026:                public String getItemText() {
1027:                    // TODO review the output
1028:                    return ctr.getName().toString();
1029:                }
1030:
1031:                protected CsmPaintComponent.ConstructorPaintComponent createPaintComponent() {
1032:                    return new CsmPaintComponent.ConstructorPaintComponent();
1033:                }
1034:
1035:                public Component getPaintComponent(boolean isSelected) {
1036:                    if (ctrComponent == null) {
1037:                        ctrComponent = createPaintComponent();
1038:                    }
1039:                    ctrComponent.setName(getItemText());
1040:                    ctrComponent.setModifiers(getModifiers());
1041:                    ctrComponent.setParams(getParams());
1042:                    ctrComponent.setExceptions(getExceptions());
1043:                    ctrComponent.setSelected(isSelected);
1044:                    return ctrComponent;
1045:                }
1046:
1047:            }
1048:
1049:            public static class NamespaceAliasResultItem extends CsmResultItem {
1050:
1051:                private CsmNamespaceAlias alias;
1052:                private String aliasName;
1053:                private static CsmPaintComponent.NamespaceAliasPaintComponent aliasComponent;
1054:
1055:                public NamespaceAliasResultItem(CsmNamespaceAlias alias,
1056:                        boolean displayFullNamespacePath, int priotity) {
1057:                    super (alias, priotity);
1058:                    this .alias = alias;
1059:                    this .aliasName = alias.getAlias().toString();
1060:                }
1061:
1062:                public String getItemText() {
1063:                    return alias.getAlias().toString();
1064:                }
1065:
1066:                protected CsmPaintComponent.NamespaceAliasPaintComponent createPaintComponent() {
1067:                    return new CsmPaintComponent.NamespaceAliasPaintComponent();
1068:                }
1069:
1070:                public Component getPaintComponent(boolean isSelected) {
1071:                    if (aliasComponent == null) {
1072:                        aliasComponent = createPaintComponent();
1073:                    }
1074:                    aliasComponent.setSelected(isSelected);
1075:                    aliasComponent.setAliasName(aliasName);
1076:                    return aliasComponent;
1077:                }
1078:
1079:            }
1080:
1081:            public static class NamespaceResultItem extends CsmResultItem {
1082:
1083:                private boolean displayFullNamespacePath;
1084:                private CsmNamespace pkg;
1085:                private String pkgName;
1086:                private static CsmPaintComponent.NamespacePaintComponent pkgComponent;
1087:
1088:                public NamespaceResultItem(CsmNamespace pkg,
1089:                        boolean displayFullNamespacePath, int priotity) {
1090:                    super (pkg, priotity);
1091:                    this .pkg = pkg;
1092:                    this .displayFullNamespacePath = displayFullNamespacePath;
1093:                    this .pkgName = pkg.getName().toString();
1094:                }
1095:
1096:                public String getItemText() {
1097:                    return displayFullNamespacePath ? pkg.getQualifiedName()
1098:                            .toString() : pkg.getName().toString();
1099:                }
1100:
1101:                protected CsmPaintComponent.NamespacePaintComponent createPaintComponent() {
1102:                    return new CsmPaintComponent.NamespacePaintComponent();
1103:                }
1104:
1105:                public Component getPaintComponent(boolean isSelected) {
1106:                    if (pkgComponent == null) {
1107:                        pkgComponent = createPaintComponent();
1108:                    }
1109:                    pkgComponent.setSelected(isSelected);
1110:                    pkgComponent.setNamespaceName(pkgName);
1111:                    pkgComponent
1112:                            .setDisplayFullNamespacePath(displayFullNamespacePath);
1113:                    return pkgComponent;
1114:                }
1115:
1116:            }
1117:
1118:            public static class EnumResultItem extends CsmResultItem {
1119:
1120:                private CsmEnum enm;
1121:                private boolean isInterface;
1122:                private int classDisplayOffset;
1123:                private boolean isDeprecated;
1124:                private boolean displayFQN;
1125:
1126:                private static CsmPaintComponent.EnumPaintComponent enumComponent = null;
1127:
1128:                public EnumResultItem(CsmEnum enm, boolean displayFQN,
1129:                        int priotity) {
1130:                    this (enm, 0, displayFQN, priotity);
1131:                }
1132:
1133:                public EnumResultItem(CsmEnum enm, int classDisplayOffset,
1134:                        boolean displayFQN, int priotity) {
1135:                    super (enm, priotity);
1136:                    this .enm = enm;
1137:                    this .classDisplayOffset = classDisplayOffset;
1138:                    this .displayFQN = displayFQN;
1139:                }
1140:
1141:                protected String getName() {
1142:                    return enm.getName().toString();
1143:                }
1144:
1145:                protected String getReplaceText() {
1146:                    String text = getItemText();
1147:                    if (classDisplayOffset > 0
1148:                            && classDisplayOffset < text.length()) { // Only the last name for inner classes
1149:                        text = text.substring(classDisplayOffset);
1150:                    }
1151:                    return text;
1152:                }
1153:
1154:                public String getItemText() {
1155:                    return displayFQN ? enm.getQualifiedName().toString() : enm
1156:                            .getName().toString();
1157:                }
1158:
1159:                protected CsmPaintComponent.EnumPaintComponent createPaintComponent() {
1160:                    return new CsmPaintComponent.EnumPaintComponent();
1161:                }
1162:
1163:                public Component getPaintComponent(boolean isSelected) {
1164:                    if (enumComponent == null) {
1165:                        enumComponent = createPaintComponent();
1166:                    }
1167:                    enumComponent.setSelected(isSelected);
1168:                    enumComponent.setFormatEnumName(getName());
1169:                    return enumComponent;
1170:                }
1171:
1172:            }
1173:
1174:            public static class EnumeratorResultItem extends CsmResultItem {
1175:
1176:                private CsmEnumerator enmtr;
1177:                private int enumDisplayOffset;
1178:                private boolean isDeprecated;
1179:                private boolean displayFQN;
1180:
1181:                private static CsmPaintComponent.EnumeratorPaintComponent enumtrComponent = null;
1182:
1183:                public EnumeratorResultItem(CsmEnumerator enmtr,
1184:                        boolean displayFQN, int priotity) {
1185:                    this (enmtr, 0, displayFQN, priotity);
1186:                }
1187:
1188:                public EnumeratorResultItem(CsmEnumerator enmtr,
1189:                        int enumDisplayOffset, boolean displayFQN, int priotity) {
1190:                    super (enmtr, priotity);
1191:                    this .enmtr = enmtr;
1192:                    this .enumDisplayOffset = enumDisplayOffset;
1193:                    this .displayFQN = displayFQN;
1194:                }
1195:
1196:                protected String getName() {
1197:                    return enmtr.getName().toString();
1198:                }
1199:
1200:                protected String getReplaceText() {
1201:                    String text = getItemText();
1202:                    if (enumDisplayOffset > 0
1203:                            && enumDisplayOffset < text.length()) { // Only the last name for inner classes
1204:                        text = text.substring(enumDisplayOffset);
1205:                    }
1206:                    return text;
1207:                }
1208:
1209:                public String getItemText() {
1210:                    // TODO: do we need name of enum?
1211:                    return (displayFQN ? enmtr.getEnumeration()
1212:                            .getQualifiedName()
1213:                            + CsmCompletion.SCOPE : "")
1214:                            + enmtr.getName(); //NOI18N
1215:                }
1216:
1217:                protected CsmPaintComponent.EnumeratorPaintComponent createPaintComponent() {
1218:                    return new CsmPaintComponent.EnumeratorPaintComponent();
1219:                }
1220:
1221:                public Component getPaintComponent(boolean isSelected) {
1222:                    if (enumtrComponent == null) {
1223:                        enumtrComponent = createPaintComponent();
1224:                    }
1225:                    enumtrComponent.setSelected(isSelected);
1226:                    enumtrComponent.setFormatEnumeratorName(getName());
1227:                    return enumtrComponent;
1228:                }
1229:
1230:            }
1231:
1232:            public static class ClassResultItem extends CsmResultItem {
1233:
1234:                private CsmClass cls;
1235:                private CsmDeclaration.Kind kind;
1236:                private boolean isInterface;
1237:                private int classDisplayOffset;
1238:                private boolean isDeprecated;
1239:                private boolean displayFQN;
1240:
1241:                private static CsmPaintComponent.ClassPaintComponent clsComponent = null;
1242:                private static CsmPaintComponent.StructPaintComponent structComponent = null;
1243:                private static CsmPaintComponent.UnionPaintComponent unionComponent = null;
1244:
1245:                public ClassResultItem(CsmClass cls, boolean displayFQN,
1246:                        int priotity) {
1247:                    this (cls, 0, displayFQN, priotity);
1248:                }
1249:
1250:                public ClassResultItem(CsmClass cls, int classDisplayOffset,
1251:                        boolean displayFQN, int priotity) {
1252:                    super (cls, priotity);
1253:                    this .cls = cls;
1254:                    this .kind = cls.getKind();
1255:                    this .classDisplayOffset = classDisplayOffset;
1256:                    this .displayFQN = displayFQN;
1257:                }
1258:
1259:                protected String getName() {
1260:                    return cls.isTemplate() ? ((CsmTemplate) cls)
1261:                            .getDisplayName().toString() : cls.getName()
1262:                            .toString();
1263:                }
1264:
1265:                protected String getReplaceText() {
1266:                    String text = getItemText();
1267:                    if (classDisplayOffset > 0
1268:                            && classDisplayOffset < text.length()) { // Only the last name for inner classes
1269:                        text = text.substring(classDisplayOffset);
1270:                    }
1271:                    return text;
1272:                }
1273:
1274:                public String getItemText() {
1275:                    return displayFQN ? cls.getQualifiedName().toString()
1276:                            : getName();
1277:                }
1278:
1279:                protected CsmPaintComponent.StructPaintComponent createStructPaintComponent() {
1280:                    return new CsmPaintComponent.StructPaintComponent();
1281:                }
1282:
1283:                protected CsmPaintComponent.UnionPaintComponent createUnionPaintComponent() {
1284:                    return new CsmPaintComponent.UnionPaintComponent();
1285:                }
1286:
1287:                protected CsmPaintComponent.ClassPaintComponent createClassPaintComponent() {
1288:                    return new CsmPaintComponent.ClassPaintComponent();
1289:                }
1290:
1291:                public Component getPaintComponent(boolean isSelected) {
1292:                    if (kind == CsmDeclaration.Kind.STRUCT) {
1293:                        if (structComponent == null) {
1294:                            structComponent = createStructPaintComponent();
1295:                        }
1296:                        structComponent.setSelected(isSelected);
1297:                        structComponent.setFormatClassName(getName());
1298:                        return structComponent;
1299:                    } else if (kind == CsmDeclaration.Kind.UNION) {
1300:                        if (unionComponent == null) {
1301:                            unionComponent = createUnionPaintComponent();
1302:                        }
1303:                        unionComponent.setSelected(isSelected);
1304:                        unionComponent.setFormatClassName(getName());
1305:                        return unionComponent;
1306:                    } else {
1307:                        assert (kind == CsmDeclaration.Kind.CLASS) : "must be class kind";
1308:                        if (clsComponent == null) {
1309:                            clsComponent = createClassPaintComponent();
1310:                        }
1311:                        clsComponent.setSelected(isSelected);
1312:                        clsComponent.setFormatClassName(getName());
1313:                        return clsComponent;
1314:                    }
1315:                }
1316:
1317:            }
1318:
1319:            public static class TypedefResultItem extends CsmResultItem {
1320:
1321:                private CsmTypedef def;
1322:                private int defDisplayOffset;
1323:                private boolean isDeprecated;
1324:                private boolean displayFQN;
1325:
1326:                private static CsmPaintComponent.TypedefPaintComponent defComponent = null;
1327:
1328:                public TypedefResultItem(CsmTypedef def, boolean displayFQN,
1329:                        int priotity) {
1330:                    this (def, 0, displayFQN, priotity);
1331:                }
1332:
1333:                public TypedefResultItem(CsmTypedef def, int defDisplayOffset,
1334:                        boolean displayFQN, int priotity) {
1335:                    super (def, priotity);
1336:                    this .def = def;
1337:                    this .defDisplayOffset = defDisplayOffset;
1338:                    this .displayFQN = displayFQN;
1339:                }
1340:
1341:                protected String getName() {
1342:                    return def.getName().toString();
1343:                }
1344:
1345:                protected String getReplaceText() {
1346:                    String text = getItemText();
1347:                    if (defDisplayOffset > 0
1348:                            && defDisplayOffset < text.length()) { // Only the last name for inner classes
1349:                        text = text.substring(defDisplayOffset);
1350:                    }
1351:                    return text;
1352:                }
1353:
1354:                public String getItemText() {
1355:                    return displayFQN ? def.getQualifiedName().toString() : def
1356:                            .getName().toString();
1357:                }
1358:
1359:                protected CsmPaintComponent.TypedefPaintComponent createTypedefPaintComponent() {
1360:                    return new CsmPaintComponent.TypedefPaintComponent();
1361:                }
1362:
1363:                public Component getPaintComponent(boolean isSelected) {
1364:                    if (defComponent == null) {
1365:                        defComponent = createTypedefPaintComponent();
1366:                    }
1367:                    defComponent.setSelected(isSelected);
1368:                    defComponent.setFormatTypedefName(getName());
1369:                    return defComponent;
1370:                }
1371:
1372:            }
1373:
1374:            public static class StringResultItem extends CsmResultItem {
1375:
1376:                private String str;
1377:                private static CsmPaintComponent.StringPaintComponent stringComponent = null;
1378:
1379:                public StringResultItem(String str, int priotity) {
1380:                    super (null, priotity);
1381:                    this .str = str;
1382:                }
1383:
1384:                public String getItemText() {
1385:                    return str;
1386:                }
1387:
1388:                public Component getPaintComponent(boolean isSelected) {
1389:                    if (stringComponent == null) {
1390:                        stringComponent = createStringPaintComponent();
1391:                    }
1392:                    stringComponent.setSelected(isSelected);
1393:                    stringComponent.setString(str);
1394:                    return stringComponent;
1395:                }
1396:
1397:                public Object getAssociatedObject() {
1398:                    return str;
1399:                }
1400:
1401:                protected CsmPaintComponent.StringPaintComponent createStringPaintComponent() {
1402:                    return new CsmPaintComponent.StringPaintComponent();
1403:                }
1404:            }
1405:
1406:            //    static class ParamStr {
1407:            //        private String type, simpleType, prm;
1408:            //        private Color typeColor;
1409:            //        public ParamStr(String type, String simpleType, String prm, Color typeColor) {
1410:            //            this.type = type;
1411:            //            this.simpleType = simpleType;
1412:            //            this.prm = prm;
1413:            //            this.typeColor = typeColor;
1414:            //        }
1415:            //        
1416:            //        public String getTypeName() {
1417:            //            return type;
1418:            //        }
1419:            //        
1420:            //        public String getSimpleTypeName() {
1421:            //            return simpleType;
1422:            //        }
1423:            //        
1424:            //        public String getName() {
1425:            //            return prm;
1426:            //        }
1427:            //        
1428:            //        public Color getTypeColor() {
1429:            //            return typeColor;
1430:            //        }
1431:            //    }
1432:
1433:            //    static class ExcStr {
1434:            //        private String name;
1435:            //        private Color typeColor;
1436:            //        public ExcStr(String name, Color typeColor) {
1437:            //            this.name = name;
1438:            //            this.typeColor = typeColor;
1439:            //        }
1440:            //        
1441:            //        public String getName() {
1442:            //            return name;
1443:            //        }
1444:            //        
1445:            //        public Color getTypeColor() {
1446:            //            return typeColor;
1447:            //        }
1448:            //    }
1449:
1450:        }
w_w_w___.__ja__v___a2__s___.__c_o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.