Java Code Examples for com.intellij.openapi.util.text.StringUtil.isEmpty()

The following are Jave code examples for showing how to use isEmpty() of the com.intellij.openapi.util.text.StringUtil class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ApkMultiChannelPlugin   File: OptionsHelper.java   Source Code and License Vote up 6 votes
public static boolean verify(Options options) {
    String message = null;
    if (StringUtil.isEmpty(options.keyStorePath)) {
        message = "Please choose a keystore file";
    } else if (StringUtil.isEmpty(options.keyStorePassword)) {
        message = "Please enter the keystore password";
    } else if (StringUtil.isEmpty(options.keyPassword)) {
        message = "Please enter the key password";
    } else if (StringUtil.isEmpty(options.keyAlias)) {
        message = "Please enter the key alias";
    } else if (options.channels.size() == 0) {
        message = "Please enter channels";
    } else if (StringUtil.isEmpty(options.zipalignPath)) {
        message = "Please choose a zipalign file";
    } else if (StringUtil.isEmpty(options.signer)) {
        message = "Please choose a signer";
    } else if (StringUtil.isEmpty(options.buildType)) {
        message = "Please choose a build type";
    }

    boolean success = message == null;
    if (!success) {
        NotificationHelper.error(message);
    }
    return success;
}
 
Example 2
Project: hybris-integration-intellij-idea-plugin   File: TSMetaModelImpl.java   Source Code and License Vote up 6 votes
@Nullable
TSMetaEnumImpl findOrCreateEnum(final @NotNull EnumType domEnumType) {
    final String name = TSMetaEnumImpl.extractName(domEnumType);
    if (StringUtil.isEmpty(name)) {
        return null;
    }
    final NoCaseMap<TSMetaEnumImpl> enums = getEnums();
    TSMetaEnumImpl impl = enums.get(name);
    if (impl == null) {
        impl = new TSMetaEnumImpl(name, domEnumType);
        enums.put(name, impl);
    } else {
        //report a problem
    }
    return impl;
}
 
Example 3
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 6 votes
/**
   * If inside tell (only in a tell?) compound statement - first check it's terms
   */
  public static boolean parseExpression(PsiBuilder b, int l, String dictionaryTermToken, Parser expression) {
    if (!recursion_guard_(b, l, "parseExpression")) return false;
    if (!nextTokenIsFast(b, dictionaryTermToken)) return false;
    boolean r;

    //check application terms first
    if (b.getUserData(PARSING_TELL_COMPOUND_STATEMENT) == Boolean.TRUE) {
      String toldAppName = peekTargetApplicationName(b);
      if (!StringUtil.isEmpty(toldAppName)) {
        StringHolder parsedName = new StringHolder();
        PsiBuilder.Marker mComName = enter_section_(b, l, _AND_, "<parse Expression>");
        r = parseCommandNameForApplication(b, l + 1, parsedName, toldAppName, true);
        exit_section_(b, l, mComName, null, r, false, null);
        if (r) return false;
        if (ParsableScriptSuiteRegistryHelper.isPropertyWithPrefixExist(toldAppName, dictionaryTermToken)) {
          return false;
//          PsiBuilder.Marker m = enter_section_(b, l, _AND_, null, "<dictionary constant>");
//          r = parseDictionaryConstant(b, l + 1);
//          exit_section_(b, l, m, r, false, null);
//          if (r) return false;
        }
      }
    }
    return expression.parse(b, l + 1);
  }
 
Example 4
Project: AppleScript-IDEA   File: SDEF_Parser.java   Source Code and License Vote up 6 votes
public static void parse(@NotNull XmlFile file, @NotNull ApplicationDictionary parsedDictionary) {
  System.out.println("Start parsing xml file --- " + file.toString() + " ---");
  LOG.debug("Start parsing xml file --- " + file.toString() + " ---");

  if (parsedDictionary.getRootTag() == null) {
    parsedDictionary.setRootTag(file.getRootTag());
  }
  final XmlDocument document = file.getDocument();
  if (document != null) {
    final XmlTag rootTag = document.getRootTag();
    if (rootTag != null) {
      XmlAttribute attr = rootTag.getAttribute("title");
      if ("dictionary".equals(rootTag.getName()) && attr != null) {
        String dicTitle = attr.getValue();
        if (!StringUtil.isEmpty(dicTitle)) {
          parsedDictionary.setName(dicTitle);
        }
      }
      parseRootTag(parsedDictionary, rootTag);
    }
  }
  System.out.println("parsing completed for file.");
  LOG.debug("parsing completed for file.");
}
 
