Java 类com.intellij.lang.properties.PropertiesUtil 实例源码

项目:intellij-ce-playground    文件:IgnoredPropertiesFilesSuffixesManager.java   
public List<PropertiesFile> getPropertiesFilesWithoutTranslation(final ResourceBundle resourceBundle, final Set<String> keys) {
  final PropertiesFile defaultPropertiesFile = resourceBundle.getDefaultPropertiesFile();
  return ContainerUtil.filter(resourceBundle.getPropertiesFiles(), new Condition<PropertiesFile>() {
    @Override
    public boolean value(PropertiesFile propertiesFile) {
      if (defaultPropertiesFile.equals(propertiesFile)) {
        return false;
      }
      for (String key : keys) {
        if (propertiesFile.findPropertyByKey(key) == null && !myState.getIgnoredSuffixes().contains(PropertiesUtil.getSuffix(propertiesFile))) {
          return true;
        }
      }
      return false;
    }
  });
}
项目:tools-idea    文件:ResourceBundleKeyReference.java   
public PsiElement resolve() {
  final Project project = myFile.getProject();
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final VirtualFile formVirtualFile = myFile.getVirtualFile();
  if (formVirtualFile == null) {
    return null;
  }
  final Module module = fileIndex.getModuleForFile(formVirtualFile);
  if (module == null) {
    return null;
  }
  final PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(myBundleName, module, null);
  if (propertiesFile == null) {
    return null;
  }
  IProperty property = propertiesFile.findPropertyByKey(getRangeText());
  return property == null ? null : property.getPsiElement();
}
项目:tools-idea    文件:StringDescriptorManager.java   
public IProperty resolveToProperty(@NotNull StringDescriptor descriptor, @Nullable Locale locale) {
  String propFileName = descriptor.getDottedBundleName();
  Pair<Locale, String> cacheKey = new Pair<Locale, String>(locale, propFileName);
  SoftReference<PropertiesFile> propertiesFileRef;
  synchronized (myPropertiesFileCache) {
    propertiesFileRef = myPropertiesFileCache.get(cacheKey);
  }
  PropertiesFile propertiesFile = (propertiesFileRef == null) ? null : propertiesFileRef.get();
  if (propertiesFile == null || !propertiesFile.getContainingFile().isValid()) {
    propertiesFile = PropertiesUtil.getPropertiesFile(propFileName, myModule, locale);
    synchronized (myPropertiesFileCache) {
      myPropertiesFileCache.put(cacheKey, new SoftReference<PropertiesFile>(propertiesFile));
    }
  }

  if (propertiesFile != null) {
    final IProperty propertyByKey = propertiesFile.findPropertyByKey(descriptor.getKey());
    if (propertyByKey != null) {
      return propertyByKey;
    }
  }
  return null;
}
项目:tools-idea    文件:ResourceBundlePropertyStructureViewElement.java   
public ItemPresentation getPresentation() {
  return new ColoredItemPresentation() {
    public String getPresentableText() {
      return myPresentableName == null ? myPropertyName : myPresentableName;
    }

    public String getLocationString() {
      return null;
    }

    public Icon getIcon(boolean open) {
      return PlatformIcons.PROPERTY_ICON;
    }

    @Override
    public TextAttributesKey getTextAttributesKey() {
      boolean isComplete = PropertiesUtil.isPropertyComplete(myProject, myResourceBundle, myPropertyName);

      if (isComplete) {
        return PropertiesHighlighter.PROPERTY_KEY;
      }
      return INCOMPLETE_PROPERTY_KEY;
    }
  };
}
项目:tools-idea    文件:ResourceBundleEditorProvider.java   
@NotNull
public FileEditor createEditor(@NotNull Project project, @NotNull final VirtualFile file){
  ResourceBundle resourceBundle;
  if (file instanceof ResourceBundleAsVirtualFile) {
    resourceBundle = ((ResourceBundleAsVirtualFile)file).getResourceBundle();
  }
  else {
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile == null) {
      throw new IllegalArgumentException("psifile cannot be null");
    }
    resourceBundle = PropertiesUtil.getPropertiesFile(psiFile).getResourceBundle();
  }

  return new ResourceBundleEditor(project, resourceBundle);
}
项目:tools-idea    文件:ResourceBundleEditor.java   
private void updatePropertyValueFromDocument(final String propertyName,
                                             final PropertiesFile propertiesFile,
                                             final String text) {
  if (PropertiesUtil.isUnescapedBackSlashAtTheEnd(text)) {
    myBackSlashPressed.add(propertiesFile);
  }
  else {
    myBackSlashPressed.remove(propertiesFile);
  }
  IProperty property = propertiesFile.findPropertyByKey(propertyName);
  try {
    if (property == null) {
      propertiesFile.addProperty(propertyName, text);
    }
    else {
      property.setValue(text);
    }
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
项目:errai-intellij-idea-plugin    文件:DataBindUtil.java   
public static Set<String> getConfiguredBindableTypes(Project project) {
  final Set<String> bindableTypes = new HashSet<String>();

  for (PsiFile file : Util.getAllErraiAppProperties(project)) {
    for (IProperty property
        : PropertiesUtil.findAllProperties(project, PropertiesUtil.getResourceBundle(file), "errai.ui.bindableTypes")) {
      final String value = property.getValue();
      if (value != null) {
        for (String s : value.split("\\s+")) {
          bindableTypes.add(s.trim());
        }
      }
    }
  }

  return bindableTypes;
}
项目:errai-intellij-idea-plugin    文件:MarshallingUtil.java   
public static Set<String> getConfiguredPortableTypes(Project project) {
  final Set<String> bindableTypes = new HashSet<String>();

  for (PsiFile file : Util.getAllErraiAppProperties(project)) {
    for (IProperty property
        : PropertiesUtil.findAllProperties(project,
        PropertiesUtil.getResourceBundle(file), "errai.marshalling.serializableTypes")) {
      final String value = property.getValue();
      if (value != null) {
        for (String s : value.split("\\s+")) {
          bindableTypes.add(s.trim());
        }
      }
    }
  }

  return bindableTypes;
}
项目:consulo-ui-designer    文件:ResourceBundleKeyReference.java   
public PsiElement resolve() {
  final Project project = myFile.getProject();
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final VirtualFile formVirtualFile = myFile.getVirtualFile();
  if (formVirtualFile == null) {
    return null;
  }
  final Module module = fileIndex.getModuleForFile(formVirtualFile);
  if (module == null) {
    return null;
  }
  final PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(myBundleName, module, null);
  if (propertiesFile == null) {
    return null;
  }
  IProperty property = propertiesFile.findPropertyByKey(getRangeText());
  return property == null ? null : property.getPsiElement();
}
项目:consulo-ui-designer    文件:StringDescriptorManager.java   
public IProperty resolveToProperty(@NotNull StringDescriptor descriptor, @Nullable Locale locale) {
  String propFileName = descriptor.getDottedBundleName();
  Pair<Locale, String> cacheKey = new Pair<Locale, String>(locale, propFileName);
  SoftReference<PropertiesFile> propertiesFileRef;
  synchronized (myPropertiesFileCache) {
    propertiesFileRef = myPropertiesFileCache.get(cacheKey);
  }
  PropertiesFile propertiesFile = (propertiesFileRef == null) ? null : propertiesFileRef.get();
  if (propertiesFile == null || !propertiesFile.getContainingFile().isValid()) {
    propertiesFile = PropertiesUtil.getPropertiesFile(propFileName, myModule, locale);
    synchronized (myPropertiesFileCache) {
      myPropertiesFileCache.put(cacheKey, new SoftReference<PropertiesFile>(propertiesFile));
    }
  }

  if (propertiesFile != null) {
    final IProperty propertyByKey = propertiesFile.findPropertyByKey(descriptor.getKey());
    if (propertyByKey != null) {
      return propertyByKey;
    }
  }
  return null;
}
项目:consulo-google-guice    文件:NamedReference.java   
@NotNull
public ResolveResult[] multiResolve(boolean incompleteCode){
    final String text = element.getText();
    final String strippedText = text.substring(1, text.length() - 1);
  // TODO[yole] figure out what was meant here. this never works and never could have worked.
    final List<IProperty> properties =
            PropertiesUtil.findAllProperties(element.getProject(), null, strippedText);
    final Set<IProperty> propertySet = new HashSet<IProperty>(properties);
    final ResolveResult[] out = new ResolveResult[propertySet.size()];
    int i = 0;
    for(IProperty property : propertySet){
        out[i] = new CandidateInfo(property.getPsiElement(), null);
        i++;
    }

    return out;
}
项目:intellij-ce-playground    文件:EnterInPropertiesFileHandler.java   
private static void handleEnterInPropertiesFile(final Editor editor,
                                                final Document document,
                                                final PsiElement psiAtOffset,
                                                int caretOffset) {
  String text = document.getText();
  String line = text.substring(0, caretOffset);
  int i = line.lastIndexOf('\n');
  if (i > 0) {
    line = line.substring(i);
  }
  final String toInsert;
  if (PropertiesUtil.isUnescapedBackSlashAtTheEnd(line)) {
    toInsert = "\n  ";
  }
  else {
    final IElementType elementType = psiAtOffset == null ? null : psiAtOffset.getNode().getElementType();

    if (elementType == PropertiesTokenTypes.VALUE_CHARACTERS) {
      toInsert = "\\\n  ";
    }
    else if (elementType == PropertiesTokenTypes.END_OF_LINE_COMMENT && "#!".indexOf(document.getText().charAt(caretOffset)) == -1) {
      toInsert = "\n#";
    }
    else {
      toInsert = "\n";
    }
  }
  document.insertString(caretOffset, toInsert);
  caretOffset+=toInsert.length();
  editor.getCaretModel().moveToOffset(caretOffset);
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  editor.getSelectionModel().removeSelection();
}
项目:intellij-ce-playground    文件:CombinePropertiesFilesAction.java   
@Nullable
private BaseNameError checkBaseName(final String baseNameCandidate) {
  for (PropertiesFile propertiesFile : myPropertiesFiles) {
    final String name = propertiesFile.getVirtualFile().getName();
    if (!name.startsWith(baseNameCandidate) || !PropertiesUtil.BASE_NAME_BORDER_CHAR.contains(name.charAt(baseNameCandidate.length()))) {
      return new BaseNameError(name);
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:RenamePropertyProcessor.java   
public void prepareRenaming(final PsiElement element, final String newName,
                            final Map<PsiElement, String> allRenames) {
  ResourceBundle resourceBundle = PropertiesImplUtil.getProperty(element).getPropertiesFile().getResourceBundle();

  final Map<PsiElement, String> allRenamesCopy = new LinkedHashMap<PsiElement, String>(allRenames);
  allRenames.clear();
  for (final Map.Entry<PsiElement, String> e : allRenamesCopy.entrySet()) {
    final IProperty property = PropertiesImplUtil.getProperty(e.getKey());
    final List<IProperty> properties = PropertiesUtil.findAllProperties(resourceBundle, property.getUnescapedKey());
    for (final IProperty toRename : properties) {
      allRenames.put(toRename.getPsiElement(), e.getValue());
    }
  }
}
项目:intellij-ce-playground    文件:IgnoredPropertiesFilesSuffixesManager.java   
public boolean isPropertyComplete(final ResourceBundle resourceBundle, final String key) {
  List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
  for (PropertiesFile propertiesFile : propertiesFiles) {
    if (propertiesFile.findPropertyByKey(key) == null && !myState.getIgnoredSuffixes().contains(PropertiesUtil.getSuffix(propertiesFile))) {
        return false;
    }
  }
  return true;
}
项目:tools-idea    文件:ResourceBundleKeyReference.java   
public boolean isReferenceTo(final PsiElement element) {
  if (!(element instanceof IProperty)) {
    return false;
  }
  IProperty property = (IProperty) element;
  String baseName = PropertiesUtil.getFullName(property.getPropertiesFile());
  return baseName != null && myBundleName.equals(baseName.replace('.', '/')) && getRangeText().equals(property.getUnescapedKey());
}
项目:tools-idea    文件:ResourceBundleFileReference.java   
public PsiElement resolve() {
  final Project project = myFile.getProject();

  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final VirtualFile formVirtualFile = myFile.getVirtualFile();
  if (formVirtualFile == null) {
    return null;
  }
  final Module module = fileIndex.getModuleForFile(formVirtualFile);
  if (module == null) {
    return null;
  }
  PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(getRangeText(), module, null);
  return propertiesFile == null ? null : propertiesFile.getContainingFile();
}
项目:tools-idea    文件:ResourceBundleFileReference.java   
@Override
public boolean isReferenceTo(final PsiElement element) {
  if (!(element instanceof PropertiesFile)) return false;
  String baseName = PropertiesUtil.getFullName((PropertiesFile) element);
  if (baseName == null) return false;
  baseName = baseName.replace('.', '/');
  final String rangeText = getRangeText();
  return rangeText.equals(baseName);
}
项目:tools-idea    文件:EnterInPropertiesFileHandler.java   
private static void handleEnterInPropertiesFile(final Editor editor,
                                                final Document document,
                                                final PsiElement psiAtOffset,
                                                int caretOffset) {
  String text = document.getText();
  String line = text.substring(0, caretOffset);
  int i = line.lastIndexOf('\n');
  if (i > 0) {
    line = line.substring(i);
  }
  final String toInsert;
  if (PropertiesUtil.isUnescapedBackSlashAtTheEnd(line)) {
    toInsert = "\n  ";
  }
  else {
    final IElementType elementType = psiAtOffset == null ? null : psiAtOffset.getNode().getElementType();

    if (elementType == PropertiesTokenTypes.VALUE_CHARACTERS) {
      toInsert = "\\\n  ";
    }
    else if (elementType == PropertiesTokenTypes.END_OF_LINE_COMMENT && "#!".indexOf(document.getText().charAt(caretOffset)) == -1) {
      toInsert = "\n#";
    }
    else {
      toInsert = "\n";
    }
  }
  document.insertString(caretOffset, toInsert);
  caretOffset+=toInsert.length();
  editor.getCaretModel().moveToOffset(caretOffset);
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  editor.getSelectionModel().removeSelection();
}
项目:tools-idea    文件:XmlPropertiesReferenceContributor.java   
@Override
public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
  registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withLocalName("key"),
                                      new PsiReferenceProvider() {
    @NotNull
    @Override
    public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
      PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(element.getContainingFile());
      if (propertiesFile == null) return PsiReference.EMPTY_ARRAY;
      XmlProperty property = new XmlProperty(PsiTreeUtil.getParentOfType(element, XmlTag.class), (XmlPropertiesFile)propertiesFile);
      return new PsiReference[] { new PsiReferenceBase.Immediate<PsiElement>(element, PomService.convertToPsi(property))};
    }
  });
}
项目:tools-idea    文件:RenamePropertyProcessor.java   
public void prepareRenaming(final PsiElement element, final String newName,
                            final Map<PsiElement, String> allRenames) {
  IProperty property = (IProperty) element;
  ResourceBundle resourceBundle = property.getPropertiesFile().getResourceBundle();
  List<IProperty> properties = PropertiesUtil.findAllProperties(element.getProject(), resourceBundle, property.getUnescapedKey());
  allRenames.clear();
  for (IProperty otherProperty : properties) {
    allRenames.put(otherProperty.getPsiElement(), newName);
  }
}
项目:tools-idea    文件:XmlPropertiesTest.java   
public void testXmlProperties() throws Exception {
  myFixture.configureByFile("foo.xml");
  List<PropertiesFile> files = PropertiesReferenceManager.getInstance(getProject()).findPropertiesFiles(myModule, "foo");
  assertEquals(1, files.size());
  PropertiesFile file = files.get(0);
  assertEquals(1, file.findPropertiesByKey("foo").size());

  List<IProperty> properties = PropertiesUtil.findPropertiesByKey(getProject(), "foo");
  assertEquals(1, properties.size());
}
项目:tools-idea    文件:JavaI18nUtil.java   
public static boolean isPropertyRef(final PsiLiteralExpression expression, final String key, final String resourceBundleName) {
  if (resourceBundleName == null) {
    return !PropertiesUtil.findPropertiesByKey(expression.getProject(), key).isEmpty();
  }
  else {
    final List<PropertiesFile> propertiesFiles = propertiesFilesByBundleName(resourceBundleName, expression);
    boolean containedInPropertiesFile = false;
    for (PropertiesFile propertiesFile : propertiesFiles) {
      containedInPropertiesFile |= propertiesFile.findPropertyByKey(key) != null;
    }
    return containedInPropertiesFile;
  }
}
项目:consulo-ui-designer    文件:ResourceBundleKeyReference.java   
public boolean isReferenceTo(final PsiElement element) {
  if (!(element instanceof IProperty)) {
    return false;
  }
  IProperty property = (IProperty) element;
  String baseName = PropertiesUtil.getFullName(property.getPropertiesFile());
  return baseName != null && myBundleName.equals(baseName.replace('.', '/')) && getRangeText().equals(property.getUnescapedKey());
}
项目:consulo-ui-designer    文件:ResourceBundleFileReference.java   
public PsiElement resolve() {
  final Project project = myFile.getProject();

  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final VirtualFile formVirtualFile = myFile.getVirtualFile();
  if (formVirtualFile == null) {
    return null;
  }
  final Module module = fileIndex.getModuleForFile(formVirtualFile);
  if (module == null) {
    return null;
  }
  PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(getRangeText(), module, null);
  return propertiesFile == null ? null : propertiesFile.getContainingFile();
}
项目:consulo-ui-designer    文件:ResourceBundleFileReference.java   
@Override
public boolean isReferenceTo(final PsiElement element) {
  if (!(element instanceof PropertiesFile)) return false;
  String baseName = PropertiesUtil.getFullName((PropertiesFile) element);
  if (baseName == null) return false;
  baseName = baseName.replace('.', '/');
  final String rangeText = getRangeText();
  return rangeText.equals(baseName);
}
项目:consulo-google-guice    文件:NamedReference.java   
public Object[] getVariants(){
    // TODO[yole] figure out what was meant here. this never works and never could have worked.
    final List<IProperty> properties = PropertiesUtil.findAllProperties(element.getProject(), null, null);
    final List<Object> out = new ArrayList<Object>();
    for(IProperty property : properties){
        out.add(property.getName());
    }

    return out.toArray(new Object[out.size()]);
}
项目:consulo-java    文件:JavaI18nUtil.java   
public static boolean isPropertyRef(final PsiLiteralExpression expression, final String key, final String resourceBundleName) {
  if (resourceBundleName == null) {
    return !PropertiesUtil.findPropertiesByKey(expression.getProject(), key).isEmpty();
  }
  else {
    final List<PropertiesFile> propertiesFiles = propertiesFilesByBundleName(resourceBundleName, expression);
    boolean containedInPropertiesFile = false;
    for (PropertiesFile propertiesFile : propertiesFiles) {
      containedInPropertiesFile |= propertiesFile.findPropertyByKey(key) != null;
    }
    return containedInPropertiesFile;
  }
}
项目:intellij-ce-playground    文件:IgnoreIncompletePropertyPropertiesFilesAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
  final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor)PlatformDataKeys.FILE_EDITOR.getData(e.getDataContext());
  LOG.assertTrue(resourceBundleEditor != null);
  final Project project = getEventProject(e);
  LOG.assertTrue(project != null);

  final Set<String> properties = new HashSet<String>();
  processSelectedIncompleteProperties(new Processor<IProperty>() {
    @Override
    public boolean process(IProperty property) {
      properties.add(property.getKey());
      return true;
    }
  }, resourceBundleEditor, project);

  final IgnoredPropertiesFilesSuffixesManager suffixesManager = IgnoredPropertiesFilesSuffixesManager.getInstance(project);
  final List<PropertiesFile> allFilesWithoutTranslation =
    suffixesManager.getPropertiesFilesWithoutTranslation(resourceBundleEditor.getResourceBundle(), properties);
  if (allFilesWithoutTranslation.isEmpty()) {
    return;
  }
  Collections.sort(allFilesWithoutTranslation, new Comparator<PropertiesFile>() {
    @Override
    public int compare(PropertiesFile p1, PropertiesFile p2) {
      return p1.getName().compareTo(p2.getName());
    }
  });

  final List<PropertiesFile> suffixRepresentatives =
    new IgnoredSuffixesDialog(allFilesWithoutTranslation, project).showAndGetSuffixesRepresentatives();
  if (suffixRepresentatives == null) {
    return;
  }
  final List<String> suffixesToIgnore = ContainerUtil.map(suffixRepresentatives, new NotNullFunction<PropertiesFile, String>() {
    @NotNull
    @Override
    public String fun(PropertiesFile propertiesFile) {
      return PropertiesUtil.getSuffix(propertiesFile);
    }
  });
  if (!suffixesToIgnore.isEmpty()) {
    suffixesManager.addSuffixes(suffixesToIgnore);
    UIUtil.invokeLaterIfNeeded(new Runnable() {
      @Override
      public void run() {
        resourceBundleEditor.queueUpdateTree();
      }
    });
  }
}
项目:intellij-ce-playground    文件:XmlPropertiesFileImpl.java   
@NotNull
@Override
public Locale getLocale() {
  return PropertiesUtil.getLocale(this);
}
项目:tools-idea    文件:XmlPropertiesFile.java   
@NotNull
@Override
public ResourceBundle getResourceBundle() {
  return PropertiesUtil.getResourceBundle(getContainingFile());
}
项目:tools-idea    文件:XmlPropertiesFile.java   
@NotNull
@Override
public Locale getLocale() {
  return PropertiesUtil.getLocale(getVirtualFile());
}
项目:tools-idea    文件:ResourceBundleNode.java   
public boolean contains(@NotNull VirtualFile file) {
  if (!file.isValid()) return false;
  PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
  PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(psiFile);
  return propertiesFile != null && getValue().getPropertiesFiles(myProject).contains(propertiesFile);
}
项目:tools-idea    文件:PropertiesFileImpl.java   
@Override
@NotNull
public ResourceBundle getResourceBundle() {
  return PropertiesUtil.getResourceBundle(getContainingFile());
}
项目:tools-idea    文件:PropertiesFileImpl.java   
@Override
@NotNull
public Locale getLocale() {
  return PropertiesUtil.getLocale(getVirtualFile());
}
项目:tools-idea    文件:ResourceBundleEditorProvider.java   
public boolean accept(@NotNull Project project, @NotNull VirtualFile file){
  if (file instanceof ResourceBundleAsVirtualFile) return true;
  PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
  PropertiesFile propertiesFile = PropertiesUtil.getPropertiesFile(psiFile);
  return propertiesFile != null &&  propertiesFile.getResourceBundle().getPropertiesFiles(project).size() > 1;
}
项目:tools-idea    文件:XmlPropertiesTest.java   
public void testWrongFile() throws Exception {
  PsiFile psiFile = myFixture.configureByFile("wrong.xml");
  PropertiesFile file = PropertiesUtil.getPropertiesFile(psiFile);
  assertNull(file);
}