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);
}
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());
}
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));
}
}
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);
}
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));
}
}
}
});
}
Aggregations