Example 5
Project: AppleScript-IDEA   File: SDEF_Parser.java   Source Code and License Vote up 6 votes
@NotNull
private static List<AppleScriptPropertyDefinition> getPropertiesFromTags(@NotNull DictionaryComponent classOrRecord,
                                                                         @NotNull XmlTag[] propertyTags) {
  if (!(classOrRecord instanceof AppleScriptClass) && !(classOrRecord instanceof DictionaryRecord))
    return new ArrayList<>(0);

  List<AppleScriptPropertyDefinition> properties = new ArrayList<>(propertyTags.length);
  for (XmlTag propTag : propertyTags) {
    AppleScriptPropertyDefinition property;
    String pName = propTag.getAttributeValue("name");
    String pCode = propTag.getAttributeValue("code");
    String pDescription = propTag.getAttributeValue("description");
    String pType = propTag.getAttributeValue("type");
    if (StringUtil.isEmpty(pType)) {
      XmlTag tType = propTag.findFirstSubTag("type");
      pType = tType != null ? tType.getAttributeValue("type") : null;
    }
    String pAccessType = propTag.getAttributeValue("access");
    AccessType accessType = "r".equals(pAccessType) ? AccessType.R : AccessType.RW;
    if (pName != null && pCode != null && pType != null) {
      property = new DictionaryPropertyImpl(classOrRecord, pName, pCode, pType, pDescription, propTag, accessType);
      properties.add(property);
    }
  }
  return properties;
}
 
Example 6
Project: hybris-integration-intellij-idea-plugin   File: TypeSystemGutterAnnotator.java   Source Code and License Vote up 6 votes
@NotNull
private static Stream<TSMetaClass> getExtendingMetaClassNamesStream(@NotNull final ItemType source) {
    final String code = source.getCode().getStringValue();

    if (StringUtil.isEmpty(code)) {
        return Stream.empty();
    }
    final XmlElement xmlElement = source.getXmlElement();
    final PsiFile psiFile = xmlElement == null ? null : xmlElement.getContainingFile();

    if (psiFile == null) {
        return Stream.empty();
    }
    final TSMetaModel metaModel = TSMetaModelAccess.getInstance(psiFile.getProject()).getTypeSystemMeta(psiFile);
    final TSMetaClass sourceMeta = metaModel.findMetaClassForDom(source);

    if (sourceMeta == null) {
        return Stream.empty();
    }
    return metaModel
        .getMetaClassesStream()
        .map(TSMetaClass.class::cast)
        .filter(meta -> sourceMeta.getName().equals(meta.getExtendedMetaClassName()));
}
 
Example 7
Project: AppleScript-IDEA   File: AppleScriptLineMarkerProvider.java   Source Code and License Vote up 6 votes
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element,
                                        @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {
  if (element instanceof AppleScriptApplicationReference) {
    PsiElement leafNode = PsiTreeUtil.firstChild(element);
    if (leafNode == null) return;
    AppleScriptProjectDictionaryService dictionaryService = ServiceManager.getService(element.getProject(),
        AppleScriptProjectDictionaryService.class);
    AppleScriptApplicationReference appRef = (AppleScriptApplicationReference) element;
    String appName = appRef.getApplicationName();
    if (dictionaryService == null || StringUtil.isEmpty(appName)) return;
    ApplicationDictionary dictionary = dictionaryService.getDictionary(appName);
    if (dictionary == null /*|| dictionary.getApplicationBundle() == null*/) return;

    NavigationGutterIconBuilder<PsiElement> builder =
        NavigationGutterIconBuilder.create(dictionary.getIcon(0)).
            setTargets(dictionary).setTooltipText("Navigate to application dictionary file");
    result.add(builder.createLineMarkerInfo(leafNode));

  }
}
 
Example 8
Project: AppleScript-IDEA   File: AppleScriptSystemDictionaryRegistryService.java   Source Code and License Vote up 6 votes
/**
 * Fill {@link #dictionaryInfoMap} from saved data
 *
 * @param systemDictionaryRegistry application component, which saves/loads the data
 */
