use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class ParentStyleConverter method createReferences.
@NotNull
@Override
public PsiReference[] createReferences(GenericDomValue<ResourceValue> value, PsiElement element, ConvertContext context) {
if (element instanceof XmlAttributeValue) {
// parent="" is allowed; it's used to deliberately allow style A.B.C to not be a child of A.B
XmlAttributeValue attributeValue = (XmlAttributeValue) element;
if (attributeValue.isValid() && attributeValue.getValue().isEmpty()) {
return PsiReference.EMPTY_ARRAY;
}
}
final PsiReference[] refsFromSuper = super.createReferences(value, element, context);
final ResourceValue resValue = value.getValue();
if (resValue == null || resValue.getNamespace() != null) {
return refsFromSuper;
}
final AndroidFacet facet = AndroidFacet.getInstance(context);
if (facet != null) {
final PsiReference[] refs = getReferencesInStyleName(value, facet);
if (refs.length > 0) {
return ArrayUtil.mergeArrays(refsFromSuper, refs);
}
}
return refsFromSuper;
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidResourceReferenceBase method isReferenceTo.
@Override
public boolean isReferenceTo(PsiElement element) {
if (element instanceof LazyValueResourceElementWrapper) {
element = ((LazyValueResourceElementWrapper) element).computeElement();
if (element == null) {
return false;
}
}
final ResolveResult[] results = multiResolve(false);
final PsiFile psiFile = element.getContainingFile();
final VirtualFile vFile = psiFile != null ? psiFile.getVirtualFile() : null;
for (ResolveResult result : results) {
final PsiElement target = result.getElement();
if (element.getManager().areElementsEquivalent(target, element)) {
return true;
}
if (target instanceof LazyValueResourceElementWrapper && vFile != null) {
final ValueResourceInfo info = ((LazyValueResourceElementWrapper) target).getResourceInfo();
if (info.getContainingFile().equals(vFile)) {
final XmlAttributeValue realTarget = info.computeXmlElement();
if (element.getManager().areElementsEquivalent(realTarget, element)) {
return true;
}
}
}
}
return false;
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidLayoutUtil method getAlias.
@Nullable
public static /*invalid type*/
String getAlias(Import anImport) {
String aliasValue = null;
String typeValue = null;
GenericAttributeValue<String> alias = anImport.getAlias();
if (alias != null && alias.getXmlAttributeValue() != null) {
aliasValue = alias.getXmlAttributeValue().getValue();
}
GenericAttributeValue<PsiClass> type = anImport.getType();
if (type != null) {
XmlAttributeValue value = type.getXmlAttributeValue();
if (value != null) {
typeValue = value.getValue();
}
}
return getAlias(typeValue, aliasValue);
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class ActionScriptAnnotatingVisitor method visitJSReferenceExpression.
@Override
public void visitJSReferenceExpression(JSReferenceExpression node) {
super.visitJSReferenceExpression(node);
final PsiElement parent = node.getParent();
if (node.getQualifier() == null) {
String nodeText = node.getText();
if (!(parent instanceof JSCallExpression) && JSResolveUtil.isExprInStrictTypeContext(node) && JSCommonTypeNames.VECTOR_CLASS_NAME.equals(nodeText)) {
myHolder.createWarningAnnotation(node, JSBundle.message("javascript.validation.message.vector.without.parameters"));
} else if (parent instanceof JSNewExpression && JSCommonTypeNames.VECTOR_CLASS_NAME.equals(nodeText)) {
myHolder.createWarningAnnotation(node, JSBundle.message("javascript.validation.message.vector.without.parameters2"));
}
}
if (parent instanceof JSNamedElement) {
JSNamedElement namedElement = (JSNamedElement) parent;
final ASTNode nameIdentifier = namedElement.findNameIdentifier();
if (nameIdentifier != null && nameIdentifier.getPsi() == node) {
if (parent instanceof JSPackageStatement) {
checkPackageStatement((JSPackageStatement) parent);
} else if (!(parent instanceof JSImportStatement) && parent.getParent() instanceof JSPackageStatement) {
checkNamedObjectIsInCorrespondingFile(namedElement);
} else if (parent instanceof JSVariable) {
if (parent.getParent().getParent() instanceof JSPackageStatement) {
checkNamedObjectIsInCorrespondingFile((JSVariable) parent);
}
} else if (parent instanceof JSNamespaceDeclaration) {
DuplicatesCheckUtil.checkDuplicates((JSNamespaceDeclaration) parent, myProblemReporter);
}
if (parent instanceof JSClass) {
final JSClass jsClass = (JSClass) parent;
final JSFunction constructor = jsClass.getConstructor();
if (constructor == null)
createConstructorChecker().checkMissedConstructor(jsClass);
PsiElement clazzParent = jsClass.getParent();
final PsiElement context = clazzParent.getContext();
boolean clazzParentIsInjectedJsFile = clazzParent instanceof JSFile && (context instanceof XmlAttributeValue || context instanceof XmlText) && !XmlBackedJSClassImpl.isImplementsAttribute((JSFile) clazzParent);
if (PsiTreeUtil.getParentOfType(jsClass, JSFunction.class, JSClass.class) != null || clazzParentIsInjectedJsFile) {
myHolder.createErrorAnnotation(node, JSBundle.message("javascript.validation.message.nested.classes.are.not.allowed"));
}
checkClass(jsClass);
}
}
}
JSFunction fun;
if (JSSymbolUtil.isAccurateReferenceExpressionName(node, JSFunction.ARGUMENTS_VAR_NAME) && (fun = PsiTreeUtil.getParentOfType(node, JSFunction.class)) != null && node.resolve() instanceof ImplicitJSVariableImpl) {
JSParameterList parameterList = fun.getParameterList();
if (parameterList != null) {
for (JSParameter p : parameterList.getParameterVariables()) {
if (p.isRest()) {
myHolder.createErrorAnnotation(node, JSBundle.message("javascript.validation.message.arguments.with.rest.parameter"));
}
}
}
}
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class DataBindingCompletionUtil method fillAliases.
/**
* Add completion suggestions for classes included via {@code <import>}s.
* @param resultSet the set to add the suggestions to.
*/
private static void fillAliases(@NotNull CompletionResultSet resultSet, @NotNull String packagePrefix, @NotNull PsiElement originalPosition, @NotNull Module module, @NotNull PsiElement originalParent) {
PsiFile containingFile = getRealContainingFile(originalParent.getContainingFile());
if (containingFile instanceof XmlFile) {
final Project project = module.getProject();
DomManager domManager = DomManager.getDomManager(project);
XmlTag tag = PsiTreeUtil.getParentOfType(originalPosition, XmlTag.class, false, PsiFile.class);
if (domManager.getDomElement(tag) instanceof Import) {
// No referencing aliases in import tags.
return;
}
DomFileElement<Layout> file = domManager.getFileElement((XmlFile) containingFile, Layout.class);
if (file != null) {
JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
for (Data data : file.getRootElement().getDatas()) {
for (Import anImport : data.getImports()) {
String alias = AndroidLayoutUtil.getAlias(anImport);
if (packagePrefix.isEmpty()) {
XmlAttributeValue type = anImport.getType().getXmlAttributeValue();
if (type != null && alias != null) {
String typeValue = type.getValue().replace('$', '.');
PsiClass aClass = facade.findClass(typeValue, module.getModuleWithDependenciesAndLibrariesScope(false));
if (aClass != null) {
resultSet.addElement(getClassReferenceElement(alias, aClass));
}
}
} else {
int i = packagePrefix.indexOf('.');
String possibleAlias = i < 0 ? packagePrefix : packagePrefix.substring(0, i);
if (possibleAlias.equals(alias)) {
String type = anImport.getType().getStringValue();
if (type != null) {
String fqcn = packagePrefix.equals(alias) ? type : type + packagePrefix.substring(alias.length());
PsiClass aClass = facade.findClass(fqcn, module.getModuleWithDependenciesAndLibrariesScope(false));
if (aClass != null) {
for (PsiClass innerClass : aClass.getInnerClasses()) {
String name = innerClass.getQualifiedName();
if (name != null) {
resultSet.addElement(getClassReferenceElement(name.substring(type.length() + 1), innerClass));
}
}
break;
}
}
}
}
}
}
}
}
}
Aggregations