Java 类com.intellij.lang.properties.psi.PropertiesFile 实例源码

项目:intellij-plugin    文件:CoffigDocumentationProvider.java   
private Optional<ConfigInfo> extractConfigInfo(PropertiesFile propertiesFile, CoffigResolver.Match match) {
    Optional<String> description = Optional.ofNullable(propertiesFile.findPropertyByKey(match.getUnmatchedPath())).map(IProperty::getValue);
    if (description.isPresent()) {
        // Base info
        ConfigInfo configInfo = new ConfigInfo(match.getFullPath(), description.get());

        // Extended info
        Optional.ofNullable(propertiesFile.findPropertyByKey(match.getUnmatchedPath() + ".long")).map(IProperty::getValue).ifPresent(configInfo::setLongDescription);

        // Field info
        CoffigResolver.Match resolvedMatch = match.fullyResolve();
        if (resolvedMatch.isFullyResolved()) {
            Optional<PsiField> psiField = resolvedMatch.resolveField(resolvedMatch.getUnmatchedPath());
            psiField.map(PsiVariable::getType).map(PsiType::getPresentableText).ifPresent(configInfo::setType);
        }

        return Optional.of(configInfo);
    }
    return Optional.empty();
}
项目:intellij-plugin    文件:CoffigDocumentationProvider.java   
private Optional<PropertiesFile> findResourceBundle(Project project, PsiClass configClass) {
    String qualifiedName = configClass.getQualifiedName();
    if (qualifiedName != null) {
        int lastDotIndex = qualifiedName.lastIndexOf(".");
        String packageName = qualifiedName.substring(0, lastDotIndex);
        String className = qualifiedName.substring(lastDotIndex + 1);
        PsiPackage psiPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
        if (psiPackage != null) {
            return Arrays.stream(psiPackage.getFiles(GlobalSearchScope.allScope(project)))
                    .filter(psiFile -> psiFile instanceof PropertiesFile && psiFile.getVirtualFile().getNameWithoutExtension().equals(className))
                    .map(psiFile -> (PropertiesFile) psiFile)
                    .findFirst();
        }
    }
    return Optional.empty();
}
项目:intellij-ce-playground    文件:AndroidPropertyFilesUpdater.java   
public static void updateLibraryProperty(@NotNull AndroidFacet facet,
                                       @NotNull final PropertiesFile propertiesFile,
                                       @NotNull List<Runnable> changes) {
final IProperty property = propertiesFile.findPropertyByKey(AndroidUtils.ANDROID_LIBRARY_PROPERTY);

if (property != null) {
  final String value = Boolean.toString(facet.isLibraryProject());

  if (!value.equals(property.getValue())) {
    changes.add(new Runnable() {
      @Override
      public void run() {
        property.setValue(value);
      }
    });
  }
}
else if (facet.isLibraryProject()) {
  changes.add(new Runnable() {
项目:intellij-ce-playground    文件:PropertiesImplUtil.java   
@NotNull
public static List<IProperty> findPropertiesByKey(@NotNull final Project project, @NotNull final String key) {
  final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
  final ArrayList<IProperty> properties =
    new ArrayList<IProperty>(PropertyKeyIndex.getInstance().get(key, project, scope));
  final Set<VirtualFile> files = new HashSet<VirtualFile>();
  FileBasedIndex.getInstance().processValues(XmlPropertiesIndex.NAME, new XmlPropertiesIndex.Key(key), null, new FileBasedIndex.ValueProcessor<String>() {
    @Override
    public boolean process(VirtualFile file, String value) {
      if (files.add(file)) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        PropertiesFile propertiesFile = XmlPropertiesFileImpl.getPropertiesFile(psiFile);
        if (propertiesFile != null) {
          properties.addAll(propertiesFile.findPropertiesByKey(key));
        }
      }
      return false;
    }
  }, scope);
  return properties;
}
项目:intellij-ce-playground    文件:AntMissingPropertiesFileInspection.java   
protected void checkDomElement(DomElement element, DomElementAnnotationHolder holder, DomHighlightingHelper helper) {
  if (element instanceof AntDomProperty) {
    final AntDomProperty property = (AntDomProperty)element;
    final GenericAttributeValue<PsiFileSystemItem> fileValue = property.getFile();
    final String fileName = fileValue.getStringValue();
    if (fileName != null) {
      final PropertiesFile propertiesFile = property.getPropertiesFile();
      if (propertiesFile == null) {
        final PsiFileSystemItem file = fileValue.getValue();
        if (file instanceof XmlFile) {
          holder.createProblem(fileValue, AntBundle.message("file.type.xml.not.supported", fileName));
        }
        else if (file instanceof PsiFile) {
          holder.createProblem(fileValue, AntBundle.message("file.type.not.supported", fileName));
        }
        else {
          holder.createProblem(fileValue, AntBundle.message("file.doesnt.exist", fileName));
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:FormReferencesSearcher.java   
private static boolean processReferencesInUIForms(final Processor<PsiReference> processor,
                                                  PsiManager psiManager,
                                                  final PropertiesFile propFile,
                                                  final GlobalSearchScope globalSearchScope,
                                                  final LocalSearchScope filterScope) {
  final Project project = psiManager.getProject();
  GlobalSearchScope scope = GlobalSearchScope.projectScope(project).intersectWith(globalSearchScope);
  final String baseName = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
    @Override
    public String compute() {
      return propFile.getResourceBundle().getBaseName();
    }
  });
  PsiFile containingFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
    @Override
    public PsiFile compute() {
      return propFile.getContainingFile();
    }
  });

  List<PsiFile> files = Arrays.asList(CacheManager.SERVICE.getInstance(project).getFilesWithWord(baseName, UsageSearchContext.IN_PLAIN_TEXT, scope, true));
  return processReferencesInFiles(files, psiManager, baseName, containingFile, filterScope, processor);
}
项目:intellij-ce-playground    文件:ResourceBundleManager.java   
public void dissociateResourceBundle(final @NotNull ResourceBundle resourceBundle) {
  if (resourceBundle instanceof CustomResourceBundle) {
    final CustomResourceBundleState state =
      getCustomResourceBundleState(resourceBundle.getDefaultPropertiesFile().getVirtualFile());
    LOG.assertTrue(state != null);
    myState.getCustomResourceBundles().remove(state);
  } else {
    if (EmptyResourceBundle.getInstance() != resourceBundle) {
      ((ResourceBundleImpl) resourceBundle).invalidate();
    }
    for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
      final VirtualFile file = propertiesFile.getContainingFile().getVirtualFile();
      myState.getDissociatedFiles().add(file.getUrl());
    }
  }
}
项目:intellij-ce-playground    文件:StringEditorDialog.java   
@Override protected void doOKAction() {
  if (myForm.myRbResourceBundle.isSelected()) {
    final StringDescriptor descriptor = getDescriptor();
    if (descriptor != null && descriptor.getKey().length() > 0) {
      final String value = myForm.myTfRbValue.getText();
      final PropertiesFile propFile = getPropertiesFile(descriptor);
      if (propFile != null && propFile.findPropertyByKey(descriptor.getKey()) == null) {
        saveCreatedProperty(propFile, descriptor.getKey(), value, myEditor.getPsiFile());
      }
      else {
        final String newKeyName = saveModifiedPropertyValue(myEditor.getModule(), descriptor, myLocale, value, myEditor.getPsiFile());
        if (newKeyName != null) {
          myForm.myTfKey.setText(newKeyName);
        }
      }
    }
  }
  super.doOKAction();
}
项目:intellij-ce-playground    文件:PropertiesAnnotator.java   
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  if (!(element instanceof IProperty)) return;
  final Property property = (Property)element;
  PropertiesFile propertiesFile = property.getPropertiesFile();
  Collection<IProperty> others = propertiesFile.findPropertiesByKey(property.getUnescapedKey());
  ASTNode keyNode = ((PropertyImpl)property).getKeyNode();
  if (others.size() != 1) {
    Annotation annotation = holder.createErrorAnnotation(keyNode, PropertiesBundle.message("duplicate.property.key.error.message"));
    annotation.registerFix(PropertiesQuickFixFactory.getInstance().createRemovePropertyFix(property));
  }

  highlightTokens(property, keyNode, holder, new PropertiesHighlighter());
  ASTNode valueNode = ((PropertyImpl)property).getValueNode();
  if (valueNode != null) {
    highlightTokens(property, valueNode, holder, new PropertiesValueHighlighter());
  }
}
项目:intellij-ce-playground    文件:StringEditorDialog.java   
public static boolean saveCreatedProperty(final PropertiesFile bundle, final String name, final String value,
                                          final PsiFile formFile) {
  final ReadonlyStatusHandler.OperationStatus operationStatus =
    ReadonlyStatusHandler.getInstance(bundle.getProject()).ensureFilesWritable(bundle.getVirtualFile());
  if (operationStatus.hasReadonlyFiles()) {
    return false;
  }
  CommandProcessor.getInstance().executeCommand(
    bundle.getProject(),
    new Runnable() {
      public void run() {
        UndoUtil.markPsiFileForUndo(formFile);
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          public void run() {
            try {
              bundle.addProperty(name, value);
            }
            catch (IncorrectOperationException e1) {
              LOG.error(e1);
            }
          }
        });
      }
    }, UIDesignerBundle.message("command.create.property"), null);
  return true;
}
项目:intellij-ce-playground    文件:GuiEditor.java   
private void handleEvent(final PsiTreeChangeEvent event) {
  if (event.getParent() != null) {
    PsiFile containingFile = event.getParent().getContainingFile();
    if (containingFile instanceof PropertiesFile) {
      LOG.debug("Received PSI change event for properties file");
      myAlarm.cancelRequest(myRefreshPropertiesRequest);
      myAlarm.addRequest(myRefreshPropertiesRequest, 500, ModalityState.stateForComponent(GuiEditor.this));
    }
    else if (containingFile instanceof PsiPlainTextFile && containingFile.getFileType().equals(StdFileTypes.GUI_DESIGNER_FORM)) {
      // quick check if relevant
      String resourceName = FormEditingUtil.buildResourceName(containingFile);
      if (myDocument.getText().indexOf(resourceName) >= 0) {
        LOG.debug("Received PSI change event for nested form");
        // TODO[yole]: handle multiple nesting
        myAlarm.cancelRequest(mySynchronizeRequest);
        myAlarm.addRequest(mySynchronizeRequest, 500, ModalityState.stateForComponent(GuiEditor.this));
      }
    }
  }
}
项目:intellij-ce-playground    文件:AlphaUnsortedInspectionTest.java   
public void testUnsortedSuppressed() throws Exception {
  final ExtensionPoint<AlphaUnsortedPropertiesFileInspectionSuppressor> ep =
    Extensions.getRootArea().getExtensionPoint(AlphaUnsortedPropertiesFileInspectionSuppressor.EP_NAME);
  final AlphaUnsortedPropertiesFileInspectionSuppressor suppressor = new AlphaUnsortedPropertiesFileInspectionSuppressor() {
    @Override
    public boolean suppressInspectionFor(PropertiesFile propertiesFile) {
      return propertiesFile.getName().toLowerCase().contains("suppress");
    }
  };
  try {
    ep.registerExtension(suppressor);
    doTest();
  } finally {
    ep.unregisterExtension(suppressor);
  }
}
项目: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;
    }
  });
}
项目:intellij-ce-playground    文件:CreateResourceBundleDialogComponent.java   
private String canCreateAllFilesForAllLocales() {
  final String name = getBaseName();
  if (name.isEmpty()) {
    return "Base name is empty";
  }
  final Set<String> files = getFileNamesToCreate();
  if (files.isEmpty()) {
    return "No locales added";
  }
  for (PsiElement element : myDirectory.getChildren()) {
    if (element instanceof PsiFile) {
      if (element instanceof PropertiesFile) {
        PropertiesFile propertiesFile = (PropertiesFile)element;
        final String propertiesFileName = propertiesFile.getName();
        if (files.contains(propertiesFileName)) {
          return "Some of files already exist";
        }
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:XmlPropertiesTest.java   
public void testAddProperty2() {
  final PsiFile psiFile = myFixture.configureByFile("foo.xml");
  final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
  assertNotNull(propertiesFile);

  WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
    public void run() {
      propertiesFile.addProperty("kkk", "vvv");
    }
  });

  final IProperty property = propertiesFile.findPropertyByKey("kkk");
  assertNotNull(property);
  assertEquals("vvv", property.getValue());

  WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
    public void run() {
      propertiesFile.addProperty("kkk2", "vvv");
    }
  });

  final IProperty property2 = propertiesFile.findPropertyByKey("kkk2");
  assertNotNull(property2);
  assertEquals("vvv", property2.getValue());
}
项目:intellij-ce-playground    文件:CombinePropertiesFilesAction.java   
@Nullable
private static List<PropertiesFile> getPropertiesFiles(AnActionEvent e) {
  final PsiElement[] psiElements = e.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
  if (psiElements == null || psiElements.length == 0) {
    return null;
  }
  final List<PropertiesFile> files = new ArrayList<PropertiesFile>(psiElements.length);
  for (PsiElement psiElement : psiElements) {
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiElement);
    if (propertiesFile == null) {
      return null;
    }
    files.add(propertiesFile);
  }
  return files;
}
项目:intellij-ce-playground    文件:CreatePropertyFix.java   
public static void createProperty(@NotNull final Project project,
                                  @NotNull final PsiElement psiElement,
                                  @NotNull final Collection<PropertiesFile> selectedPropertiesFiles,
                                  @NotNull final String key,
                                  @NotNull final String value) {
  for (PropertiesFile selectedFile : selectedPropertiesFiles) {
    if (!FileModificationService.getInstance().prepareFileForWrite(selectedFile.getContainingFile())) return;
  }
  UndoUtil.markPsiFileForUndo(psiElement.getContainingFile());

  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    public void run() {
      CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        public void run() {
          try {
            I18nUtil.createProperty(project, selectedPropertiesFiles, key, value);
          }
          catch (IncorrectOperationException e) {
            LOG.error(e);
          }
        }
      }, CodeInsightBundle.message("quickfix.i18n.command.name"), project);
    }
  });
}
项目:intellij-ce-playground    文件:PropertiesUtil.java   
@NotNull
public static String getDefaultBaseName(final Collection<PropertiesFile> files) {
  String commonPrefix = null;
  for (PropertiesFile file : files) {
    final String baseName = file.getVirtualFile().getNameWithoutExtension();
    if (commonPrefix == null) {
      commonPrefix = baseName;
    } else {
      commonPrefix = StringUtil.commonPrefix(commonPrefix, baseName);
      if (commonPrefix.isEmpty()) {
        break;
      }
    }
  }
  assert commonPrefix != null;
  if (!commonPrefix.isEmpty() && BASE_NAME_BORDER_CHAR.contains(commonPrefix.charAt(commonPrefix.length() - 1))) {
    commonPrefix = commonPrefix.substring(0, commonPrefix.length() - 1);
  }
  return commonPrefix;
}
项目:intellij-ce-playground    文件:PropertiesUtil.java   
/**
 * messages_en.properties is a parent of the messages_en_US.properties
 */
