Example usage for org.apache.commons.lang3 StringUtils startsWithIgnoreCase

List of usage examples for org.apache.commons.lang3 StringUtils startsWithIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils startsWithIgnoreCase.

Prototype

public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix) 

Source Link

Document

Case insensitive check if a CharSequence starts with a specified prefix.

null s are handled without exceptions.

Usage

From source file:org.eclipse.php.internal.core.codeassist.strategies.MethodNameStrategy.java

public void apply(ICompletionReporter reporter) throws BadLocationException {
    ICompletionContext context = getContext();
    if (!(context instanceof MethodNameContext)) {
        return;//from   www  .  j a va 2  s .  co m
    }

    MethodNameContext concreteContext = (MethodNameContext) context;
    CompletionRequestor requestor = concreteContext.getCompletionRequestor();

    String prefix = concreteContext.getPrefix();
    boolean exactName = requestor.isContextInformationMode();
    IType declaringClass = concreteContext.getDeclaringClass();

    String suffix = getSuffix(concreteContext);
    ISourceRange replaceRange = null;
    if (suffix.equals("")) { //$NON-NLS-1$
        replaceRange = getReplacementRange(concreteContext);
    } else {
        replaceRange = getReplacementRangeWithBraces(concreteContext);
    }

    try {
        ITypeHierarchy hierarchy = getCompanion().getSuperTypeHierarchy(declaringClass, null);
        IMethod[] superClassMethods = PHPModelUtils.getSuperTypeHierarchyMethod(declaringClass, hierarchy,
                prefix, exactName, null);
        for (IMethod superMethod : superClassMethods) {
            if (declaringClass.getMethod(superMethod.getElementName()).exists()) {
                continue;
            }
            int flags = superMethod.getFlags();
            if (!PHPFlags.isFinal(flags) && !PHPFlags.isPrivate(flags) && !PHPFlags.isStatic(flags)) {
                reporter.reportMethod(superMethod, CONSTRUCTOR_SUFFIX, replaceRange);
            }
        }
    } catch (CoreException e) {
        PHPCorePlugin.log(e);
    }

    PHPVersion phpVersion = concreteContext.getPhpVersion();

    // Add magic methods:
    Set<String> functions = new TreeSet<String>();
    functions.addAll(Arrays.asList(PHPMagicMethods.getMethods(phpVersion)));

    // Add constructors:
    functions.add(declaringClass.getElementName());
    functions.add("__construct"); //$NON-NLS-1$
    functions.add("__destruct"); //$NON-NLS-1$

    for (String function : functions) {
        if (StringUtils.startsWithIgnoreCase(function, prefix)) {
            if (!requestor.isContextInformationMode() || function.length() == prefix.length()) {
                FakeMethod fakeMethod = new FakeMethod((ModelElement) declaringClass, function);
                if (function.equals("__construct")) { //$NON-NLS-1$
                    fakeMethod.setConstructor(true);
                }
                reporter.reportMethod(fakeMethod, suffix, replaceRange);
            }
        }
    }
}

From source file:org.eclipse.php.internal.core.codeassist.strategies.NamespaceConstantsStrategy.java

public void apply(ICompletionReporter reporter) throws BadLocationException {
    ICompletionContext context = getContext();
    if (!(context instanceof NamespaceMemberContext)) {
        return;//from   w ww.ja  v a 2  s  .co m
    }

    NamespaceMemberContext concreteContext = (NamespaceMemberContext) context;
    String prefix = concreteContext.getPrefix();
    String suffix = getSuffix(concreteContext);
    ISourceRange replaceRange = getReplacementRange(concreteContext);

    for (IType ns : concreteContext.getNamespaces()) {
        try {
            for (IField field : ns.getFields()) {
                if (!PHPFlags.isConstant(field.getFlags())) {
                    continue;
                }
                if (StringUtils.startsWithIgnoreCase(field.getElementName(), prefix)) {
                    reporter.reportField(field, suffix, replaceRange, false);
                }
            }
        } catch (ModelException e) {
            PHPCorePlugin.log(e);
        }
    }
}

From source file:org.eclipse.php.internal.core.codeassist.strategies.NamespaceDocTypesStrategy.java

public IType[] getTypes(NamespacePHPDocVarStartContext context) throws BadLocationException {
    String prefix = context.getPrefix();
    prefix = PHPModelUtils.extractElementName(prefix);

    List<IType> result = new LinkedList<IType>();
    for (IType ns : context.getNamespaces()) {
        try {/*w  ww  .j  a va2 s  .co  m*/
            for (IType type : ns.getTypes()) {
                if (StringUtils.startsWithIgnoreCase(type.getElementName(), prefix)) {
                    result.add(type);
                }
            }
        } catch (ModelException e) {
            PHPCorePlugin.log(e);
        }
    }
    String lastNamespace = null;
    for (IType ns : context.getPossibleNamespaces()) {
        if (context.getNsPrefix() == null) {
            if (!ns.getElementName().equals(lastNamespace)) {
                result.add(ns);
            }
            lastNamespace = ns.getElementName();
        } else {
            String fullName = ns.getElementName();
            String alias = getAlias(ns, context.getNsPrefix());
            if (alias == null) {
                result.add(ns);
            } else {
                result.add(new AliasType((ModelElement) ns, fullName, alias));
            }
        }
    }
    return (IType[]) result.toArray(new IType[result.size()]);
}

From source file:org.eclipse.php.internal.core.codeassist.strategies.NamespaceFunctionsStrategy.java

