From cae47e40de9ebdaaff52904fd7fdcf84e6decc5b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 16 Sep 2013 19:39:59 +0400 Subject: [PATCH] model: meaningful macro name assertion --- .../openapi/components/StoragePathMacros.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StoragePathMacros.java b/platform/projectModel-api/src/com/intellij/openapi/components/StoragePathMacros.java index e485190c2800..765f350309bd 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StoragePathMacros.java +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StoragePathMacros.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,18 +26,17 @@ import org.jetbrains.annotations.NotNull; * i.e. special markers that are mapped to the current file system environment at runtime. *

* This class holds those markers and utility method for working with them. - * + * * @author Denis Zhdanov * @since 5/2/12 12:57 PM */ public class StoragePathMacros { - /** Points to the application-level settings root directory. */ @NonNls @NotNull public static final String APP_CONFIG = "$APP_CONFIG$"; - + /** '.ipr' file path key. */ @NonNls @NotNull public static final String PROJECT_FILE = "$PROJECT_FILE$"; - + /** '.idea' directory path key. */ @NonNls @NotNull public static final String PROJECT_CONFIG_DIR = "$PROJECT_CONFIG_DIR$"; @@ -56,19 +55,15 @@ public class StoragePathMacros { * Allows to extract macro name from the given macro definition. *

* Basically, performs conversion like {@code '$NAME$' -> 'NAME'}. - * + * * @param macro macro definition which name should be extracted. * @return name of the given macro definition * @throws IllegalArgumentException if given macro definition has unexpected format */ @NotNull public static String getMacroName(@NotNull String macro) throws IllegalArgumentException { - if (macro.length() <= 0) { - throw new IllegalArgumentException("Can't extract name from the given macro definition. Reason: it's empty"); - } - if (macro.charAt(0) != '$' || macro.charAt(macro.length() - 1) != '$') { - throw new IllegalArgumentException("Can't extract name from the given macro definition (" + macro + ")." + - " Reason: it doesn't conform to the expected format ($NAME$)"); + if (macro.length() < 3 || macro.charAt(0) != '$' || macro.charAt(macro.length() - 1) != '$') { + throw new IllegalArgumentException("Malformed macro definition (" + macro + ")"); } return macro.substring(1, macro.length() - 1); }