Search in sources :

Example 61 with PsiField

use of com.intellij.psi.PsiField in project intellij-community by JetBrains.

the class PsiFieldFavoriteNodeProvider method createPathFromUrl.

@Override
public Object[] createPathFromUrl(final Project project, final String url, final String moduleName) {
    if (DumbService.isDumb(project))
        return null;
    final Module module = moduleName != null ? ModuleManager.getInstance(project).findModuleByName(moduleName) : null;
    final GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.allScope(project);
    final String[] paths = url.split(";");
    if (paths == null || paths.length != 2)
        return null;
    final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(paths[0], scope);
    if (aClass == null)
        return null;
    final PsiField aField = aClass.findFieldByName(paths[1], false);
    return new Object[] { aField };
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module)

Example 62 with PsiField

use of com.intellij.psi.PsiField in project intellij-community by JetBrains.

the class CompositeShortNamesCache method getFieldsByNameIfNotMoreThan.

@NotNull
@Override
public PsiField[] getFieldsByNameIfNotMoreThan(@NonNls @NotNull String name, @NotNull GlobalSearchScope scope, int maxCount) {
    Merger<PsiField> merger = null;
    for (PsiShortNamesCache cache : myCaches) {
        PsiField[] fields = cache.getFieldsByNameIfNotMoreThan(name, scope, maxCount);
        if (fields.length == maxCount)
            return fields;
        if (fields.length != 0) {
            if (merger == null)
                merger = new Merger<>();
            merger.add(fields);
        }
    }
    PsiField[] result = merger == null ? null : merger.getResult();
    return result == null ? PsiField.EMPTY_ARRAY : result;
}
Also used : PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) PsiField(com.intellij.psi.PsiField) NotNull(org.jetbrains.annotations.NotNull)

Example 63 with PsiField

use of com.intellij.psi.PsiField in project intellij-community by JetBrains.

the class ExtensionPointImpl method collectMissingWithTags.

@Override
public List<PsiField> collectMissingWithTags() {
    PsiClass beanClass = getBeanClass().getValue();
    if (beanClass == null) {
        return Collections.emptyList();
    }
    final List<PsiField> result = new SmartList<>();
    for (PsiField field : beanClass.getAllFields()) {
        if (ExtensionDomExtender.isClassField(field.getName()) && ExtensionDomExtender.findWithElement(getWithElements(), field) == null) {
            result.add(field);
        }
    }
    return result;
}
Also used : PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) SmartList(com.intellij.util.SmartList)

Example 64 with PsiField

use of com.intellij.psi.PsiField in project intellij-community by JetBrains.

the class AddWithTagFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    DomElement element = DomUtil.getDomElement(descriptor.getPsiElement());
    if (!(element instanceof ExtensionPoint)) {
        return;
    }
    ExtensionPoint extensionPoint = (ExtensionPoint) element;
    List<PsiField> fields = extensionPoint.collectMissingWithTags();
    PsiElement navTarget = null;
    for (PsiField field : fields) {
        With with = extensionPoint.addWith();
        String tagName = PluginFieldNameConverter.getAnnotationValue(field, Tag.class);
        if (tagName != null) {
            with.getTag().setStringValue(tagName);
        } else {
            String attributeName = PluginFieldNameConverter.getAttributeAnnotationValue(field);
            if (attributeName == null) {
                attributeName = field.getName();
            }
            if (attributeName.equals("forClass")) {
                continue;
            }
            with.getAttribute().setStringValue(attributeName);
        }
        String epName = extensionPoint.getName().getStringValue();
        String className = "";
        if (epName != null) {
            int pos = epName.lastIndexOf('.');
            epName = StringUtil.capitalize(pos >= 0 ? epName.substring(pos + 1) : epName);
            PsiClass[] classesByName = PsiShortNamesCache.getInstance(project).getClassesByName(epName, ProjectScope.getAllScope(project));
            if (classesByName.length == 1) {
                className = classesByName[0].getQualifiedName();
            }
        }
        with.getImplements().setStringValue(className);
        if (navTarget == null) {
            navTarget = with.getImplements().getXmlAttributeValue();
        }
    }
    if (navTarget != null) {
        PsiNavigateUtil.navigate(navTarget);
    }
}
Also used : DomElement(com.intellij.util.xml.DomElement) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) With(org.jetbrains.idea.devkit.dom.With)

Example 65 with PsiField

use of com.intellij.psi.PsiField in project intellij-community by JetBrains.

the class PublicFieldInspection method buildFixes.

@NotNull
@Override
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
    final List<InspectionGadgetsFix> fixes = new ArrayList<>();
    final PsiField field = (PsiField) infos[0];
    fixes.add(new EncapsulateVariableFix(field.getName()));
    AddToIgnoreIfAnnotatedByListQuickFix.build(field, ignorableAnnotations, fixes);
    return fixes.toArray(new InspectionGadgetsFix[fixes.size()]);
}
Also used : EncapsulateVariableFix(com.siyeh.ig.fixes.EncapsulateVariableFix) PsiField(com.intellij.psi.PsiField) ArrayList(java.util.ArrayList) InspectionGadgetsFix(com.siyeh.ig.InspectionGadgetsFix) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiField (com.intellij.psi.PsiField)86 PsiClass (com.intellij.psi.PsiClass)34 PsiElement (com.intellij.psi.PsiElement)27 ArrayList (java.util.ArrayList)13 PsiMethod (com.intellij.psi.PsiMethod)11 NotNull (org.jetbrains.annotations.NotNull)11 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)8 PsiReference (com.intellij.psi.PsiReference)7 PsiType (com.intellij.psi.PsiType)7 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 Nullable (org.jetbrains.annotations.Nullable)6 Nullable (com.android.annotations.Nullable)5 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiExpression (com.intellij.psi.PsiExpression)5 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)5 ResourceType (com.android.resources.ResourceType)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)4 PsiFile (com.intellij.psi.PsiFile)4