1 11 package org.eclipse.ant.internal.ui.editor.templates; 12 13 import java.util.Arrays ; 14 import java.util.Comparator ; 15 16 import org.eclipse.jface.text.templates.TemplateContext; 17 import org.eclipse.jface.text.templates.TemplateVariableResolver; 18 19 23 public class AntVariableResolver extends TemplateVariableResolver { 24 27 protected String [] resolveAll(TemplateContext context) { 28 String [] proposals= new String [] { "${srcDir}", "${dstDir}" }; 30 Arrays.sort(proposals, new Comparator () { 31 32 public int compare(Object o1, Object o2) { 33 return getCommonPrefixLength(getType(), (String ) o2) - getCommonPrefixLength(getType(), (String ) o1); 34 } 35 36 private int getCommonPrefixLength(String type, String var) { 37 int i= 0; 38 CharSequence vSeq= var.subSequence(2, var.length() - 1); while (i < type.length() && i < vSeq.length()) 40 if (Character.toLowerCase(type.charAt(i)) == Character.toLowerCase(vSeq.charAt(i))) 41 i++; 42 else 43 break; 44 return i; 45 } 46 }); 47 48 return proposals; 49 } 50 } 51 | Popular Tags |