001 package org.crsh.cmdline.matcher.impl;
002
003 import org.crsh.cmdline.ClassDescriptor;
004 import org.crsh.cmdline.MethodDescriptor;
005 import org.crsh.cmdline.matcher.CmdCompletionException;
006 import org.crsh.cmdline.matcher.tokenizer.Termination;
007
008 import java.util.HashMap;
009 import java.util.Map;
010
011 /**
012 * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
013 */
014 class MethodCompletion<T> extends Completion {
015
016 /** . */
017 private final ClassDescriptor<T> descriptor;
018
019 /** . */
020 private final String mainName;
021
022 /** . */
023 private final String prefix;
024
025 /** . */
026 private final Termination termination;
027
028 MethodCompletion(ClassDescriptor<T> descriptor, String mainName, String prefix, Termination termination) {
029 this.descriptor = descriptor;
030 this.mainName = mainName;
031 this.prefix = prefix;
032 this.termination = termination;
033 }
034
035 @Override
036 protected Map<String, String> complete() throws CmdCompletionException {
037 Map<String, String> completions = new HashMap<String, String>();
038 for (MethodDescriptor<?> m : descriptor.getMethods()) {
039 String name = m.getName();
040 if (name.startsWith(prefix)) {
041 if (!name.equals(mainName)) {
042 completions.put(name.substring(prefix.length()), termination.getEnd());
043 }
044 }
045 }
046 return completions;
047 }
048 }