public void apply(ICompletionReporter reporter) throws BadLocationException {
    ICompletionContext context = getContext();
    if (!(context instanceof NamespaceMemberContext)) {
        return;//from  w  w w  .j ava2 s . c o  m
    }

    NamespaceMemberContext concreteContext = (NamespaceMemberContext) context;
    String prefix = concreteContext.getPrefix();
    String suffix = getSuffix(concreteContext);
    ISourceRange replaceRange = getReplacementRange(concreteContext);

    for (IType ns : concreteContext.getNamespaces()) {
        try {
            for (IMethod method : ns.getMethods()) {
                if (StringUtils.startsWithIgnoreCase(method.getElementName(), prefix)) {
                    reporter.reportMethod(method, suffix, replaceRange);
                }
            }
        } catch (ModelException e) {
            PHPCorePlugin.log(e);
        }
    }
}

From source file:org.eclipse.php.internal.core.codeassist.strategies.NamespaceTypesStrategy.java

public IType[] getTypes(NamespaceMemberContext context) throws BadLocationException {
    String prefix = context.getPrefix();

    List<IType> result = new LinkedList<IType>();
    for (IType ns : context.getNamespaces()) {
        try {//from w w  w  .  ja  v a  2 s  .c o m
            for (IType type : ns.getTypes()) {
                if (StringUtils.startsWithIgnoreCase(type.getElementName(), prefix)) {
                    result.add(type);
                }
            }
        } catch (ModelException e) {
            PHPCorePlugin.log(e);
        }
    }
    return (IType[]) result.toArray(new IType[result.size()]);
}

From source file:org.eclipse.php.internal.core.codeassist.strategies.NamespaceUseConstNameStrategy.java

public IField[] getFields(NamespaceUseConstNameContext context) throws BadLocationException {
    String prefix = context.getPrefix();

    List<IField> result = new LinkedList<IField>();
    for (IType ns : context.getNamespaces()) {
        try {/*from   ww w . j  a  v a  2s  . c om*/
            for (IField field : ns.getFields()) {
                if (StringUtils.startsWithIgnoreCase(field.getElementName(), prefix)) {
                    result.add(field);
                }
            }
        } catch (ModelException e) {
            PHPCorePlugin.log(e);
        }
    }
    return result.toArray(new IField[result.size()]);
}

From source file:org.eclipse.php.internal.core.codeassist.strategies.NamespaceUseFunctionNameStrategy.java

public IMethod[] getMethods(NamespaceUseFunctionNameContext context) throws BadLocationException {
    String prefix = context.getPrefix();

    List<IMethod> result = new LinkedList<IMethod>();
    for (IType ns : context.getNamespaces()) {
        try {// w  w  w  .  j a  va  2s.  c  o m
            for (IMethod method : ns.getMethods()) {
                if (StringUtils.startsWithIgnoreCase(method.getElementName(), prefix)) {
                    result.add(method);
                }
            }
        } catch (ModelException e) {
            PHPCorePlugin.log(e);
        }
    }
    return result.toArray(new IMethod[result.size()]);
}

From source file:org.eclipse.php.internal.core.codeassist.strategies.NamespaceUseNameStrategy.java

public IType[] getTypes(NamespaceUseNameContext context) throws BadLocationException {
    String prefix = context.getPrefix();

    List<IType> result = new LinkedList<IType>();
    for (IType ns : context.getNamespaces()) {
        try {/*from w w  w.ja v a  2 s  .co m*/
            for (IType type : ns.getTypes()) {
                if (StringUtils.startsWithIgnoreCase(type.getElementName(), prefix)) {
                    result.add(type);
                }
            }
        } catch (ModelException e) {
            PHPCorePlugin.log(e);
        }
    }
    return (IType[]) result.toArray(new IType[result.size()]);
}

From source file:org.eclipse.php.internal.core.codeassist.strategies.NamespaceUseTraitNameStrategy.java

public IType[] getTypes(NamespaceUseNameContext context) throws BadLocationException {
    if (context.getNamespaces() == null) {
        return new IType[0];
    }// w w  w .j  av  a2  s.  com
    String prefix = context.getPrefix();

    List<IType> result = new LinkedList<IType>();
    for (IType ns : context.getNamespaces()) {
        try {
            for (IType type : ns.getTypes()) {
                if (PHPFlags.isTrait(type.getFlags())
                        && StringUtils.startsWithIgnoreCase(type.getElementName(), prefix)) {
                    result.add(type);
                }
            }
        } catch (ModelException e) {
            PHPCorePlugin.log(e);
        }
    }
    return (IType[]) result.toArray(new IType[result.size()]);
}

From source file:org.eclipse.php.internal.core.codeassist.strategies.PHPDocTagStrategy.java

public void apply(ICompletionReporter reporter) throws BadLocationException {
    ICompletionContext context = getContext();
    if (!(context instanceof PHPDocTagContext)) {
        return;// w w w  . j  a  v  a 2  s.co  m
    }
    PHPDocTagContext tagContext = (PHPDocTagContext) context;
    String tagName = tagContext.getTagName();
    CompletionRequestor requestor = tagContext.getCompletionRequestor();

    ISourceRange replaceRange = getReplacementRange(tagContext);
    String suffix = ""; //$NON-NLS-1$

    for (TagKind nextTag : TagKind.values()) {
        String nextTagName = nextTag.getName();
        if (StringUtils.startsWithIgnoreCase(nextTagName, tagName)) {
            if (!requestor.isContextInformationMode() || nextTagName.length() == tagName.length()) {

                // Tags are reported like keywords:
                reporter.reportKeyword(nextTagName, suffix, replaceRange);
            }
        }
    }
}