use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class InconsistentPropertiesEndsInspectionProvider method check.
@Override
public void check(BidirectionalMap<PropertiesFile, PropertiesFile> parents, List<PropertiesFile> files, Map<PropertiesFile, Set<String>> keysUpToParent, Map<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps, InspectionManager manager, RefManager refManager, ProblemDescriptionsProcessor processor) {
for (PropertiesFile file : files) {
final Set<String> filePropertyKeys = new THashSet<>(propertiesFilesNamesMaps.get(file).keySet());
PropertiesFile parent = parents.get(file);
while (parent != null) {
final Collection<String> commonKeys = ContainerUtil.intersection(propertiesFilesNamesMaps.get(parent).keySet(), filePropertyKeys);
for (final String commonKey : commonKeys) {
final IProperty property = file.findPropertyByKey(commonKey);
assert property != null;
final String propertyValue = property.getValue();
if (StringUtil.isEmptyOrSpaces(propertyValue)) {
continue;
}
final char lastChar = propertyValue.charAt(propertyValue.length() - 1);
if (!PROPERTY_VALUE_END_CHECK_SYMBOLS.contains(lastChar)) {
continue;
}
final String parentPropertyValue = propertiesFilesNamesMaps.get(parent).get(commonKey);
if (parentPropertyValue == null) {
continue;
}
final char parentLastChar = parentPropertyValue.charAt(parentPropertyValue.length() - 1);
if (lastChar != parentLastChar) {
final String message;
if (PROPERTY_VALUE_END_CHECK_SYMBOLS.contains(parentLastChar)) {
message = InspectionsBundle.message("inconsistent.bundle.property.inconsistent.end.parent.end.from.check.symbols", lastChar, parentLastChar, parent.getName());
} else {
message = InspectionsBundle.message("inconsistent.bundle.property.inconsistent.end", lastChar);
}
final PsiElement propertyPsiElement = property.getPsiElement();
processor.addProblemElement(refManager.getReference(file.getContainingFile()), manager.createProblemDescriptor(propertyPsiElement, message, true, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
filePropertyKeys.removeAll(commonKeys);
parent = parents.get(parent);
}
}
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class MavenFilteredPropertyPsiReference method doResolve.
@Override
protected PsiElement doResolve() {
PsiElement result = super.doResolve();
if (result != null)
return result;
for (String each : myMavenProject.getFilterPropertiesFiles()) {
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(each);
if (file == null)
continue;
IProperty property = MavenDomUtil.findProperty(myProject, file, myText);
if (property != null)
return property.getPsiElement();
}
return null;
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class MavenPropertyPsiReference method doResolve.
// See org.apache.maven.project.interpolation.AbstractStringBasedModelInterpolator.createValueSources()
@Nullable
protected PsiElement doResolve() {
boolean hasPrefix = false;
String unprefixed = myText;
if (myText.startsWith("pom.")) {
unprefixed = myText.substring("pom.".length());
hasPrefix = true;
} else if (myText.startsWith("project.")) {
unprefixed = myText.substring("project.".length());
hasPrefix = true;
}
MavenProject mavenProject = myMavenProject;
while (unprefixed.startsWith("parent.")) {
if (unprefixed.equals("parent.groupId") || unprefixed.equals("parent.artifactId") || unprefixed.equals("parent.version") || unprefixed.equals("parent.relativePath")) {
break;
}
MavenId parentId = mavenProject.getParentId();
if (parentId == null)
return null;
mavenProject = myProjectsManager.findProject(parentId);
if (mavenProject == null)
return null;
unprefixed = unprefixed.substring("parent.".length());
}
if (unprefixed.equals("basedir") || (hasPrefix && mavenProject == myMavenProject && unprefixed.equals("baseUri"))) {
return getBaseDir(mavenProject);
}
if (myText.equals(TIMESTAMP_PROP)) {
return myElement;
}
if (hasPrefix) {
MavenDomProjectModel domProjectModel = MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile());
if (domProjectModel != null) {
PsiElement res = resolveModelProperty(domProjectModel, unprefixed, new HashSet<>());
if (res != null) {
return res;
}
}
}
// todo resolve properties from config.
MavenRunnerSettings runnerSettings = MavenRunner.getInstance(myProject).getSettings();
if (runnerSettings.getMavenProperties().containsKey(myText) || runnerSettings.getVmOptions().contains("-D" + myText + '=')) {
return myElement;
}
if (MavenUtil.getPropertiesFromMavenOpts().containsKey(myText)) {
return myElement;
}
MavenDomProfile profile = DomUtil.findDomElement(myElement, MavenDomProfile.class);
if (profile != null) {
PsiElement result = MavenDomProjectProcessorUtils.findProperty(profile.getProperties(), myText);
if (result != null)
return result;
}
MavenDomConfiguration pluginCfg = DomUtil.findDomElement(myElement, MavenDomConfiguration.class);
if (pluginCfg != null) {
boolean notFound = MavenPluginDescriptor.processDescriptors(descriptor -> {
if (descriptor.properties != null) {
for (MavenPluginDescriptor.ModelProperty property : descriptor.properties) {
if (property.insideConfigurationOnly && property.name.equals(myText)) {
return false;
}
}
}
return true;
}, pluginCfg);
if (!notFound) {
return myElement;
}
}
if (myProjectDom != null) {
PsiElement result = MavenDomProjectProcessorUtils.searchProperty(myText, myProjectDom, myProject);
if (result != null)
return result;
}
if ("java.home".equals(myText)) {
PsiElement element = resolveToCustomSystemProperty("java.home", MavenUtil.getModuleJreHome(myProjectsManager, mavenProject));
if (element != null) {
return element;
}
}
if ("java.version".equals(myText)) {
PsiElement element = resolveToCustomSystemProperty("java.version", MavenUtil.getModuleJavaVersion(myProjectsManager, mavenProject));
if (element != null) {
return element;
}
}
MavenPropertiesVirtualFileSystem mavenPropertiesVirtualFileSystem = MavenPropertiesVirtualFileSystem.getInstance();
IProperty property = mavenPropertiesVirtualFileSystem.findSystemProperty(myProject, myText);
if (property != null)
return property.getPsiElement();
if (myText.startsWith("env.")) {
property = mavenPropertiesVirtualFileSystem.findEnvProperty(myProject, myText.substring("env.".length()));
if (property != null)
return property.getPsiElement();
}
String textWithEnv = "env." + myText;
property = mavenPropertiesVirtualFileSystem.findSystemProperty(myProject, textWithEnv);
if (property != null)
return property.getPsiElement();
property = mavenPropertiesVirtualFileSystem.findEnvProperty(myProject, textWithEnv);
if (property != null)
return property.getPsiElement();
if (!hasPrefix) {
MavenDomProjectModel domProjectModel = MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile());
if (domProjectModel != null) {
PsiElement res = resolveModelProperty(domProjectModel, unprefixed, new HashSet<>());
if (res != null) {
return res;
}
}
}
if (mavenProject.getProperties().containsKey(myText)) {
return myElement;
}
if (myText.startsWith("settings.")) {
return resolveSettingsModelProperty();
}
return null;
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class GotoPropertyDeclarationsProvider method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) {
final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
if (!(editor instanceof ResourceBundleEditor)) {
return Collections.emptyList();
}
final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor) editor;
final Collection<ResourceBundleEditorViewElement> elements = resourceBundleEditor.getSelectedElements();
if (elements.size() != 1) {
return Collections.emptyList();
}
final IProperty[] properties = ContainerUtil.getFirstItem(elements).getProperties();
if (properties == null || properties.length != 1 || !(properties[0] instanceof Property)) {
return Collections.emptyList();
}
final IProperty property = properties[0];
final String propertyKey = property.getKey();
final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(property.getPsiElement().getContainingFile());
assert file != null;
final ResourceBundle resourceBundle = file.getResourceBundle();
return ContainerUtil.mapNotNull(resourceBundle.getPropertiesFiles(), (NullableFunction<PropertiesFile, GotoRelatedItem>) f -> {
final IProperty foundProperty = f.findPropertyByKey(propertyKey);
return foundProperty == null ? null : new GotoRelatedItem(foundProperty.getPsiElement(), "Property Declarations");
});
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class PropertiesPsiCompletionUtil method getPropertiesKeys.
static Set<Object> getPropertiesKeys(final PropertyReferenceBase propertyReference) {
final Set<Object> variants = new THashSet<>(new TObjectHashingStrategy<Object>() {
public int computeHashCode(final Object object) {
if (object instanceof IProperty) {
final String key = ((IProperty) object).getKey();
return key == null ? 0 : key.hashCode();
} else {
return 0;
}
}
public boolean equals(final Object o1, final Object o2) {
return o1 instanceof IProperty && o2 instanceof IProperty && Comparing.equal(((IProperty) o1).getKey(), ((IProperty) o2).getKey(), true);
}
});
List<PropertiesFile> propertiesFileList = propertyReference.getPropertiesFiles();
if (propertiesFileList == null) {
PropertiesReferenceManager.getInstance(propertyReference.getElement().getProject()).processAllPropertiesFiles(new PropertiesFileProcessor() {
@Override
public boolean process(String baseName, PropertiesFile propertiesFile) {
addVariantsFromFile(propertyReference, propertiesFile, variants);
return true;
}
});
} else {
for (PropertiesFile propFile : propertiesFileList) {
addVariantsFromFile(propertyReference, propFile, variants);
}
}
return variants;
}
Aggregations