private void initDictionariesInfoFromCache(@NotNull AppleScriptSystemDictionaryRegistryComponent systemDictionaryRegistry) {
  notScriptableApplicationList.addAll(systemDictionaryRegistry.getNotScriptableApplications());
  for (DictionaryInfo.State dInfoState : systemDictionaryRegistry.getDictionariesPersistedInfo()) {
    String appName = dInfoState.applicationName;
    String dictionaryUrl = dInfoState.dictionaryUrl;
    String applicationUrl = dInfoState.applicationUrl;
    if (!StringUtil.isEmptyOrSpaces(appName) && !StringUtil.isEmptyOrSpaces(dictionaryUrl)) {
      File dictionaryFile = !StringUtil.isEmpty(dictionaryUrl) ? new File(dictionaryUrl) : null;
      File applicationFile = !StringUtil.isEmpty(applicationUrl) ? new File(applicationUrl) : null;
      if (dictionaryFile != null && dictionaryFile.exists()) {
        DictionaryInfo dInfo = new DictionaryInfo(appName, dictionaryFile, applicationFile);
        addDictionaryInfo(dInfo);
      }
    }
  }
}
 
Example 9
Project: AppleScript-IDEA   File: AppleScriptSystemDictionaryRegistryService.java   Source Code and License Vote up 6 votes
private void parseClassElement(@NotNull String applicationName, @NotNull Element classElement, boolean isExtends) {
//    if isExtends -> name is always == "application"
    String className = isExtends ? classElement.getAttributeValue("extends") : classElement.getAttributeValue("name");
    String code = classElement.getAttributeValue("code");
    String pluralClassName = classElement.getAttributeValue("plural");
    if (className == null || code == null) return;
    pluralClassName = !StringUtil.isEmpty(pluralClassName) ? pluralClassName : className + "s";

    updateObjectNameSetForApplication(className, applicationName, applicationNameToClassNameSetMap);
    updateObjectNameSetForApplication(pluralClassName, applicationName, applicationNameToClassNamePluralSetMap);
    if (ApplicationDictionary.SCRIPTING_ADDITIONS_LIBRARY.equals(applicationName)) {
      updateApplicationNameSetFor(className, applicationName, stdClassNameToApplicationNameSetMap);
      updateApplicationNameSetFor(pluralClassName, applicationName, stdClassNamePluralToApplicationNameSetMap);
    }
  }
 
Example 10
Project: IntelliJ-Key-Promoter-X   File: KeyPromoter.java   Source Code and License Vote up 6 votes
private void showTip(KeyPromoterAction action) {
    if (action == null || !action.isValid() || statsService.isSuppressed(action)) {
        return;
    }

    final String shortcut = action.getShortcut();
    if (!StringUtil.isEmpty(shortcut)) {
        statsService.registerAction(action);
        KeyPromoterNotification.showTip(action, statsService.get(action).getCount());

    } else {
        final String ideaActionID = action.getIdeaActionID();
        withoutShortcutStats.putIfAbsent(ideaActionID, 0);
        withoutShortcutStats.put(ideaActionID, withoutShortcutStats.get(ideaActionID) + 1);
        if (keyPromoterSettings.getProposeToCreateShortcutCount() > 0 && withoutShortcutStats.get(ideaActionID) % keyPromoterSettings.getProposeToCreateShortcutCount() == 0) {
            KeyPromoterNotification.askToCreateShortcut(action);

        }
    }
}
 
Example 11
Project: AppleScript-IDEA   File: AppleScriptRunSettingsEditor.java   Source Code and License Vote up 6 votes
@Override
protected void resetEditorFrom(AppleScriptRunConfiguration configuration) {
  String scriptPath = configuration.getScriptPath();
  String scriptParameters = configuration.getScriptParameters();
  String scriptOptions = configuration.getScriptOptions();
  boolean showAppleEvents = configuration.isShowAppleEvents();
  if (!StringUtil.isEmpty(scriptPath)) {
    scriptTextField.setText(scriptPath);
    String[] parts = scriptPath.split("/");
    if (parts.length > 0) {
      runConfiguration.setName(parts[parts.length - 1]);
    }
  }
  if (!StringUtil.isEmpty(scriptParameters)) {
    parametersTextField.setText(scriptParameters);
  }
  if (!StringUtil.isEmpty(scriptOptions)) {
    scriptOptionsTextField.setText(scriptOptions);
  }
  showAppleEventsCheckBox.setSelected(showAppleEvents);
}
 
