@Nullable private PsiElement resolveToCustomSystemProperty(@NotNull String propertyName, @Nullable String propertyValue) { if (propertyValue == null) return null; PsiFile propFile = PsiFileFactory.getInstance(myProject).createFileFromText("SystemProperties.properties", PropertiesLanguage.INSTANCE, propertyName + '=' + propertyValue); return ((PropertiesFile)propFile).getProperties().get(0).getPsiElement(); }
protected void prepareTemplate(@NotNull Template template, @NotNull final PsiElement element, String relativePath, @NotNull final PsiFile fileToInsertComment) { final List<String> allFiles = Util.collectFilePaths(element, new Function<PsiFile, String>() { public String fun(@NotNull final PsiFile psiFile) { PsiFile file = psiFile.getViewProvider().getPsi(PropertiesLanguage.INSTANCE); if (!(file instanceof PropertiesFile)) { return null; } final VelocityPropertiesProvider propertiesProvider = new VelocityPropertiesProvider((PropertiesFile)file); List<PsiFile> macroLibs = collectReferencedLibFiles(ModuleUtil.findModuleForPsiElement(element), propertiesProvider); for (PsiFile macroLib : macroLibs) { if (!(macroLib instanceof VtlFile) || ((VtlFile)macroLib).getNumberOfMacros(((VtlReferenceExpression)element).getReferenceName()) <= 0) { continue; } VirtualFile vFile = macroLib.getViewProvider().getVirtualFile(); String res = Util.computeFilePath(propertiesProvider, vFile.getPath(), vFile.getName(), fileToInsertComment); if(res != null) return res; } return null; } }); template.addTextSegment("#* @velocityproperties path="); final Expression pathExpression = new StringCollectionExpression(allFiles); template.addVariable("PATH", pathExpression, pathExpression, true); final String fileRef = relativePath != null ? " file=\"" + relativePath + "\"" : ""; template.addTextSegment(fileRef + " *#\n"); template.addEndVariable(); }
private static List<String> computeFilePaths(final PsiElement element, final PsiFile fileToInsertComment) { final VtlFileReferenceSet refSet = findVtlFileReferenceSet(element); if (refSet == null) { return Collections.emptyList(); } final PsiFile[] referencedFiles = findReferencedFiles(ModuleUtil.findModuleForPsiElement(element), refSet.getLastReference().getCanonicalText()); if (referencedFiles.length == 0) { return Collections.emptyList(); } return collectFilePaths(element, new Function<PsiFile, String>() { public String fun(@NotNull final PsiFile psiFile) { PsiFile file = psiFile.getViewProvider().getPsi(PropertiesLanguage.INSTANCE); if (file instanceof PropertiesFile) { PropertiesFile propFile = (PropertiesFile)file; VelocityPropertiesProvider velocityProperties = new VelocityPropertiesProvider(propFile); for (PsiFile referencedFile : referencedFiles) { String referencedFilePath = referencedFile.getViewProvider().getVirtualFile().getPath(); String filePath = computeFilePath(velocityProperties, referencedFilePath, refSet.getPathString(), fileToInsertComment); if (filePath != null) return filePath; } } return null; } }); }
public PropertiesCompletionContributor() { extend(CompletionType.BASIC, PlatformPatterns.psiElement().withLanguage(PropertiesLanguage.INSTANCE), new PropertiesCompletionProvider()); }
@NotNull public Language getLanguage() { return PropertiesLanguage.INSTANCE; }
public PropertiesCodeStyleSettings(CodeStyleSettings container) { super(PropertiesLanguage.INSTANCE.getID(), container); }
@Nullable @Override public String getConfigurableDisplayName() { return PropertiesLanguage.INSTANCE.getDisplayName(); }
public PropertiesElementType(@NonNls String debugName) { super(debugName, PropertiesLanguage.INSTANCE); }
private static String guessSeparator(final Project project, final VirtualFile file) { Collection<PropertiesFile> files; if (file instanceof ResourceBundleAsVirtualFile) { files = ((ResourceBundleAsVirtualFile)file).getResourceBundle().getPropertiesFiles(project); } else { PsiManager psiManager = PsiManager.getInstance(project); final FileViewProvider provider = psiManager.findViewProvider(file); files = new SmartList<PropertiesFile>(); if (provider != null) { ContainerUtil.addIfNotNull((PropertiesFile)provider.getPsi(PropertiesLanguage.INSTANCE), files); } } final TIntLongHashMap charCounts = new TIntLongHashMap(); for (PropertiesFile propertiesFile : files) { if (propertiesFile == null) continue; List<IProperty> properties = propertiesFile.getProperties(); for (IProperty property : properties) { String key = property.getUnescapedKey(); if (key == null) continue; for (int i =0; i<key.length(); i++) { char c = key.charAt(i); if (!Character.isLetterOrDigit(c)) { charCounts.put(c, charCounts.get(c) + 1); } } } } final char[] mostProbableChar = new char[]{'.'}; charCounts.forEachKey(new TIntProcedure() { long count = -1; public boolean execute(int ch) { long charCount = charCounts.get(ch); if (charCount > count) { count = charCount; mostProbableChar[0] = (char)ch; } return true; } }); if (mostProbableChar[0] == 0) { mostProbableChar[0] = '.'; } return Character.toString(mostProbableChar[0]); }
public PropertiesFileImpl(FileViewProvider viewProvider) { super(viewProvider, PropertiesLanguage.INSTANCE); }
private PlayJavaConfFileType() { super(PropertiesLanguage.INSTANCE); }