Source Code Cross Referenced for JavaTypeCompletionProcessor.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » refactoring » contentassist » 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 Eclipse » jdt » org.eclipse.jdt.internal.ui.refactoring.contentassist 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.ui.refactoring.contentassist;
011:
012:        import java.util.Arrays;
013:        import java.util.List;
014:
015:        import org.eclipse.jdt.core.CompletionProposal;
016:        import org.eclipse.jdt.core.ICompilationUnit;
017:        import org.eclipse.jdt.core.IJavaElement;
018:        import org.eclipse.jdt.core.IPackageFragment;
019:        import org.eclipse.jdt.core.IType;
020:        import org.eclipse.jdt.core.Signature;
021:
022:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
023:        import org.eclipse.jdt.internal.corext.util.TypeFilter;
024:
025:        import org.eclipse.jdt.internal.ui.JavaPluginImages;
026:        import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
027:
028:        public class JavaTypeCompletionProcessor extends
029:                CUPositionCompletionProcessor {
030:
031:            public static final String DUMMY_CLASS_NAME = "$$__$$"; //$NON-NLS-1$
032:
033:            /**
034:             * The CU name to be used if no parent ICompilationUnit is available.
035:             * The main type of this class will be filtered out from the proposals list.
036:             */
037:            public static final String DUMMY_CU_NAME = DUMMY_CLASS_NAME
038:                    + JavaModelUtil.DEFAULT_CU_SUFFIX;
039:
040:            /**
041:             * Creates a <code>JavaTypeCompletionProcessor</code>.
042:             * The completion context must be set via {@link #setPackageFragment(IPackageFragment)}.
043:             * 
044:             * @param enableBaseTypes complete java base types iff <code>true</code>
045:             * @param enableVoid complete <code>void</code> base type iff <code>true</code>
046:             */
047:            public JavaTypeCompletionProcessor(boolean enableBaseTypes,
048:                    boolean enableVoid) {
049:                this (enableBaseTypes, enableVoid, false);
050:            }
051:
052:            /**
053:             * Creates a <code>JavaTypeCompletionProcessor</code>.
054:             * The completion context must be set via {@link #setPackageFragment(IPackageFragment)}.
055:             * 
056:             * @param enableBaseTypes complete java base types iff <code>true</code>
057:             * @param enableVoid complete <code>void</code> base type iff <code>true</code>
058:             * @param fullyQualify always complete to fully qualifies type iff <code>true</code>
059:             */
060:            public JavaTypeCompletionProcessor(boolean enableBaseTypes,
061:                    boolean enableVoid, boolean fullyQualify) {
062:                super (new TypeCompletionRequestor(enableBaseTypes, enableVoid,
063:                        fullyQualify));
064:            }
065:
066:            public char[] getCompletionProposalAutoActivationCharacters() {
067:                // disable auto activation in dialog fields, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89476
068:                return null;
069:            }
070:
071:            /**
072:             * @param packageFragment the new completion context
073:             */
074:            public void setPackageFragment(IPackageFragment packageFragment) {
075:                //TODO: Some callers have a better completion context and should include imports
076:                // and nested classes of their declaring CU in WC's source.
077:                if (packageFragment == null) {
078:                    setCompletionContext(null, null, null);
079:                } else {
080:                    String before = "public class " + DUMMY_CLASS_NAME + " { "; //$NON-NLS-1$//$NON-NLS-2$
081:                    String after = " }"; //$NON-NLS-1$
082:                    setCompletionContext(packageFragment
083:                            .getCompilationUnit(DUMMY_CU_NAME), before, after);
084:                }
085:            }
086:
087:            public void setExtendsCompletionContext(IJavaElement javaElement) {
088:                if (javaElement instanceof  IPackageFragment) {
089:                    IPackageFragment packageFragment = (IPackageFragment) javaElement;
090:                    ICompilationUnit cu = packageFragment
091:                            .getCompilationUnit(DUMMY_CU_NAME);
092:                    setCompletionContext(
093:                            cu,
094:                            "public class " + DUMMY_CLASS_NAME + " extends ", " {}"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
095:                } else if (javaElement instanceof  IType) {
096:                    // pattern: public class OuterType { public class Type extends /*caret*/  {} }
097:                    IType type = (IType) javaElement;
098:                    String before = "public class " + type.getElementName() + " extends "; //$NON-NLS-1$ //$NON-NLS-2$
099:                    String after = " {}"; //$NON-NLS-1$
100:                    IJavaElement parent = type.getParent();
101:                    while (parent instanceof  IType) {
102:                        type = (IType) parent;
103:                        before += "public class " + type.getElementName() + " {"; //$NON-NLS-1$ //$NON-NLS-2$
104:                        after += "}"; //$NON-NLS-1$
105:                        parent = type.getParent();
106:                    }
107:                    ICompilationUnit cu = type.getCompilationUnit();
108:                    setCompletionContext(cu, before, after);
109:                } else {
110:                    setCompletionContext(null, null, null);
111:                }
112:            }
113:
114:            //	public void setImplementsCompletionContext(IPackageFragment packageFragment) {
115:            //		ICompilationUnit cu= packageFragment.getCompilationUnit(DUMMY_CU_NAME);
116:            //		setCompletionContext(cu, "public class " + DUMMY_CLASS_NAME + " implements ", " {}"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
117:            //	}
118:
119:            protected static class TypeCompletionRequestor extends
120:                    CUPositionCompletionRequestor {
121:                private static final String VOID = "void"; //$NON-NLS-1$
122:                private static final List BASE_TYPES = Arrays
123:                        .asList(new String[] {
124:                                "boolean", "byte", "char", "double", "float", "int", "long", "short" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
125:
126:                private boolean fEnableBaseTypes;
127:                private boolean fEnableVoid;
128:                private final boolean fFullyQualify;
129:
130:                public TypeCompletionRequestor(boolean enableBaseTypes,
131:                        boolean enableVoid, boolean fullyQualify) {
132:                    fFullyQualify = fullyQualify;
133:                    fEnableBaseTypes = enableBaseTypes;
134:                    fEnableVoid = enableVoid;
135:                    setIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION,
136:                            true);
137:                    setIgnored(CompletionProposal.FIELD_REF, true);
138:                    setIgnored(CompletionProposal.LABEL_REF, true);
139:                    setIgnored(CompletionProposal.LOCAL_VARIABLE_REF, true);
140:                    setIgnored(CompletionProposal.METHOD_DECLARATION, true);
141:                    setIgnored(CompletionProposal.METHOD_REF, true);
142:                    setIgnored(CompletionProposal.VARIABLE_DECLARATION, true);
143:                    setIgnored(CompletionProposal.POTENTIAL_METHOD_DECLARATION,
144:                            true);
145:                    setIgnored(CompletionProposal.METHOD_NAME_REFERENCE, true);
146:                }
147:
148:                public void accept(CompletionProposal proposal) {
149:                    switch (proposal.getKind()) {
150:                    case CompletionProposal.PACKAGE_REF:
151:                        char[] packageName = proposal.getDeclarationSignature();
152:                        if (TypeFilter.isFiltered(packageName))
153:                            return;
154:                        addAdjustedCompletion(new String(packageName),
155:                                new String(proposal.getCompletion()), proposal
156:                                        .getReplaceStart(), proposal
157:                                        .getReplaceEnd(), proposal
158:                                        .getRelevance(),
159:                                JavaPluginImages.DESC_OBJS_PACKAGE);
160:                        return;
161:
162:                    case CompletionProposal.TYPE_REF:
163:                        char[] fullName = Signature.toCharArray(proposal
164:                                .getSignature());
165:                        if (TypeFilter.isFiltered(fullName))
166:                            return;
167:                        StringBuffer buf = new StringBuffer();
168:                        buf.append(Signature.getSimpleName(fullName));
169:                        if (buf.length() == 0)
170:                            return; // this is the dummy class, whose $ have been converted to dots
171:                        char[] typeQualifier = Signature.getQualifier(fullName);
172:                        if (typeQualifier.length > 0) {
173:                            buf.append(" - "); //$NON-NLS-1$
174:                            buf.append(typeQualifier);
175:                        }
176:                        String name = buf.toString();
177:
178:                        addAdjustedTypeCompletion(name, new String(proposal
179:                                .getCompletion()), proposal.getReplaceStart(),
180:                                proposal.getReplaceEnd(), proposal
181:                                        .getRelevance(),
182:                                JavaElementImageProvider
183:                                        .getTypeImageDescriptor(false, false,
184:                                                proposal.getFlags(), false),
185:                                fFullyQualify ? new String(fullName) : null);
186:                        return;
187:
188:                    case CompletionProposal.KEYWORD:
189:                        if (!fEnableBaseTypes)
190:                            return;
191:                        String keyword = new String(proposal.getName());
192:                        if ((fEnableVoid && VOID.equals(keyword))
193:                                || (fEnableBaseTypes && BASE_TYPES
194:                                        .contains(keyword)))
195:                            addAdjustedCompletion(keyword, new String(proposal
196:                                    .getCompletion()), proposal
197:                                    .getReplaceStart(), proposal
198:                                    .getReplaceEnd(), proposal.getRelevance(),
199:                                    null);
200:                        return;
201:
202:                    default:
203:                        return;
204:                    }
205:
206:                }
207:            }
208:        }
ww___w._j__a_va_2___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.