Example 12
Project: AppleScript-IDEA   File: SDEF_Parser.java   Source Code and License Vote up 5 votes
private static void processIncludes(@NotNull ApplicationDictionary parsedDictionary, @Nullable XmlTag[] includes) {
    if (includes == null) return;
    for (XmlTag include : includes) {
      String hrefIncl = include.getAttributeValue("href");
      if (!StringUtil.isEmpty(hrefIncl)) {
        hrefIncl = hrefIncl.replace("file://localhost", "");
        File includedFile = new File(hrefIncl);
//        ((IncludedXmlTag) suiteTag).getOriginal().getContainingFile();
        //as there is assertion error (java.lang.AssertionError: File accessed outside allowed roots),
        // we are trying to find if the dictionary file for this included dictionary was already generated
        AppleScriptSystemDictionaryRegistryService dictionarySystemRegistry = ServiceManager
            .getService(AppleScriptSystemDictionaryRegistryService.class);
        VirtualFile vFile;
        File ioFile = null;
        DictionaryInfo dInfo = dictionarySystemRegistry.getDictionaryInfoByApplicationPath(includedFile.getPath());
        if (dInfo != null) {
          ioFile = dInfo.getDictionaryFile();
        } else if (includedFile.isFile()) {
          String fName = includedFile.getName();
          int index = fName.lastIndexOf('.');
          fName = index < 0 ? fName : fName.substring(0, index);
          ioFile = dictionarySystemRegistry.getDictionaryFile(fName);
        }
        if (ioFile == null || !ioFile.exists()) ioFile = includedFile;
        if (ioFile.exists()) {
          vFile = LocalFileSystem.getInstance().findFileByIoFile(ioFile);
          if (vFile == null || !vFile.isValid()) continue;

          PsiFile psiFile = PsiManager.getInstance(parsedDictionary.getProject()).findFile(vFile);
          XmlFile xmlFile = (XmlFile) psiFile;
          if (xmlFile != null) {
            parsedDictionary.processInclude(xmlFile);
          }
        }
      }
    }
  }
 
Example 13
Project: AppleScript-IDEA   File: SDEF_Parser.java   Source Code and License Vote up 5 votes
private static AppleScriptClass parseClassTag(XmlTag classTag, Suite suite) {
  String name = classTag.getAttributeValue("name");
  String code = classTag.getAttributeValue("code");
  String pluralName = classTag.getAttributeValue("plural");

  if (name == null || code == null) return null;

  String parentClassName = classTag.getAttributeValue("inherits");
  List<String> elementNames = initClassElements(classTag);
  List<String> respondingCommands = initClassRespondingMessages(classTag);


  final AppleScriptClass aClass = new DictionaryClass(suite, name, code, classTag, parentClassName, elementNames,
      respondingCommands, pluralName);
  String description = classTag.getAttributeValue("description");
  aClass.setDescription(description);
  XmlTag[] propertyTags = classTag.findSubTags("property");
  final List<AppleScriptPropertyDefinition> properties = new ArrayList<>();
  for (XmlTag propTag : propertyTags) {
    String pName = propTag.getAttributeValue("name");
    String pCode = propTag.getAttributeValue("code");
    String pDescription = propTag.getAttributeValue("description");
    String pType = propTag.getAttributeValue("type");
    if (StringUtil.isEmpty(pType)) {
      XmlTag tType = propTag.findFirstSubTag("type");
      pType = tType != null ? tType.getAttributeValue("type") : null;
    }
    String pAccessType = propTag.getAttributeValue("access");
    AccessType accessType = "r".equals(pAccessType) ? AccessType.R : AccessType.RW;
    if (pName != null && pCode != null && pType != null) {
      final AppleScriptPropertyDefinition property = new DictionaryPropertyImpl(aClass, pName, pCode, pType,
          pDescription, propTag, accessType);
      properties.add(property);
    }
  }
  aClass.setProperties(properties);
  return aClass;
}
 
