1 /*2 * The contents of this file are subject to the terms of the Common Development3 * and Distribution License (the License). You may not use this file except in4 * compliance with the License.5 *6 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html7 * or http://www.netbeans.org/cddl.txt.8 *9 * When distributing Covered Code, include this CDDL Header Notice in each file10 * and include the License file at http://www.netbeans.org/cddl.txt.11 * If applicable, add the following below the CDDL Header, with the fields12 * enclosed by brackets [] replaced by your own identifying information:13 * "Portions Copyrighted [year] [name of copyright owner]"14 *15 * The Original Software is NetBeans. The Initial Developer of the Original16 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun17 * Microsystems, Inc. All Rights Reserved.18 */19 20 package org.netbeans.modules.websvc.editor.completion;21 22 import java.util.ArrayList ;23 import java.util.Collection ;24 import java.util.List ;25 import javax.swing.text.BadLocationException ;26 import javax.swing.text.JTextComponent ;27 import org.netbeans.editor.TokenItem;28 import org.netbeans.editor.ext.CompletionQuery;29 import org.netbeans.editor.ext.Completion;30 import org.netbeans.editor.ext.ExtEditorUI;31 import org.netbeans.editor.BaseDocument;32 import org.netbeans.editor.Utilities;33 // Retouche34 //import org.netbeans.editor.ext.java.JCExpression;35 //import org.netbeans.editor.ext.java.JCFinder;36 //import org.netbeans.editor.ext.java.JavaCompletionQuery;37 //import org.netbeans.editor.ext.java.JavaSyntaxSupport;38 //import org.netbeans.editor.ext.java.JavaTokenContext;39 //import org.netbeans.jmi.javamodel.*;40 //import org.netbeans.modules.editor.java.JCFinderFactory;41 //import org.netbeans.modules.editor.java.NbJavaJMISyntaxSupport;42 //import org.netbeans.modules.javacore.JMManager;43 import org.netbeans.modules.editor.NbEditorUtilities;44 import org.openide.filesystems.FileObject;45 import org.openide.loaders.DataObject;46 47 /**48 * Completion query for JSR-181 (Webservice Metadata) aNNotations.49 *50 * @author Marek Fukala51 * @author Dusan Balek52 */53 public class WSCompletionQuery /*extends JavaCompletionQuery*/ {54 55 private static final String WEBSERVICE_NN = "WebService";//NOI18N56 private static final String HANDLER_CHAIN_NN = "HandlerChain";//NOI18N57 58 private List resolvers;59 60 public WSCompletionQuery(boolean isJava15) {61 // Retouche 62 // setJava15(isJava15);63 }64 // Retouche 65 // protected JCFinder getFinder() {66 // FileObject fo = getFileObject();67 // return JCFinderFactory.getDefault().getFinder(fo);68 // }69 // 70 // protected CompletionQuery.Result getResult(JTextComponent component, JavaSyntaxSupport sup, boolean openingSource, int offset, JCExpression exp) {71 // Completion completion = ((ExtEditorUI)Utilities.getEditorUI(component)).getCompletion();72 // boolean autoPopup = completion != null ? completion.provokedByAutoPopup : false;73 // JMIUtils utils = JMIUtils.get(getBaseDocument());74 // utils.beginTrans(false);75 // try {76 // ((JMManager) JMManager.getManager()).setSafeTrans(true);77 // Context ctx = new Context(component, (NbJavaJMISyntaxSupport)sup.get(NbJavaJMISyntaxSupport.class), openingSource, offset, utils, autoPopup);78 // boolean ok = ctx.resolveExp(exp);79 // return ok ? ctx.result : null;80 // } finally {81 // utils.endTrans(false);82 // }83 // }84 // 85 // private FileObject getFileObject() {86 // BaseDocument bDoc = getBaseDocument();87 // DataObject dobj = NbEditorUtilities.getDataObject(bDoc);88 // return dobj.getPrimaryFile();89 // }90 // 91 // private final class Context {92 // 93 // /** Text component */94 // private JTextComponent component;95 // 96 // /** Syntax support for the given document */97 // private NbJavaJMISyntaxSupport sup;98 // 99 // /** Whether the query is performed to open the source file. It has slightly100 // * different handling in some situations.101 // */102 // private boolean openingSource;103 // 104 // /** End position of the scanning - usually the caret position */105 // private int endOffset;106 // 107 // /** If set to true true - find the type of the result expression.108 // * It's stored in the lastType variable or lastPkg if it's a package.109 // * The result variable is not populated.110 // * False means that the code completion output should be collected.111 // */112 // private boolean findType;113 // 114 // /** Whether currently scanning either the package or the class name115 // * so the results should limit the search to the static fields and methods.116 // */117 // private boolean staticOnly = true;118 // 119 // /** Last package found when scanning dot expression */120 // private JavaPackage lastPkg;121 // 122 // /** Last type found when scanning dot expression */123 // private Type lastType;124 // 125 // /** Result list when code completion output is generated */126 // private DefaultResult result;127 // 128 // /** Helper flag for recognizing constructors */129 // private boolean isConstructor;130 // 131 // private boolean isImport;132 // private boolean isStaticImport;133 // 134 // private boolean isGeneric;135 // private Collection typeBounds;136 // 137 // private boolean isAnnotation;138 // private boolean isAnnotationOpen;139 // 140 // private JavaClass curCls;141 // 142 // /** True when code completion is invoked by auto popup. In such case, code completion returns no result143 // * after "new ". To get a result, code completion has to be invoked manually (using Ctrl-Space). */ // NOI18N144 // private boolean autoPopup;145 // 146 // /** Finder associated with this Context. */147 // private JMIUtils jmiUtils = null;148 // 149 // public Context(JTextComponent component, NbJavaJMISyntaxSupport sup, boolean openingSource, int endOffset, JMIUtils utils, boolean autoPopup) {150 // 151 // this.component = component;152 // this.sup = sup;153 // this.openingSource = openingSource;154 // this.endOffset = endOffset;155 // this.jmiUtils = utils;156 // this.curCls = sup.getJavaClass(endOffset);157 // if (this.curCls == null) {158 // this.curCls = sup.getTopJavaClass();159 // }160 // this.autoPopup = autoPopup;161 // }162 // 163 // boolean resolveExp(JCExpression exp) {164 // //System.out.println(exp);165 // switch (exp.getExpID()) {166 // case JCExpression.ANNOTATION_OPEN:167 // String annotationName = getAnnotationTypeName(exp);168 // resolveCompletionContext(annotationName, getCompletedMemberName(exp), "");169 // break;170 // case JCExpression.CONSTANT:171 // //JCTokenProcessor hack - we cannot easily get an information about the current context172 // resolveConstantExpression(exp);173 // break;174 // }175 // return true;176 // }177 // 178 // private void resolveConstantExpression(JCExpression exp) {179 // NNParser parser = new NNParser(getBaseDocument());180 // NNParser.NN nn = parser.parseAnnotation(endOffset);181 // //XXX I should improve the NNParser to provide the offset data!182 // //temp - parse backward and look for the attribute name183 // if(nn != null) {184 // try {185 // TokenItem ti = sup.getTokenChain(endOffset -1, endOffset);186 // if(ti.getTokenID() == JavaTokenContext.STRING_LITERAL) {187 // ti = ti.getPrevious();188 // if(ti.getTokenID() == JavaTokenContext.WHITESPACE) ti = ti.getPrevious();189 // if(ti.getTokenID() == JavaTokenContext.EQ) {190 // ti = ti.getPrevious();191 // if(ti.getTokenID() == JavaTokenContext.WHITESPACE) ti = ti.getPrevious();192 // if(ti.getTokenID() == JavaTokenContext.IDENTIFIER) {193 // //probably the attribute name194 // String attrName = ti.getImage();195 // String value = exp.getTokenText(0);196 // resolveCompletionContext(nn.getName(), attrName, value);197 // }198 // }199 // }200 // 201 // }catch(BadLocationException ble) {202 // ble.printStackTrace();203 // }204 // }205 // 206 // 207 // }208 // 209 // private void resolveCompletionContext(String annotationName, String attrName, String attrValue) {210 // if (WEBSERVICE_NN.equals(annotationName)) { // NOI18N211 // completeWebService(attrName, attrValue);212 // } else if (HANDLER_CHAIN_NN.equals(annotationName)) {213 // completeHandlerChain(attrName, attrValue);214 // }215 // }216 // 217 // 218 // private String getCompletedMemberName(JCExpression exp) {219 // int parCnt = exp.getParameterCount();220 // if (parCnt <= 0) {221 // return null;222 // }223 // 224 // JCExpression lastMember = exp.getParameter(parCnt - 1);225 // if (lastMember.getParameterCount() < 2) {226 // return null;227 // }228 // JCExpression lastMemberParm1 = lastMember.getParameter(1);229 // // trying to ensure that lastMember is something like name= and not something like name=foo230 // if (lastMemberParm1.getExpID() != JCExpression.VARIABLE || lastMemberParm1.getTokenText(0).length() > 0) {231 // return null;232 // }233 // 234 // String completedMember = lastMember.getParameter(0).getTokenText(0);235 // 236 // return completedMember;237 // }238 // 239 // private void completeWebService(String attributeName, String completedAttributeValue) {240 // if ("wsdlLocation".equals(attributeName)) { // NOI18N241 // List results = results = new ArrayList();242 // results.addAll(FileAttributeSupport.completionResults(endOffset, sup, getBaseDocument(), completedAttributeValue, true));243 // result = new CompletionQuery.DefaultResult(component, "*", results, /*exp.getTokenOffset(0)*/0, 0); // NOI18N244 // }245 // }246 // 247 // private void completeHandlerChain(String attributeName, String completedAttributeValue) {248 // if ("file".equals(attributeName)) { // NOI18N249 // List results = results = new ArrayList();250 // results.addAll(FileAttributeSupport.completionResults(endOffset, sup, getBaseDocument(), completedAttributeValue, false));251 // result = new CompletionQuery.DefaultResult(component, "*", results, /*exp.getTokenOffset(0)*/0, 0); // NOI18N252 // }253 // }254 // 255 // private String getAnnotationTypeName(JCExpression exp) {256 // assert exp != null;257 // 258 // String result = null;259 // 260 // if (exp.getParameterCount() < 1) {261 // return result;262 // }263 // JCExpression variable = exp.getParameter(0);264 // if (variable.getExpID() != JCExpression.VARIABLE) {265 // return result;266 // }267 // // XXX this does not count with an annotation type written like "javax.persistence.Table"268 // // should try to resolve the annotation type269 // result = variable.getTokenText(0);270 // return result;271 // }272 // 273 // 274 // }275 276 }277