Source Code Cross Referenced for ASTBasedProvider.java in  » IDE-Netbeans » languages » org » netbeans » modules » php » editor » completion » 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 » languages » org.netbeans.modules.php.editor.completion 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.php.editor.completion;
043:
044:        import java.io.IOException;
045:        import java.util.Collections;
046:        import java.util.ConcurrentModificationException;
047:        import java.util.Set;
048:        import javax.swing.text.Document;
049:        import org.netbeans.modules.gsf.api.HtmlFormatter;
050:        import org.netbeans.api.lexer.Token;
051:        import org.netbeans.api.lexer.TokenSequence;
052:        import org.netbeans.modules.php.editor.TokenUtils;
053:        import org.netbeans.modules.php.model.PhpModel;
054:
055:        /**
056:         *
057:         * @author Victor G. Vasilyev 
058:         */
059:        public abstract class ASTBasedProvider {
060:            protected CodeCompletionContext myContext;
061:
062:            @SuppressWarnings("unchecked")
063:            protected static final Set<ExpectedToken> ANY_TOKEN = Collections.EMPTY_SET;
064:
065:            /**
066:             * A service that is used as the key to recognize a given project as the
067:             * PHP Project.
068:             */
069:            //    private static final Class PHP_PROJECT_KEY_SERVICE = null;
070:            /**
071:             * Wrapps info about expected token.
072:             */
073:            protected static class ExpectedToken {
074:                private String type;
075:                private String text;
076:
077:                /**
078:                 * Creates wrapper.
079:                 * @param type expected type of the token (non-null value)
080:                 * @param text expected text of the token, <code>null</code> means any 
081:                 * text.
082:                 */
083:                public ExpectedToken(String type, String text) {
084:                    assert type != null;
085:                    this .type = type;
086:                    this .text = text;
087:                }
088:
089:                public String getType() {
090:                    return type;
091:                }
092:
093:                public String getText() {
094:                    return text;
095:                }
096:
097:                public boolean isAnyText() {
098:                    return text == null;
099:                }
100:            }
101:
102:            /**
103:             *  
104:             * @param c the set of expected tokens in the current position.
105:             * @param l1 the set of expected tokens in the previous position.
106:             * @return <code>true</code> if expected tokens are matched.
107:             */
108:            protected boolean isMatchedCL1(Set<ExpectedToken> c,
109:                    Set<ExpectedToken> l1) {
110:                try {
111:                    TokenSequence ts = getTokenSequencePHP();
112:                    Token t = TokenUtils.getEnteredToken(ts, getCaretOffset());
113:                    if (c != ANY_TOKEN) {
114:                        assertOneOf(t, c);
115:                    }
116:                    if (l1 != ANY_TOKEN) {
117:                        boolean hasPreviousToken = ts.movePrevious();
118:                        if (hasPreviousToken) {
119:                            t = ts.token();
120:                            assertOneOf(t, l1);
121:                        }
122:                    }
123:                    return true;
124:                } catch (IOException ioe) {
125:                    return false; // getDocument() fails
126:                } catch (ConcurrentModificationException cme) {
127:                    // the token sequence is no longer valid because of an underlying 
128:                    // mutable input source modification.
129:                    return false;
130:                } catch (Exception e) {
131:                    return false;
132:                }
133:            }
134:
135:            /**
136:             * Returns the <code>TokenSequence</code> of the PHP block pointed by 
137:             * the caret offset of the <code>CodeCompletionContext</code>.
138:             * @return the <code>TokenSequence</code> of the PHP block.
139:             * @throws java.io.IOException if {@link #getDocument()} fails
140:             * @throws java.lang.Exception if pointed code is not a PHP block or 
141:             * <code>TokenSequence</code> can't be returned for this code.
142:             */
143:            protected TokenSequence getTokenSequencePHP() throws IOException,
144:                    Exception {
145:                assertPHPContext();
146:                Document doc = getDocument();
147:                int offset = getCaretOffset();
148:                TokenSequence ts = TokenUtils.getEmbeddedTokenSequence(doc,
149:                        offset);
150:                if (ts == null) {
151:                    throw new Exception();
152:                }
153:                return ts;
154:
155:            }
156:
157:            /**
158:             * Assert that a given <code>CodeCompletionContext</code> in the scope of a 
159:             * PHP project.
160:             * @throws java.lang.Exception if a given <code>CodeCompletionContext</code> 
161:             * is not in the scope of a PHP project.
162:             */
163:            protected void assertPHPProject() throws Exception {
164:                //        FileObject fo = myContext.getCompilationInfo().getFileObject();
165:                //        Project project = FileOwnerQuery.getOwner(fo);
166:                //        if (project == null || 
167:                //                project.getLookup().lookup(PHP_PROJECT_KEY_SERVICE) == null) {
168:                throw new Exception();
169:                //        }
170:            }
171:
172:            /**
173:             * Assert that a given <code>CodeCompletionContext</code> in the file that 
174:             * has a MIME type registered in the IDE for PHP processing.
175:             * @throws java.lang.Exception if a given <code>CodeCompletionContext</code> 
176:             * is not in the in the file that has a MIME type registered in the IDE for 
177:             * PHP processing.
178:             */
179:            protected void assertMIMETypePHP() throws Exception {
180:                String type = myContext.getCompilationInfo().getFileObject()
181:                        .getMIMEType();
182:                if (!type.equals("text/x-php5")) {
183:                    throw new Exception();
184:                }
185:            }
186:
187:            protected void assertPHPContext() throws IOException, Exception {
188:                Document doc = getDocument();
189:                int offset = getCaretOffset();
190:                if (!TokenUtils.checkPhp(doc, offset)) {
191:                    throw new Exception();
192:                }
193:            }
194:
195:            protected void assertWhitespace(Token t) throws Exception {
196:                if (!TokenUtils.PHPTokenName.WHITESPACE.value().equals(
197:                        TokenUtils.getTokenType(t))) {
198:                    throw new Exception();
199:                }
200:            }
201:
202:            protected void assertOneOf(Token t, Set<ExpectedToken> tokenSet)
203:                    throws Exception {
204:                String tType = TokenUtils.getTokenType(t);
205:                String tText = t.text().toString();
206:                for (ExpectedToken et : tokenSet) {
207:                    if (et.getType().equals(tType)) {
208:                        String etText = et.getText();
209:                        if (et.isAnyText()) {
210:                            return;
211:                        }
212:                        if (etText.equals(tText)) {
213:                            return;
214:                        }
215:                    }
216:                }
217:                throw new Exception();
218:            }
219:
220:            protected Document getDocument() throws IOException {
221:                return myContext.getCompilationInfo().getDocument();
222:            }
223:
224:            protected int getCaretOffset() {
225:                return myContext.getCaretOffset();
226:            }
227:
228:            protected HtmlFormatter getFormatter() {
229:                return myContext.getFormatter();
230:            }
231:
232:            protected PhpModel getModel() {
233:                return myContext.getSourceElement().getModel();
234:            }
235:
236:            protected void checkContext(CodeCompletionContext context)
237:                    throws IllegalStateException {
238:                if (context != myContext) {
239:                    throw new IllegalStateException(
240:                            "The isApplicable method MUST BE called before.");
241:                }
242:            }
243:
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.