Example 14
Project: teamcity-msteams-notifier   File: MsTeamsNotifierSettingsController.java   Source Code and License Vote up 5 votes
private void Validate(String token, String botName, String iconUrl
        , String maxCommitsToDisplay, String showBuildAgent, String proxyHost, String proxyPort, String proxyUser, String proxyPassword) throws MsTeamsConfigValidationException {
    if(token == null || StringUtil.isEmpty(token)
            || botName == null || StringUtil.isEmpty(botName)
            || iconUrl == null || StringUtil.isEmpty(iconUrl)
            || (showBuildAgent.toLowerCase() == "false" && (maxCommitsToDisplay == null || StringUtil.isEmpty(maxCommitsToDisplay)))
            || tryParseInt(maxCommitsToDisplay) == null
            || (!isNullOrEmpty(proxyHost) && isNullOrEmpty(proxyPort))
            || (!isNullOrEmpty(proxyUser) && isNullOrEmpty(proxyPassword))
            || (!isNullOrEmpty(proxyPort) && tryParseInt(proxyPort) == null)
            ){

        throw new MsTeamsConfigValidationException("Could not validate parameters. Please recheck the request.");
    }
}
 
Example 15
Project: AppleScript-IDEA   File: LoadDictionaryAction.java   Source Code and License Vote up 5 votes
public static void openLoadDirectoryDialog(@NotNull final Project project, @Nullable VirtualFile directoryFile, @Nullable final String appName) {
  final boolean chooseMultiple = StringUtil.isEmpty(appName);
  FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, chooseMultiple);
  FileChooser.chooseFiles(descriptor, project, directoryFile, files -> {
    AppleScriptProjectDictionaryService projectDictionaryRegistry = ServiceManager.getService(project, AppleScriptProjectDictionaryService
        .class);
    if (projectDictionaryRegistry == null) return;

    for (VirtualFile file : files) {
      if (!ApplicationDictionaryImpl.extensionSupported(file.getExtension())) continue;

      if (chooseMultiple) {
        String applicationName;
        if (ApplicationDictionary.SUPPORTED_APPLICATION_EXTENSIONS.contains(file.getExtension())) {
          applicationName = file.getNameWithoutExtension();
        } else {
          applicationName = Messages.showInputDialog(project, "Please specify application name for dictionary "
              + file.getName(), "Enter Application Name", null, file.getNameWithoutExtension(), null);
        }
        if (StringUtil.isEmpty(applicationName)) continue;
        projectDictionaryRegistry.createDictionaryFromFile(applicationName, file);
      } else {
        projectDictionaryRegistry.createDictionaryFromFile(appName, file);
        return;
      }
    }
  });
}
 
Example 16
Project: AppleScript-IDEA   File: AppleScriptSystemDictionaryRegistryService.java   Source Code and License Vote up 5 votes
private void initializeScriptingAdditions() {
  for (String stdLibFolder : ApplicationDictionary.SCRIPTING_ADDITIONS_FOLDERS) {
    final File dir = new File(stdLibFolder);
    if (!dir.isDirectory()) continue;
    final File[] stdLibs = dir.listFiles();
    if (stdLibs == null || stdLibs.length == 0) continue;
    for (File stdLib : stdLibs) {
      String libraryName = stdLib.getName();
      int last = libraryName.lastIndexOf(".");
      libraryName = libraryName.substring(0, last > 0 ? last : libraryName.length() - 1);
      if (StringUtil.isEmpty(libraryName)) continue;
      DictionaryInfo dInfo = getDictionaryInfo(libraryName);
      if (dInfo != null) {
        initializeDictionaryFromInfo(dInfo);
      } else {
        if (stdLib.exists())
          dInfo = createAndInitializeInfo(stdLib, libraryName);
      }
      if (dInfo != null)
        scriptingAdditions.add(dInfo.getApplicationName());
      else {
        LOG.warn("Can not initialize scripting addition library from file: " + stdLib + ". Will copy bundled lib.");
        try {
          dInfo = initStdTerms(ApplicationDictionary.SCRIPTING_ADDITIONS_LIBRARY);
          if (dInfo != null) {
            scriptingAdditions.add(dInfo.getApplicationName());
          }
        } catch (IOException e) {
          LOG.warn("Can not initialize scripting addition library from bundle: " + e.getMessage());
        }
      }
    }
  }
}
 
Example 17
Project: AppleScript-IDEA   File: AppleScriptSystemDictionaryRegistryService.java   Source Code and License Vote up 5 votes
private static void updateSetForMappedObjectName(@NotNull String objectName,
                                                 @NotNull String nameToAdd,
                                                 @NotNull Map<String, HashSet<String>> objectNameToNameSetMap,
                                                 @Nullable HashSet<String> nameSetForObject) {
  if (nameSetForObject == null) {
    nameSetForObject = new HashSet<>();
    if (!StringUtil.isEmpty(objectName)) {
      objectNameToNameSetMap.put(objectName, nameSetForObject);
    }
  }
  if (!nameSetForObject.contains(nameToAdd)) {
    nameSetForObject.add(nameToAdd);
  }
}
 
