Search in sources :

Example 1 with GenericAttributeValue

use of com.intellij.util.xml.GenericAttributeValue in project intellij-community by JetBrains.

the class BasicDomElementsInspection method checkDomElement.

/**
   * The default implementations checks for resolve problems (if {@link #shouldCheckResolveProblems(com.intellij.util.xml.GenericDomValue)}
   * returns true), then runs annotators (see {@link com.intellij.util.xml.DomFileDescription#createAnnotator()}),
   * checks for {@link com.intellij.util.xml.Required} and {@link com.intellij.util.xml.ExtendClass} annotation
   * problems, checks for name identity (see {@link com.intellij.util.xml.NameValue} annotation) and custom annotation
   * checkers (see {@link com.intellij.util.xml.highlighting.DomCustomAnnotationChecker}).
   *
   * @param element element to check
   * @param holder  a place to add problems to
   * @param helper  helper object
   */
@Override
protected void checkDomElement(DomElement element, DomElementAnnotationHolder holder, DomHighlightingHelper helper) {
    final int oldSize = holder.getSize();
    if (element instanceof GenericDomValue) {
        final GenericDomValue genericDomValue = (GenericDomValue) element;
        if (shouldCheckResolveProblems(genericDomValue)) {
            helper.checkResolveProblems(genericDomValue, holder);
        }
    }
    for (final Class<? extends T> aClass : getDomClasses()) {
        helper.runAnnotators(element, holder, aClass);
    }
    if (oldSize != holder.getSize())
        return;
    if (!helper.checkRequired(element, holder).isEmpty())
        return;
    if (!(element instanceof GenericAttributeValue) && !GenericDomValue.class.equals(ReflectionUtil.getRawType(element.getDomElementType()))) {
        if (!helper.checkNameIdentity(element, holder).isEmpty())
            return;
    }
    helper.checkCustomAnnotations(element, holder);
}
Also used : GenericDomValue(com.intellij.util.xml.GenericDomValue) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue)

Example 2 with GenericAttributeValue

use of com.intellij.util.xml.GenericAttributeValue in project android by JetBrains.

the class AndroidRenameHandler method isPackageAttributeInManifest.

static boolean isPackageAttributeInManifest(@NotNull Project project, @Nullable PsiElement element) {
    if (element == null) {
        return false;
    }
    final PsiFile psiFile = element.getContainingFile();
    if (!(psiFile instanceof XmlFile)) {
        return false;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(psiFile);
    if (facet == null) {
        return false;
    }
    final VirtualFile vFile = psiFile.getVirtualFile();
    if (vFile == null || !vFile.equals(AndroidRootUtil.getPrimaryManifestFile(facet))) {
        return false;
    }
    if (!(element instanceof XmlAttributeValue)) {
        return false;
    }
    final PsiElement parent = element.getParent();
    if (!(parent instanceof XmlAttribute)) {
        return false;
    }
    final GenericAttributeValue attrValue = DomManager.getDomManager(project).getDomElement((XmlAttribute) parent);
    if (attrValue == null) {
        return false;
    }
    final DomElement parentDomElement = attrValue.getParent();
    return parentDomElement instanceof Manifest && attrValue.equals(((Manifest) parentDomElement).getPackage());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DomElement(com.intellij.util.xml.DomElement) PsiFile(com.intellij.psi.PsiFile) Manifest(org.jetbrains.android.dom.manifest.Manifest) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) PsiElement(com.intellij.psi.PsiElement) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue)

Example 3 with GenericAttributeValue

use of com.intellij.util.xml.GenericAttributeValue in project android by JetBrains.

