1 19 20 package org.netbeans.modules.retouche.editor.codetemplates; 21 22 23 import java.io.IOException ; 24 import java.util.*; 25 import javax.swing.SwingUtilities ; 26 import javax.swing.text.JTextComponent ; 27 import org.netbeans.api.retouche.source.CompilationInfo; 28 29 import org.netbeans.lib.editor.codetemplates.spi.*; 30 import org.openide.ErrorManager; 31 32 41 public class GsfCodeTemplateProcessor implements CodeTemplateProcessor { 42 43 public static final String INSTANCE_OF = "instanceof"; public static final String ARRAY = "array"; public static final String ITERABLE = "iterable"; public static final String TYPE = "type"; public static final String ITERABLE_ELEMENT_TYPE = "iterableElementType"; public static final String LEFT_SIDE_TYPE = "leftSideType"; public static final String RIGHT_SIDE_TYPE = "rightSideType"; public static final String CAST = "cast"; public static final String NEW_VAR_NAME = "newVarName"; public static final String NAMED = "named"; 54 private static final String FALSE = "false"; private static final String NULL = "null"; 57 private CodeTemplateInsertRequest request; 58 59 private CompilationInfo cInfo = null; 60 private Map<CodeTemplateParameter, String > param2hints = new HashMap<CodeTemplateParameter, String >(); 65 68 private GsfCodeTemplateProcessor(CodeTemplateInsertRequest request) { 69 this.request = request; 70 } 71 72 73 public synchronized void updateDefaultValues() { 74 boolean cont = true; 75 while (cont) { 76 cont = false; 77 for (Object p : request.getMasterParameters()) { 78 CodeTemplateParameter param = (CodeTemplateParameter)p; 79 String value = getProposedValue(param); 80 if (value != null && !value.equals(param.getValue())) { 81 param.setValue(value); 82 cont = true; 83 } 84 } 85 } 86 } 98 public void parameterValueChanged(CodeTemplateParameter masterParameter, boolean typingChange) { 100 } 124 public void release() { 126 } 153 154 private String getProposedValue(CodeTemplateParameter param) { 156 String name = null; 159 for (Object e : param.getHints().entrySet()) { 160 Map.Entry entry = (Map.Entry)e; 161 if (INSTANCE_OF.equals(entry.getKey())) { 162 } else if (NEW_VAR_NAME.equals(entry.getKey())) { 252 param2hints.put(param, NEW_VAR_NAME); 253 return newVarName(param.getInsertTextOffset() + 1); 254 } else if (NAMED.equals(entry.getKey())) { 255 name = param.getName(); 256 } 257 } 258 return null; 259 } 260 private String newVarName(int caretOffset) { 464 try { 465 } catch (Exception e) { 482 } 483 return null; 484 } 485 486 559 public static final class Factory implements CodeTemplateProcessorFactory { 560 public CodeTemplateProcessor createProcessor(CodeTemplateInsertRequest request) { 561 return new GsfCodeTemplateProcessor(request); 562 } 563 } 564 } 565 | Popular Tags |