Search in sources :

Example 56 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 57 with PsiField

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

the class RemoveMiddlemanHandler method invoke.

public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
    if (elements.length != 1) {
        return;
    }
    if (elements[0] instanceof PsiField) {
        Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
        invoke((PsiField) elements[0], editor);
    }
}
Also used : PsiField(com.intellij.psi.PsiField) Editor(com.intellij.openapi.editor.Editor)

Example 58 with PsiField

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

the class MakeClassStaticRefactoringImpl method getFields.

public List<PsiField> getFields() {
    final Settings settings = myProcessor.getSettings();
    List<PsiField> result = new ArrayList<>();
    final List<Settings.FieldParameter> parameterOrderList = settings.getParameterOrderList();
    for (final Settings.FieldParameter fieldParameter : parameterOrderList) {
        result.add(fieldParameter.field);
    }
    return result;
}
Also used : PsiField(com.intellij.psi.PsiField) ArrayList(java.util.ArrayList) Settings(com.intellij.refactoring.makeStatic.Settings)

Example 59 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 60 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)

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