the class AndroidCreateOnClickHandlerAction method invoke.

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final AndroidFacet facet = AndroidFacet.getInstance(file);
    assert facet != null;
    final XmlAttributeValue attrValue = getXmlAttributeValue(file, editor);
    assert attrValue != null;
    final String methodName = attrValue.getValue();
    assert methodName != null;
    final GenericAttributeValue domValue = DomManager.getDomManager(project).getDomElement((XmlAttribute) attrValue.getParent());
    assert domValue != null;
    final OnClickConverter converter = (OnClickConverter) domValue.getConverter();
    final PsiClass activityBaseClass = JavaPsiFacade.getInstance(project).findClass(AndroidUtils.ACTIVITY_BASE_CLASS_NAME, facet.getModule().getModuleWithDependenciesAndLibrariesScope(false));
    if (activityBaseClass == null) {
        return;
    }
    final GlobalSearchScope scope = facet.getModule().getModuleScope(false);
    final PsiClass selectedClass;
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        final Ref<PsiClass> selClassRef = Ref.create();
        ClassInheritorsSearch.search(activityBaseClass, scope, true, true, false).forEach(new Processor<PsiClass>() {

            @Override
            public boolean process(PsiClass psiClass) {
                if (!psiClass.isInterface() && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
                    selClassRef.set(psiClass);
                    return false;
                }
                return true;
            }
        });
        selectedClass = selClassRef.get();
    } else {
        final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser("Choose Activity to Create the Method", scope, activityBaseClass, null, new ClassFilter() {

            @Override
            public boolean isAccepted(PsiClass aClass) {
                return !converter.findHandlerMethod(aClass, methodName);
            }
        });
        chooser.showDialog();
        selectedClass = chooser.getSelected();
    }
    if (selectedClass != null) {
        addHandlerMethodAndNavigate(project, selectedClass, methodName, converter.getDefaultMethodParameterType(selectedClass));
    }
}
Also used : OnClickConverter(org.jetbrains.android.dom.converters.OnClickConverter) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ClassFilter(com.intellij.ide.util.ClassFilter) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue)

Example 4 with GenericAttributeValue

use of com.intellij.util.xml.GenericAttributeValue in project android by JetBrains.

the class AndroidCreateOnClickHandlerAction method isAvailable.

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    if (editor == null || !(file instanceof XmlFile)) {
        return false;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(file);
    if (facet == null) {
        return false;
    }
    final XmlAttributeValue attrValue = getXmlAttributeValue(file, editor);
    if (attrValue == null) {
        return false;
    }
    final PsiElement parent = attrValue.getParent();
    if (!(parent instanceof XmlAttribute)) {
        return false;
    }
    final GenericAttributeValue domValue = DomManager.getDomManager(project).getDomElement((XmlAttribute) parent);
    if (domValue == null || !(domValue.getConverter() instanceof OnClickConverter)) {
        return false;
    }
    final String methodName = attrValue.getValue();
    return methodName != null && StringUtil.isJavaIdentifier(methodName);
}
Also used : OnClickConverter(org.jetbrains.android.dom.converters.OnClickConverter) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue)

Example 5 with GenericAttributeValue

use of com.intellij.util.xml.GenericAttributeValue in project android by JetBrains.

the class AndroidApplicationPackageRenameProcessor method processAllClassAttrValues.

private static void processAllClassAttrValues(@NotNull XmlFile file, @NotNull final Processor<Pair<GenericAttributeValue, PsiClass>> processor) {
    final DomManager domManager = DomManager.getDomManager(file.getProject());
    file.accept(new XmlRecursiveElementVisitor() {

        @Override
        public void visitXmlAttribute(XmlAttribute attribute) {
            final GenericAttributeValue domAttrValue = domManager.getDomElement(attribute);
            if (domAttrValue != null) {
                final Object value = domAttrValue.getValue();
                if (value instanceof PsiClass) {
                    processor.process(Pair.create(domAttrValue, (PsiClass) value));
                }
            }
        }
    });
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) DomManager(com.intellij.util.xml.DomManager) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue)

Aggregations

GenericAttributeValue (com.intellij.util.xml.GenericAttributeValue)8 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)4 XmlAttribute (com.intellij.psi.xml.XmlAttribute)3 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)3 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 XmlFile (com.intellij.psi.xml.XmlFile)2 OnClickConverter (org.jetbrains.android.dom.converters.OnClickConverter)2 Manifest (org.jetbrains.android.dom.manifest.Manifest)2 ClassFilter (com.intellij.ide.util.ClassFilter)1 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)1 BaseImpl (com.intellij.jam.model.common.BaseImpl)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 Ref (com.intellij.openapi.util.Ref)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 CachedValue (com.intellij.psi.util.CachedValue)1 CachedValueProvider (com.intellij.psi.util.CachedValueProvider)1