1 11 package org.eclipse.jface.text.templates; 12 13 import org.eclipse.core.runtime.Assert; 14 15 25 public class TemplateVariableResolver { 26 27 28 private String fType= null; 29 30 31 private String fDescription= null; 32 33 39 protected TemplateVariableResolver(String type, String description) { 40 setType(type); 41 setDescription(description); 42 } 43 44 53 public TemplateVariableResolver() { 54 } 55 56 61 public String getType() { 62 return fType; 63 } 64 65 70 public String getDescription() { 71 return fDescription; 72 } 73 74 84 protected String resolve(TemplateContext context) { 85 return context.getVariable(getType()); 86 } 87 88 97 protected String [] resolveAll(TemplateContext context) { 98 String binding= resolve(context); 99 if (binding == null) 100 return new String [0]; 101 return new String [] { binding }; 102 } 103 104 113 public void resolve(TemplateVariable variable, TemplateContext context) { 114 String [] bindings= resolveAll(context); 115 if (bindings.length != 0) 116 variable.setValues(bindings); 117 if (bindings.length > 1) 118 variable.setUnambiguous(false); 119 else 120 variable.setUnambiguous(isUnambiguous(context)); 121 variable.setResolved(true); 122 } 123 124 137 protected boolean isUnambiguous(TemplateContext context) { 138 return false; 139 } 140 141 151 public final void setDescription(String description) { 152 Assert.isNotNull(description); 153 Assert.isTrue(fDescription == null); fDescription= description; 155 } 156 157 167 public final void setType(String type) { 168 Assert.isNotNull(type); 169 Assert.isTrue(fType == null); fType= type; 171 } 172 } 173 | Popular Tags |