Search in sources :

Example 21 with Property

use of com.intellij.lang.properties.psi.Property in project intellij-community by JetBrains.

the class PropertiesFileStructureViewElement method getChildrenBase.

@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    List<? extends IProperty> properties = getElement().getProperties();
    Collection<StructureViewTreeElement> elements = new ArrayList<>(properties.size());
    for (IProperty property : properties) {
        elements.add(new PropertiesStructureViewElement((Property) property));
    }
    return elements;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) ArrayList(java.util.ArrayList) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with Property

use of com.intellij.lang.properties.psi.Property in project intellij-community by JetBrains.

the class DuplicatePropertyInspection method prepareDuplicateValuesByFile.

private static void prepareDuplicateValuesByFile(final Map<String, Set<PsiFile>> valueToFiles, final InspectionManager manager, final List<ProblemDescriptor> problemDescriptors, final PsiFile psiFile, final ProgressIndicator progress) {
    for (final String value : valueToFiles.keySet()) {
        if (progress != null) {
            progress.setText2(InspectionsBundle.message("duplicate.property.value.progress.indicator.text", value));
            progress.checkCanceled();
        }
        if (value.length() == 0)
            continue;
        StringSearcher searcher = new StringSearcher(value, true, true);
        final StringBuffer message = new StringBuffer();
        final int[] duplicatesCount = { 0 };
        Set<PsiFile> psiFilesWithDuplicates = valueToFiles.get(value);
        for (final PsiFile file : psiFilesWithDuplicates) {
            CharSequence text = file.getViewProvider().getContents();
            LowLevelSearchUtil.processTextOccurrences(text, 0, text.length(), searcher, progress, offset -> {
                PsiElement element = file.findElementAt(offset);
                if (element != null && element.getParent() instanceof Property) {
                    final Property property = (Property) element.getParent();
                    if (Comparing.equal(property.getValue(), value) && element.getStartOffsetInParent() != 0) {
                        if (duplicatesCount[0] == 0) {
                            message.append(InspectionsBundle.message("duplicate.property.value.problem.descriptor", property.getValue()));
                        }
                        surroundWithHref(message, element, true);
                        duplicatesCount[0]++;
                    }
                }
                return true;
            });
        }
        if (duplicatesCount[0] > 1) {
            problemDescriptors.add(manager.createProblemDescriptor(psiFile, message.toString(), false, null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
        }
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) PsiElement(com.intellij.psi.PsiElement) StringSearcher(com.intellij.util.text.StringSearcher)

Example 23 with Property

use of com.intellij.lang.properties.psi.Property in project intellij-community by JetBrains.

the class FormReferencesSearcher method execute.

@Override
public boolean execute(@NotNull final ReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
    SearchScope userScope = p.getScopeDeterminedByUser();
    if (!scopeCanContainForms(userScope))
        return true;
    final PsiElement refElement = p.getElementToSearch();
    final PsiFile psiFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {

        @Override
        public PsiFile compute() {
            if (!refElement.isValid())
                return null;
            return refElement.getContainingFile();
        }
    });
    if (psiFile == null)
        return true;
    final VirtualFile virtualFile = psiFile.getVirtualFile();
    if (virtualFile == null)
        return true;
    final GlobalSearchScope[] scope = new GlobalSearchScope[1];
    Project project = ApplicationManager.getApplication().runReadAction(new Computable<Project>() {

        @Override
        public Project compute() {
            Project project = psiFile.getProject();
            Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(virtualFile);
            if (module != null) {
                scope[0] = GlobalSearchScope.moduleWithDependenciesScope(module);
            }
            return project;
        }
    });
    if (scope[0] == null) {
        return true;
    }
    final LocalSearchScope filterScope = userScope instanceof LocalSearchScope ? (LocalSearchScope) userScope : null;
    PsiManager psiManager = PsiManager.getInstance(project);
    if (refElement instanceof PsiPackage) {
    //no need to do anything
    //if (!UIFormUtil.processReferencesInUIForms(consumer, (PsiPackage)refElement, scope)) return false;
    } else if (refElement instanceof PsiClass) {
        if (!processReferencesInUIForms(consumer, psiManager, (PsiClass) refElement, scope[0], filterScope))
            return false;
    } else if (refElement instanceof PsiEnumConstant) {
        if (!processEnumReferencesInUIForms(consumer, psiManager, (PsiEnumConstant) refElement, scope[0], filterScope))
            return false;
    } else if (refElement instanceof PsiField) {
        if (!processReferencesInUIForms(consumer, psiManager, (PsiField) refElement, scope[0], filterScope))
            return false;
    } else if (refElement instanceof IProperty) {
        if (!processReferencesInUIForms(consumer, psiManager, (Property) refElement, scope[0], filterScope))
            return false;
    } else if (refElement instanceof PropertiesFile) {
        if (!processReferencesInUIForms(consumer, psiManager, (PropertiesFile) refElement, scope[0], filterScope))
            return false;
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Module(com.intellij.openapi.module.Module) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty)

Aggregations

Property (com.intellij.lang.properties.psi.Property)23 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)16 IProperty (com.intellij.lang.properties.IProperty)12 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)5 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiElement (com.intellij.psi.PsiElement)4 PsiFile (com.intellij.psi.PsiFile)4 ASTNode (com.intellij.lang.ASTNode)3 Logger (com.intellij.openapi.diagnostic.Logger)3 ProgressManager (com.intellij.openapi.progress.ProgressManager)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 com.intellij.codeInspection (com.intellij.codeInspection)2 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)2 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Project (com.intellij.openapi.project.Project)2 PsiSearchHelper (com.intellij.psi.search.PsiSearchHelper)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2