@Nullable
public static PropertiesFile getParent(PropertiesFile file, List<PropertiesFile> candidates) {
  VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) return null;
  String name = virtualFile.getNameWithoutExtension();
  String[] parts = name.split("_");
  if (parts.length == 1) return null;
  List<String> partsList = Arrays.asList(parts);
  for (int i=parts.length-1; i>=1;i--) {
    String parentName = StringUtil.join(partsList.subList(0, i), "_") + "." + virtualFile.getExtension();
    for (PropertiesFile candidate : candidates) {
      if (parentName.equals(candidate.getName())) return candidate;
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:PropertyKeyReferenceProvider.java   
@Override
protected List<PropertiesFile> retrievePropertyFilesByBundleName(String bundleName, PsiElement element) {
  final List<String> allBundleNames;
  if (bundleName == null) {
    allBundleNames = getPluginResourceBundles(element);
  }
  else {
    allBundleNames = Collections.singletonList(bundleName);
  }

  final Project project = element.getProject();
  final PropertiesReferenceManager propertiesReferenceManager = PropertiesReferenceManager.getInstance(project);
  final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);

  final List<PropertiesFile> allPropertiesFiles = new ArrayList<PropertiesFile>();
  for (String name : allBundleNames) {
    final List<PropertiesFile> propertiesFiles = propertiesReferenceManager
      .findPropertiesFiles(searchScope, name, BundleNameEvaluator.DEFAULT);
    allPropertiesFiles.addAll(propertiesFiles);
  }
  return allPropertiesFiles;
}
项目:intellij-ce-playground    文件:PropertiesCopyHandler.java   
@Override
public void doCopy(PsiElement[] elements, PsiDirectory defaultTargetDirectory) {
  final IProperty representative = PropertiesImplUtil.getProperty(elements[0]);
  final String key = representative.getKey();
  if (key == null) {
    return;
  }
  final ResourceBundle resourceBundle = representative.getPropertiesFile().getResourceBundle();
  final List<IProperty> properties = ContainerUtil.mapNotNull(resourceBundle.getPropertiesFiles(),
                                                              new NullableFunction<PropertiesFile, IProperty>() {
                                                                @Nullable
                                                                @Override
                                                                public IProperty fun(PropertiesFile propertiesFile) {
                                                                  return propertiesFile.findPropertyByKey(key);
                                                                }
                                                              });

  final PropertiesCopyDialog dlg = new PropertiesCopyDialog(properties, resourceBundle);
  if (dlg.showAndGet()) {
    final String propertyNewName = dlg.getCurrentPropertyName();
    final ResourceBundle destinationResourceBundle = dlg.getCurrentResourceBundle();
    copyPropertyToAnotherBundle(properties, propertyNewName, destinationResourceBundle);
  }
}
项目:intellij-ce-playground    文件:XmlPropertiesFileImpl.java   
public static PropertiesFile getPropertiesFile(final PsiFile file) {
  CachedValuesManager manager = CachedValuesManager.getManager(file.getProject());
  if (file instanceof XmlFile) {
    return manager.getCachedValue(file, KEY,
                                  new CachedValueProvider<PropertiesFile>() {
                                    @Override
                                    public Result<PropertiesFile> compute() {
                                      PropertiesFile value =
                                        XmlPropertiesIndex.isPropertiesFile((XmlFile)file)
                                        ? new XmlPropertiesFileImpl((XmlFile)file)
                                        : null;
                                      return Result.create(value, file);
                                    }
                                  }, false
    );
  }
  return null;
}
项目:intellij-ce-playground    文件:JavaCreatePropertyFix.java   
@Nullable
protected Couple<String> invokeAction(@NotNull final Project project,
                                      @NotNull PsiFile file,
                                      @NotNull PsiElement psiElement,
                                      @Nullable final String suggestedKey,
                                      @Nullable String suggestedValue,
                                      @Nullable final List<PropertiesFile> propertiesFiles) {
  final PsiLiteralExpression literalExpression = psiElement instanceof PsiLiteralExpression ? (PsiLiteralExpression)psiElement : null;
  final String propertyValue = suggestedValue == null ? "" : suggestedValue;

  final I18nizeQuickFixDialog dialog = new JavaI18nizeQuickFixDialog(
    project,
    file,
    literalExpression,
    propertyValue,
    createDefaultCustomization(suggestedKey, propertiesFiles),
    false,
    false
  );
  return doAction(project, psiElement, dialog);
}
项目:intellij-ce-playground    文件:ResourceBundleStructureViewComponent.java   
@Override
public void deleteElement(@NotNull final DataContext dataContext) {
  final List<PropertiesFile> bundlePropertiesFiles = myResourceBundle.getPropertiesFiles();

  final List<PsiElement> toDelete = new ArrayList<PsiElement>();
  for (IProperty property : myProperties) {
    final String key = property.getKey();
    if (key == null) {
      LOG.error("key must be not null " + property);
    } else {
      for (PropertiesFile propertiesFile : bundlePropertiesFiles) {
        for (final IProperty iProperty : propertiesFile.findPropertiesByKey(key)) {
          toDelete.add(iProperty.getPsiElement());
        }
      }
    }
  }
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  LOG.assertTrue(project != null);
  new SafeDeleteHandler().invoke(project, PsiUtilCore.toPsiElementArray(toDelete), dataContext);
  myInsertDeleteManager.reload();
}
项目:intellij-ce-playground    文件:ResourceBundlePropertiesUpdateManager.java   
public void insertOrUpdateTranslation(String key, String value, final PropertiesFile propertiesFile) throws IncorrectOperationException {
  final IProperty property = propertiesFile.findPropertyByKey(key);
  if (property != null) {
    property.setValue(value);
    return;
  }

  if (myOrdered) {
    if (myAlphaSorted) {
      propertiesFile.addProperty(key, value);
      return;
    }
    final Pair<IProperty, Integer> propertyAndPosition = findExistedPrevSiblingProperty(key, propertiesFile);
    propertiesFile.addPropertyAfter(key, value, propertyAndPosition == null ? null : (Property)propertyAndPosition.getFirst());
  }
  else {
    insertPropertyLast(key, value, propertiesFile);
  }
}
项目:intellij-ce-playground    文件:PropertiesReferenceManager.java   
@NotNull
public List<PropertiesFile> findPropertiesFiles(@NotNull final GlobalSearchScope searchScope,
                                                final String bundleName,
                                                BundleNameEvaluator bundleNameEvaluator) {


  final ArrayList<PropertiesFile> result = new ArrayList<PropertiesFile>();
  processPropertiesFiles(searchScope, new PropertiesFileProcessor() {
    public boolean process(String baseName, PropertiesFile propertiesFile) {
      if (baseName.equals(bundleName)) {
        result.add(propertiesFile);
      }
      return true;
    }
  }, bundleNameEvaluator);
  return result;
}
项目:hybris-integration-intellij-idea-plugin    文件:JspPropertyFoldingBuilder.java   
private static Locale safeGetLocale(final @NotNull IProperty property) {
    try {
        PropertiesFile file = property.getPropertiesFile();
        return file == null ? null : file.getLocale();
    } catch (PsiInvalidElementAccessException e) {
        return null;
    }
}
项目:intellij-ce-playground    文件:I18nizeTest.java   
private void doTest(@NonNls String ext) throws Exception {
  configureByFile(getBasePath() + "/before"+getTestName(false)+"."+ext);
  I18nizeAction action = new I18nizeAction();
  DataContext dataContext = DataManager.getInstance().getDataContext(myEditor.getComponent());
  AnActionEvent event = AnActionEvent.createFromAnAction(action, null, "place", dataContext);
  action.update(event);
  @NonNls String afterFile = getBasePath() + "/after" + getTestName(false) + "." + ext;
  boolean afterFileExists = new File(PathManagerEx.getTestDataPath() + afterFile).exists();
  I18nQuickFixHandler handler = I18nizeAction.getHandler(event);
  try {
    if (handler != null) {
      handler.checkApplicability(getFile(), getEditor());
    }
  }
  catch (IncorrectOperationException e) {
    event.getPresentation().setEnabled(false);
  }
  assertEquals(afterFileExists, event.getPresentation().isEnabled());

  if (afterFileExists) {
    PsiLiteralExpression literalExpression = I18nizeAction.getEnclosingStringLiteral(getFile(), getEditor());
    assertNotNull(handler);
    handler.performI18nization(getFile(), getEditor(), literalExpression, Collections.<PropertiesFile>emptyList(), "key1", "value1", "i18nizedExpr",
                               PsiExpression.EMPTY_ARRAY, JavaI18nUtil.DEFAULT_PROPERTY_CREATION_HANDLER);
    checkResultByFile(afterFile);
  }
}
项目:intellij-ce-playground    文件: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 = PropertiesImplUtil.findPropertiesByKey(getProject(), "foo");
  assertEquals(1, properties.size());
}
项目:intellij-ce-playground    文件:AndroidRootUtil.java   
@Nullable
public static Pair<PropertiesFile, VirtualFile> findPropertyFile(@NotNull Module module, @NotNull String propertyFileName) {
  for (VirtualFile contentRoot : ModuleRootManager.getInstance(module).getContentRoots()) {
    VirtualFile vFile = contentRoot.findChild(propertyFileName);
    if (vFile != null) {
      PsiFile psiFile = AndroidPsiUtils.getPsiFileSafely(module.getProject(), vFile);
      if (psiFile instanceof PropertiesFile) {
        return Pair.create((PropertiesFile)psiFile, vFile);
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:CustomResourceBundleTest.java   
public void testCustomResourceBundleFilesMovedOrDeleted() throws IOException {
  final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("resources-dev/my-app-dev.properties", ""));
  final PropertiesFile file2 = PropertiesImplUtil.getPropertiesFile(
    myFixture.addFileToProject("resources-dev/my-app-test.properties", ""));
  final PropertiesFile file3 = PropertiesImplUtil.getPropertiesFile(
    myFixture.addFileToProject("resources-prod/my-app-prod.properties", ""));
  assertNotNull(file);
  assertNotNull(file2);
  assertNotNull(file3);
  assertOneElement(file.getResourceBundle().getPropertiesFiles());
  assertOneElement(file2.getResourceBundle().getPropertiesFiles());
  assertOneElement(file3.getResourceBundle().getPropertiesFiles());
  final ResourceBundleManager resourceBundleBaseNameManager = ResourceBundleManager.getInstance(getProject());
  resourceBundleBaseNameManager.combineToResourceBundle(list(file, file2, file3), "my-app");

  assertSize(3, file.getResourceBundle().getPropertiesFiles());

  final PsiDirectory newDir = PsiManager.getInstance(getProject()).findDirectory(
    myFixture.getTempDirFixture().findOrCreateDir("new-resources-dir"));
  new MoveFilesOrDirectoriesProcessor(getProject(), new PsiElement[] {file2.getContainingFile()}, newDir, false, false, null, null).run();
  file3.getContainingFile().delete();

  assertSize(2, file.getResourceBundle().getPropertiesFiles());

  final ResourceBundleManagerState state = ResourceBundleManager.getInstance(getProject()).getState();
  assertNotNull(state);
  assertSize(1, state.getCustomResourceBundles());
  assertSize(2, state.getCustomResourceBundles().get(0).getFileUrls());
}
项目:intellij-ce-playground    文件:AlphaUnsortedPropertiesFileInspection.java   
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  final boolean force = myFilesToSort.length == 1;
  for (PropertiesFile file : myFilesToSort) {
    if (!force && file.isAlphaSorted()) {
      continue;
    }
    sortPropertiesFile(file);
  }
}
项目:intellij-ce-playground    文件:MvcModuleStructureUtil.java   
@Nullable
public static PropertiesFile findApplicationProperties(@NotNull Module module, MvcFramework framework) {
  VirtualFile root = framework.findAppRoot(module);
  if (root == null) return null;

  VirtualFile appChild = root.findChild(APPLICATION_PROPERTIES);
  if (appChild == null || !appChild.isValid()) return null;

  PsiManager manager = PsiManager.getInstance(module.getProject());
  PsiFile psiFile = manager.findFile(appChild);
  if (psiFile instanceof PropertiesFile) {
    return (PropertiesFile)psiFile;
  }
  return null;
}
项目: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;
}
项目:intellij-ce-playground    文件:ResourceBundleManager.java   
public void combineToResourceBundle(final @NotNull List<PropertiesFile> propertiesFiles, final String baseName) {
  myState.getCustomResourceBundles()
    .add(new CustomResourceBundleState().addAll(ContainerUtil.map(propertiesFiles, new Function<PropertiesFile, String>() {
      @Override
      public String fun(PropertiesFile file) {
        return file.getVirtualFile().getUrl();
      }
    })).setBaseName(baseName));
}
项目:intellij-ce-playground    文件:CustomResourceBundle.java   
private CustomResourceBundle(final List<PropertiesFile> files, final @NotNull String baseName) {
  LOG.assertTrue(!files.isEmpty());
  myFiles = new ArrayList<PropertiesFile>(files);
  Collections.sort(myFiles, new Comparator<PropertiesFile>() {
    @Override
    public int compare(PropertiesFile f1, PropertiesFile f2) {
      return f1.getName().compareTo(f2.getName());
    }
  });
  myBaseName = baseName;
}
项目:intellij-ce-playground    文件:PropertiesUtil.java   
public static boolean isPropertyComplete(final ResourceBundle resourceBundle, final String propertyName) {
  List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
  for (PropertiesFile propertiesFile : propertiesFiles) {
    if (propertiesFile.findPropertyByKey(propertyName) == null) return false;
  }
  return true;
}
项目:intellij-ce-playground    文件:AntDomProperty.java   
@Nullable
private static PropertiesFile toPropertiesFile(@Nullable final PsiFileSystemItem item) {
  if (item instanceof PropertiesFile) {
    return (PropertiesFile)item;
  }
  // Sometimes XmlPropertiesFile is just XmlFile, sao we should ask PropertiesImplUtil about that.
  return item instanceof PsiFile? PropertiesImplUtil.getPropertiesFile(((PsiFile)item)) : null;
}
项目:intellij-ce-playground    文件:ResourceBundleEditorInsertManagerTest.java   
public void testIsAlphaSorted() {
  myFixture.configureByFile(getTestName(true) + "/p.properties");
  myFixture.configureByFile(getTestName(true) + "/p_en.properties");
  myFixture.configureByFile(getTestName(true) + "/p_fr.properties");
  final PsiFile file = myFixture.configureByFile(getTestName(true) + "/p_ru.properties");
  final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
  final ResourceBundlePropertiesUpdateManager
    manager = new ResourceBundlePropertiesUpdateManager(propertiesFile.getResourceBundle());
  manager.reload();
  assertTrue(manager.isAlphaSorted());
}
项目:intellij-ce-playground    文件:ResourceBundleTest.java   
public void testDefaultPropertyFile() {
  final PsiFile rawDefault = myFixture.addFileToProject("p.properties", "");
  myFixture.addFileToProject("p_en.properties", "");
  final PropertiesFile defaultFile = PropertiesImplUtil.getPropertiesFile(rawDefault);
  assertNotNull(defaultFile);
  final PropertiesFile file = defaultFile.getResourceBundle().getDefaultPropertiesFile();
  assertTrue(file.getContainingFile().isEquivalentTo(defaultFile.getContainingFile()));
}