Java Code Examples for org.apache.commons.lang.StringUtils#stripStart()
The following examples show how to use
org.apache.commons.lang.StringUtils#stripStart() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RunProcessRunnerFromCLI.java From FortifyBugTrackerUtility with MIT License | 6 votes |
/** * This method iterates over the given args array, and matches each argument against the given * {@link CLIOptionDefinitions}. If an argument matches with a {@link CLIOptionDefinition}, * the argument value is added to the result {@link ContextWithUnknownCLIOptionsList} (or in case * of a flag option, "true" is added to the result). Any unknown options will be added to the * unknown options set. * * @param cliOptionDefinitions * @param args * @return */ private ContextWithUnknownCLIOptionsList parseContextFromCLI(CLIOptionDefinitions cliOptionDefinitions, String[] args) { ContextWithUnknownCLIOptionsList result = new ContextWithUnknownCLIOptionsList(); for ( int i = 0 ; i < args.length ; i++ ) { String optionName = StringUtils.stripStart(args[i], "-"); if ( cliOptionDefinitions.containsCLIOptionDefinitionName(optionName) ) { if ( cliOptionDefinitions.getCLIOptionDefinitionByName(optionName).isFlag() ) { result.put(optionName, "true"); } else { result.put(optionName, args[++i]); } } else { result.addUnknowCLIOption(optionName); // Skip next argument if it looks like a value for the unknown option if ( args.length > i+1 && !args[i+1].startsWith("-") ) {i++;} } } return result; }
Example 2
Source File: TwigControllerUsageControllerRelatedGotoCollector.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public void collectGotoRelatedItems(ControllerActionGotoRelatedCollectorParameter parameter) { Method method = parameter.getMethod(); PhpClass containingClass = method.getContainingClass(); if (containingClass == null) { return; } String controllerAction = StringUtils.stripStart(containingClass.getPresentableFQN(), "\\") + "::" + method.getName(); Collection<VirtualFile> targets = new HashSet<>(); FileBasedIndex.getInstance().getFilesWithKey(TwigControllerStubIndex.KEY, new HashSet<>(Collections.singletonList(controllerAction)), virtualFile -> { targets.add(virtualFile); return true; }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(parameter.getProject()), TwigFileType.INSTANCE)); for (PsiFile psiFile: PsiElementUtils.convertVirtualFilesToPsiFiles(parameter.getProject(), targets)) { TwigUtil.visitControllerFunctions(psiFile, pair -> { if (pair.getFirst().equalsIgnoreCase(controllerAction)) { parameter.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(pair.getSecond()).withIcon(TwigIcons.TwigFileIcon, Symfony2Icons.TWIG_LINE_MARKER)); } }); } }
Example 3
Source File: QuickSearch.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
public static QuickSearch fromQueryString(String queryString) { if (queryString == null) { queryString = ""; } String cleanedQuery = StringUtils.stripStart(queryString, "*"); List<String> partialMatches = Lists.newArrayList(); List<String> fullMatches; if (queryString.isEmpty()) { fullMatches = Lists.newArrayList(); } else { String[] splitQuery = cleanedQuery.split(" "); fullMatches = Lists.newArrayList(splitQuery); int indexOfLastItem = fullMatches.size() - 1; partialMatches.add(StringUtils.stripEnd(fullMatches.remove(indexOfLastItem), "*")); } return new QuickSearch(fullMatches, partialMatches); }
Example 4
Source File: DoctrineUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Extract text: @Entity(repositoryClass="foo") */ @Nullable public static String getAnnotationRepositoryClass(@NotNull PhpDocTag phpDocTag, @NotNull PhpClass phpClass) { PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList)); if(phpDocAttributeList == null) { return null; } // @TODO: use annotation plugin // repositoryClass="Foobar" String text = phpDocAttributeList.getText(); String repositoryClass = EntityHelper.resolveDoctrineLikePropertyClass( phpClass, text, "repositoryClass", aVoid -> AnnotationUtil.getUseImportMap(phpDocTag) ); if (repositoryClass == null) { return null; } return StringUtils.stripStart(repositoryClass, "\\"); }
Example 5
Source File: ServiceContainerUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull private static SerializableService createService(@NotNull ServiceConsumer serviceConsumer) { AttributeValueInterface attributes = serviceConsumer.attributes(); Boolean anAbstract = attributes.getBoolean("abstract"); String aClass = StringUtils.stripStart(attributes.getString("class"), "\\"); if(aClass == null && isServiceIdAsClassSupported(attributes, anAbstract)) { // if no "class" given since Syfmony 3.3 we have lowercase "id" names // as we internally use case insensitive maps; add user provided values aClass = serviceConsumer.getServiceId(); } return new SerializableService(serviceConsumer.getServiceId()) .setAlias(attributes.getString("alias")) .setClassName(aClass) .setDecorates(attributes.getString("decorates")) .setParent(attributes.getString("parent")) .setIsAbstract(anAbstract) .setIsAutowire(attributes.getBoolean("autowire", serviceConsumer.getDefaults().isAutowire())) .setIsLazy(attributes.getBoolean("lazy")) .setIsPublic(attributes.getBoolean("public", serviceConsumer.getDefaults().isPublic())) .setResource(attributes.getString("resource")) .setExclude(attributes.getString("exclude")) .setTags(attributes.getTags()); }
Example 6
Source File: XmlTransformer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private String stripXmlDeclaration(CharSequence sequence) { String str = sequence.toString(); if (hasXmlDeclaration(str)) { str = str.substring(str.indexOf("?>") + 2); str = StringUtils.stripStart(str, null); } return str; }
Example 7
Source File: DrupalVirtualProperties.java From idea-php-drupal-symfony2-bridge with MIT License | 5 votes |
@Override public void getTargets(@NotNull AnnotationVirtualPropertyTargetsParameter parameter) { String fqn = StringUtils.stripStart(parameter.getPhpClass().getFQN(), "\\"); if(!ITEMS.containsKey(fqn)) { return; } if(ITEMS.containsKey(fqn) && ITEMS.get(fqn).containsKey(parameter.getProperty())) { parameter.addTarget(parameter.getPhpClass()); } }
Example 8
Source File: PhpTypeProviderUtil.java From idea-php-toolbox with MIT License | 5 votes |
/** * we can also pipe php references signatures and resolve them here * overwrite parameter to get string value */ @Nullable public static String getResolvedParameter(PhpIndex phpIndex, String parameter) { // PHP 5.5 class constant: "Class\Foo::class" if(parameter.startsWith("#K#C")) { // PhpStorm9: #K#C\Class\Foo.class if(parameter.endsWith(".class")) { return StringUtils.stripStart(parameter.substring(4, parameter.length() - 6), "\\"); } } // #K#C\Class\Foo.property // #K#C\Class\Foo.CONST if(parameter.startsWith("#")) { // get psi element from signature Collection<? extends PhpNamedElement> signTypes = phpIndex.getBySignature(parameter, null, 0); if(signTypes.size() == 0) { return null; } // get string value parameter = PhpElementsUtil.getStringValue(signTypes.iterator().next()); if(parameter == null) { return null; } } return parameter; }
Example 9
Source File: PhpTypeProviderUtil.java From idea-php-generics-plugin with MIT License | 5 votes |
/** * we can also pipe php references signatures and resolve them here * overwrite parameter to get string value */ @Nullable public static String getResolvedParameter(@NotNull PhpIndex phpIndex, @NotNull String parameter, @Nullable Set<String> visited, int depth) { // PHP 5.5 class constant: "Class\Foo::class" if(parameter.startsWith("#K#C")) { // PhpStorm9: #K#C\Class\Foo.class if(parameter.endsWith(".class")) { return StringUtils.stripStart(parameter.substring(4, parameter.length() - 6), "\\"); } } // #K#C\Class\Foo.property // #K#C\Class\Foo.CONST if(parameter.startsWith("#")) { // get psi element from signature Collection<? extends PhpNamedElement> signTypes = phpIndex.getBySignature(parameter, visited, depth); if(signTypes.size() == 0) { return null; } // get string value parameter = GenericsUtil.getStringValue(signTypes.iterator().next()); if(parameter == null) { return null; } } return parameter; }
Example 10
Source File: LocalProfilerIndex.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable @Override public String getUrlForRequest(@NotNull ProfilerRequestInterface request) { if(this.baseUrl != null) { return this.baseUrl + "/" + StringUtils.stripStart(request.getProfilerUrl(), "/"); } return ProfilerUtil.getBaseProfilerUrlFromRequest(request.getProfilerUrl()); }
Example 11
Source File: PhpElementsUtil.java From idea-php-annotation-plugin with MIT License | 5 votes |
/** * Foo::class to its class fqn include namespace */ private static String getClassConstantPhpFqn(@NotNull ClassConstantReference classConstant) { PhpExpression classReference = classConstant.getClassReference(); if(!(classReference instanceof PhpReference)) { return null; } String typeName = ((PhpReference) classReference).getFQN(); return typeName != null && StringUtils.isNotBlank(typeName) ? StringUtils.stripStart(typeName, "\\") : null; }
Example 12
Source File: EventAnnotationStubIndex.java From idea-php-symfony2-plugin with MIT License | 5 votes |
private String findClassInstance(@NotNull PhpDocComment phpDocComment, @NotNull PhpDocTag phpDocTag) { PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList)); if(phpDocAttributeList instanceof PhpPsiElement) { PsiElement childrenOfType = PsiElementUtils.getChildrenOfType(phpDocAttributeList, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocString)); if(childrenOfType instanceof StringLiteralExpression) { String contents = StringUtils.stripStart(((StringLiteralExpression) childrenOfType).getContents(), "\\"); if(StringUtils.isNotBlank(contents) && contents.length() < 350) { return contents; } } } return EventDispatcherUtil.extractEventClassInstance(phpDocComment.getText()); }
Example 13
Source File: PhpTypeProviderUtil.java From idea-php-toolbox with MIT License | 5 votes |
/** * we can also pipe php references signatures and resolve them here * overwrite parameter to get string value */ @Nullable public static String getResolvedParameter(PhpIndex phpIndex, String parameter) { // PHP 5.5 class constant: "Class\Foo::class" if(parameter.startsWith("#K#C")) { // PhpStorm9: #K#C\Class\Foo.class if(parameter.endsWith(".class")) { return StringUtils.stripStart(parameter.substring(4, parameter.length() - 6), "\\"); } } // #K#C\Class\Foo.property // #K#C\Class\Foo.CONST if(parameter.startsWith("#")) { // get psi element from signature Collection<? extends PhpNamedElement> signTypes = phpIndex.getBySignature(parameter, null, 0); if(signTypes.size() == 0) { return null; } // get string value parameter = PhpElementsUtil.getStringValue(signTypes.iterator().next()); if(parameter == null) { return null; } } return parameter; }
Example 14
Source File: ServiceUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@NotNull public static String getServiceNameForClass(@NotNull Project project, @NotNull String className) { className = StringUtils.stripStart(className, "\\"); ServiceNameStrategyParameter parameter = new ServiceNameStrategyParameter(project, className); for (ServiceNameStrategyInterface nameStrategy : NAME_STRATEGIES) { String serviceName = nameStrategy.getServiceName(parameter); if(serviceName != null && StringUtils.isNotBlank(serviceName)) { return serviceName; } } return className.toLowerCase().replace("\\", "_"); }
Example 15
Source File: ControllerReferences.java From idea-php-laravel-plugin with MIT License | 5 votes |
@Nullable private String getControllerGroupPrefix(@NotNull PsiElement element) { List<String> groupNamespaces = RouteGroupUtil.getRouteGroupPropertiesCollection(element, "namespace"); if(groupNamespaces.size() > 0) { return StringUtils.stripStart(StringUtils.join(groupNamespaces, "\\"), "\\"); } else { return null; } }
Example 16
Source File: TwigUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * Visit each "controller()" with its normalized parameter */ public static void visitControllerFunctions(@NotNull PsiFile psiFile,@NotNull Consumer<Pair<String, PsiElement>> consumer) { // PsiElement[] psiElements = PsiTreeUtil.collectElements(psiFile, psiElement -> { if (psiElement.getNode().getElementType() != TwigElementTypes.FUNCTION_CALL) { return false; } PsiElement firstChild = psiElement.getFirstChild(); if (firstChild.getNode().getElementType() != TwigTokenTypes.IDENTIFIER) { return false; } return "controller".equalsIgnoreCase(firstChild.getText()); }); // find parameter: controller("foobar::action") for (PsiElement functionCall: psiElements) { PsiElement includeTag = PsiElementUtils.getChildrenOfType(functionCall, TwigPattern.getPrintBlockOrTagFunctionPattern("controller")); if(includeTag != null) { String controllerName = includeTag.getText(); if(StringUtils.isNotBlank(controllerName)) { // escaping // "Foobar\\Test" String replace = StringUtils.stripStart(controllerName.replace("\\\\", "\\"), "\\"); consumer.consume(Pair.create(replace, includeTag)); } } } }
Example 17
Source File: FormUtil.java From idea-php-symfony2-plugin with MIT License | 4 votes |
/** * Finds form name by "getName" method * * Symfony < 2.8 * 'foo_bar' * * Symfony 2.8 * "$this->getName()" -> "$this->getBlockPrefix()" -> return 'datetime'; * "UserProfileType" => "user_profile" and namespace removal * * Symfony 3.0 * Use class name: Foo\Class * */ @Nullable public static String getFormNameOfPhpClass(@NotNull PhpClass phpClass) { Method method = phpClass.findOwnMethodByName("getName"); // @TODO: think of interface switches // method not found so use class fqn if(method == null) { return StringUtils.stripStart(phpClass.getFQN(), "\\"); } for (PhpReturn phpReturn : PsiTreeUtil.collectElementsOfType(method, PhpReturn.class)) { PhpPsiElement firstPsiChild = phpReturn.getFirstPsiChild(); // $this->getBlockPrefix() if(firstPsiChild instanceof MethodReference) { PhpExpression classReference = ((MethodReference) firstPsiChild).getClassReference(); if(classReference != null && "this".equals(classReference.getName())) { String name = firstPsiChild.getName(); if(name != null && "getBlockPrefix".equals(name)) { if(phpClass.findOwnMethodByName("getBlockPrefix") != null) { return PhpElementsUtil.getMethodReturnAsString(phpClass, name); } else { // method has no custom overwrite; rebuild expression here: // FooBarType -> foo_bar String className = phpClass.getName(); // strip Type and type if(className.toLowerCase().endsWith("type") && className.length() > 4) { className = className.substring(0, className.length() - 4); } return fr.adrienbrault.idea.symfony2plugin.util.StringUtils.underscore(className); } } } continue; } // string value fallback String stringValue = PhpElementsUtil.getStringValue(firstPsiChild); if(stringValue != null) { return stringValue; } } return null; }
Example 18
Source File: RouteHelper.java From idea-php-symfony2-plugin with MIT License | 4 votes |
/** * Support "use Symfony\Component\Routing\Annotation\Route as BaseRoute;" */ public static boolean isRouteClassAnnotation(@NotNull String clazz) { String myClazz = StringUtils.stripStart(clazz, "\\"); return ROUTE_CLASSES.stream().anyMatch(s -> s.equalsIgnoreCase(myClazz)); }
Example 19
Source File: MessageBeanProcessor.java From rice with Educational Community License v2.0 | 4 votes |
/** * Checks a string property value for a message placeholder and if found the message is retrieved and updated * in the property value * * @param propertyValue string value to process for message placeholders * @param nestedBeanStack stack of bean definitions that contain the property, used to determine the namespace * and component for the message retrieval * @return String new value for the property (possibly modified from an external message) */ protected String processMessagePlaceholders(String propertyValue, Stack<BeanDefinitionHolder> nestedBeanStack) { String trimmedPropertyValue = StringUtils.stripStart(propertyValue, " "); if (StringUtils.isBlank(trimmedPropertyValue)) { return propertyValue; } String newPropertyValue = propertyValue; // first check for a replacement message key if (trimmedPropertyValue.startsWith(KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX) && StringUtils.contains( trimmedPropertyValue, KRADConstants.MESSAGE_KEY_PLACEHOLDER_SUFFIX)) { String messageKeyStr = StringUtils.substringBetween(trimmedPropertyValue, KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX, KRADConstants.MESSAGE_KEY_PLACEHOLDER_SUFFIX); // get any default specified value (given after the message key) String messageKeyWithPlaceholder = KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX + messageKeyStr + KRADConstants.MESSAGE_KEY_PLACEHOLDER_SUFFIX; String defaultPropertyValue = StringUtils.substringAfter(trimmedPropertyValue, messageKeyWithPlaceholder); // set the new property value to the message text (if found), or the default value if a message was not found // note the message text could be an empty string, in which case it will override the default String messageText = getMessageTextForKey(messageKeyStr, nestedBeanStack); if (messageText != null) { // if default value set then we need to merge any expressions if (StringUtils.isNotBlank(defaultPropertyValue)) { newPropertyValue = getMergedMessageText(messageText, defaultPropertyValue); } else { newPropertyValue = messageText; } } else { newPropertyValue = defaultPropertyValue; } } // now check for message keys within an expression else if (StringUtils.contains(trimmedPropertyValue, KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_PREFIX)) { String[] expressionMessageKeys = StringUtils.substringsBetween(newPropertyValue, KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_PREFIX, KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_SUFFIX); for (String expressionMessageKey : expressionMessageKeys) { String expressionMessageText = getMessageTextForKey(expressionMessageKey, nestedBeanStack); newPropertyValue = StringUtils.replace(newPropertyValue, KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_PREFIX + expressionMessageKey + KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_SUFFIX, expressionMessageText); } } return newPropertyValue; }
Example 20
Source File: JsonFileIndexTwigNamespaces.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Nullable @Override public Result<Collection<TwigPath>> compute() { Collection<TwigPath> twigPaths = new ArrayList<>(); String text = psiFile.getText(); TwigConfigJson configJson = null; try { configJson = new Gson().fromJson(text, TwigConfigJson.class); } catch (JsonSyntaxException | JsonIOException | IllegalStateException ignored) { } if(configJson == null) { return Result.create(twigPaths, psiFile, psiFile.getVirtualFile()); } for(TwigPathJson twigPath : configJson.getNamespaces()) { String path = twigPath.getPath(); if(path == null || path.equals(".")) { path = ""; } path = StringUtils.stripStart(path.replace("\\", "/"), "/"); PsiDirectory parent = psiFile.getParent(); if(parent == null) { continue; } // current directory check and subfolder VirtualFile twigRoot; if(path.length() > 0) { twigRoot = VfsUtil.findRelativeFile(parent.getVirtualFile(), path.split("/")); } else { twigRoot = psiFile.getParent().getVirtualFile(); } if(twigRoot == null) { continue; } String relativePath = VfsExUtil.getRelativeProjectPath(psiFile.getProject(), twigRoot); if(relativePath == null) { continue; } String namespace = twigPath.getNamespace(); TwigUtil.NamespaceType pathType = TwigUtil.NamespaceType.ADD_PATH; String type = twigPath.getType(); if("bundle".equalsIgnoreCase(type)) { pathType = TwigUtil.NamespaceType.BUNDLE; } String namespacePath = StringUtils.stripStart(relativePath, "/"); if(StringUtils.isNotBlank(namespace)) { twigPaths.add(new TwigPath(namespacePath, namespace, pathType, true)); } else { twigPaths.add(new TwigPath(namespacePath, TwigUtil.MAIN, pathType, true)); } } return Result.create(twigPaths, psiFile, psiFile.getVirtualFile()); }