Example 18
Project: hybris-integration-intellij-idea-plugin   File: TypeSystemConverterBase.java   Source Code and License Vote up 5 votes
@Nullable
@Override
public final DOM fromString(
    @Nullable @NonNls final String s, final ConvertContext context
) {
    if (StringUtil.isEmpty(s)) {
        return null;
    }
    return searchForName(s, context, TSMetaModelAccess.getInstance(context.getProject()).
        getTypeSystemMeta(context.getFile()));
}
 
Example 19
Project: AppleScript-IDEA   File: AppleScriptScriptCommandLineState.java   Source Code and License Vote up 5 votes
@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
  String scriptPath = runConfiguration.getScriptPath();
  String scriptParameters = runConfiguration.getScriptParameters();
  String scriptOptions = runConfiguration.getScriptOptions();

  scriptPath = scriptPath == null ? "" : scriptPath;//todo change this (and add validator to run config)
  final List<String> commandString = new ArrayList<>();
  commandString.add("/usr/bin/osascript");
  if (!StringUtil.isEmpty(scriptOptions)) {
    String[] options = scriptOptions.split(" ");
    commandString.addAll(Arrays.asList(options));
  }
  commandString.add(scriptPath);
  if (!StringUtil.isEmpty(scriptParameters)) {
    Pattern regex = Pattern.compile("\"([^\"]*)\"|(\\w+)");
    final ArrayList<String> matchedParams = new ArrayList<>();
    Matcher matcher = regex.matcher(scriptParameters);
    while (matcher.find()) {
      for (int i = 1; i <= matcher.groupCount(); i++) {
        try {
          String p = matcher.group(i);
          if (!StringUtil.isEmpty(p)) matchedParams.add(p);
        } catch (IllegalStateException | IndexOutOfBoundsException e) {
          LOG.warn("Error parsing script parameters: " + e.getMessage());
        }
      }
    }
    commandString.addAll(matchedParams);
  }

  final GeneralCommandLine commandLine = new GeneralCommandLine(commandString);
  if (runConfiguration.isShowAppleEvents()) {
    commandLine.withEnvironment("AEDebugSends", "1");
    commandLine.withEnvironment("AEDebugReceives", "1");
  }
  return new AppleScriptProcessHandler(commandLine);
}
 
Example 20
Project: yii2inspections   File: StringLiteralExtractUtil.java   Source Code and License Vote up 4 votes
@Nullable
public static StringLiteralExpression resolveAsStringLiteral(@Nullable PsiElement expression, boolean resolve) {
    if (null == expression) {
        return null;
    }
    expression = getExpressionTroughParenthesis(expression);

    if (expression instanceof StringLiteralExpression) {
        return (StringLiteralExpression) expression;
    }

    if (expression instanceof FieldReference || expression instanceof ClassConstantReference) {
        final Field fieldOrConstant = resolve ? (Field) ((MemberReference) expression).resolve() : null;
        if (null != fieldOrConstant && fieldOrConstant.getDefaultValue() instanceof StringLiteralExpression) {
            return (StringLiteralExpression) fieldOrConstant.getDefaultValue();
        }
    }

    if (expression instanceof Variable) {
        final String variable = ((Variable) expression).getName();
        if (!StringUtil.isEmpty(variable)) {
            final Function scope = getScope(expression);
            if (null != scope) {
                final Set<AssignmentExpression> matched = new HashSet<>();

                Collection<AssignmentExpression> assignments
                        = PsiTreeUtil.findChildrenOfType(scope, AssignmentExpression.class);
                /* collect self-assignments as well */
                for (AssignmentExpression assignment : assignments) {
                    if (assignment.getVariable() instanceof Variable && assignment.getValue() instanceof StringLiteralExpression) {
                        final String name = assignment.getVariable().getName();
                        if (!StringUtil.isEmpty(name) && name.equals(variable)) {
                            matched.add(assignment);
                        }
                    }
                }
                assignments.clear();

                if (matched.size() == 1) {
                    StringLiteralExpression result = (StringLiteralExpression) matched.iterator().next().getValue();

                    matched.clear();
                    return result;
                }
                matched.clear();
            }
        }
    }

    return null;
}