use of com.intellij.psi.filters.ElementFilter in project intellij-community by JetBrains.
the class ApplicationLoader method registerMetaData.
private static void registerMetaData() {
final MetaDataRegistrar registrar = MetaDataRegistrar.getInstance();
registrar.registerMetaData(new AndFilter(new NamespaceFilter(RNG_NAMESPACE), new ClassFilter(XmlDocument.class)), RngNsDescriptor.class);
registrar.registerMetaData(new ClassFilter(RncDocument.class), RngNsDescriptor.class);
registrar.registerMetaData(new ElementFilter() {
@Override
public boolean isAcceptable(Object element, PsiElement context) {
if (element instanceof XmlTag) {
final XmlTag tag = (XmlTag) element;
final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
return domElement instanceof RngDefine;
}
return false;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return XmlTag.class.isAssignableFrom(hintClass);
}
}, RngDefineMetaData.class);
}
use of com.intellij.psi.filters.ElementFilter in project intellij-plugins by JetBrains.
the class AngularJSReferencesContributor method xmlAttributePattern.
private static PsiElementPattern.Capture<XmlAttributeValue> xmlAttributePattern(@NotNull final String attributeName) {
return PlatformPatterns.psiElement(XmlAttributeValue.class).and(new FilterPattern(new ElementFilter() {
@Override
public boolean isAcceptable(Object element, @Nullable PsiElement context) {
final XmlAttributeValue attributeValue = (XmlAttributeValue) element;
final PsiElement parent = attributeValue.getParent();
if (parent instanceof XmlAttribute && attributeName.equals(((XmlAttribute) parent).getName())) {
return AngularIndexUtil.hasAngularJS(attributeValue.getProject());
}
return false;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return true;
}
}));
}
use of com.intellij.psi.filters.ElementFilter in project intellij-plugins by JetBrains.
the class AngularJSReferencesContributor method uiViewPattern.
private static PsiElementPattern.Capture<PsiElement> uiViewPattern() {
return PlatformPatterns.psiElement(PsiElement.class).and(new FilterPattern(new ElementFilter() {
@Override
public boolean isAcceptable(Object element, @Nullable PsiElement context) {
if (!(element instanceof PsiElement))
return false;
if (element instanceof JSLiteralExpression || element instanceof LeafPsiElement && ((LeafPsiElement) element).getNode().getElementType() == JSTokenTypes.STRING_LITERAL) {
if (!(((PsiElement) element).getParent() instanceof JSProperty))
return false;
// started typing property, variant
PsiElement current = moveUpChain((PsiElement) element, JSLiteralExpression.class, JSReferenceExpression.class, JSProperty.class);
if (!(current instanceof JSProperty) || !acceptablePropertyValue((JSProperty) current))
return false;
current = current.getParent();
if (current != null && checkParentViewsObject(current))
return AngularIndexUtil.hasAngularJS(current.getProject());
}
return false;
}
private boolean acceptablePropertyValue(JSProperty element) {
return element.getNameIdentifier() != null && StringUtil.isQuotedString(element.getNameIdentifier().getText()) && (element.getValue() instanceof JSObjectLiteralExpression || element.getValue() instanceof JSReferenceExpression || element.getValue() == null);
}
private PsiElement moveUpChain(@Nullable final PsiElement element, @NotNull final Class<? extends PsiElement>... clazz) {
PsiElement current = element;
for (Class<? extends PsiElement> aClass : clazz) {
current = current != null && aClass.isInstance(current.getParent()) ? current.getParent() : current;
}
return current;
}
private boolean checkParentViewsObject(final PsiElement mustBeObject) {
if (mustBeObject instanceof JSObjectLiteralExpression) {
final PsiElement viewsProperty = mustBeObject.getParent();
if (viewsProperty instanceof JSProperty && "views".equals(((JSProperty) viewsProperty).getName())) {
// by now will not go further todo other cases
return true;
}
}
return false;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return true;
}
}));
}
use of com.intellij.psi.filters.ElementFilter in project intellij-plugins by JetBrains.
the class DartPackagePathReferenceContributor method registerReferenceProviders.
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
DartPackagePathReferenceProvider provider = new DartPackagePathReferenceProvider();
String[] htmlAttrs = new String[] { "href", "src" };
ElementFilter htmlFilter = DartPackagePathReferenceProvider.getFilter();
XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, htmlAttrs, htmlFilter, false, provider, PsiReferenceRegistrar.HIGHER_PRIORITY);
}
use of com.intellij.psi.filters.ElementFilter in project intellij-plugins by JetBrains.
the class ActionScriptReferenceContributor method registerReferenceProviders.
@Override
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
public boolean isAcceptable(Object element, PsiElement context) {
PsiElement parent = ((JSLiteralExpression) element).getParent();
if (parent instanceof JSArgumentList) {
JSExpression[] arguments = ((JSArgumentList) parent).getArguments();
if (arguments.length > 0 && arguments[0] == element) {
parent = parent.getParent();
if (parent instanceof JSCallExpression) {
JSExpression invokedMethod = ((JSCallExpression) parent).getMethodExpression();
if (invokedMethod instanceof JSReferenceExpression) {
String methodName = ((JSReferenceExpression) invokedMethod).getReferencedName();
if (SET_STYLE_METHOD_NAME.equals(methodName)) {
Module module = findModuleForPsiElement(parent);
return module != null && ModuleType.get(module) == FlexModuleType.getInstance();
}
}
}
}
}
return false;
}
public boolean isClassAcceptable(Class hintClass) {
return true;
}
})), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
String value = element.getText();
if (FlexCssUtil.inQuotes(value)) {
return new PsiReference[] { new CssPropertyValueReference(element) };
}
return PsiReference.EMPTY_ARRAY;
}
});
registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
public boolean isAcceptable(Object element, PsiElement context) {
PsiElement parent = ((JSLiteralExpression) element).getParent();
if (parent instanceof JSAssignmentExpression) {
PsiElement assignee = parent.getChildren()[0];
if (assignee instanceof JSDefinitionExpression) {
JSExpression expression = ((JSDefinitionExpression) assignee).getExpression();
if (expression instanceof JSReferenceExpression) {
String refName = ((JSReferenceExpression) expression).getReferencedName();
if (refName != null && FlexCssUtil.isStyleNameProperty(refName)) {
Module module = findModuleForPsiElement(parent);
return module != null && ModuleType.get(module) == FlexModuleType.getInstance();
}
}
}
}
return false;
}
public boolean isClassAcceptable(Class hintClass) {
return true;
}
})), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
String value = element.getText();
if (FlexCssUtil.inQuotes(value)) {
return new PsiReference[] { new CssClassValueReference(element) };
}
return PsiReference.EMPTY_ARRAY;
}
});
registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
public boolean isAcceptable(Object element, PsiElement context) {
PsiElement parent = ((JSLiteralExpression) element).getParent();
if (parent instanceof JSArgumentList) {
final JSExpression[] arguments = ((JSArgumentList) parent).getArguments();
if (arguments.length > 0 && arguments[0] == element) {
parent = parent.getParent();
if (parent instanceof JSCallExpression) {
final JSExpression invokedMethod = ((JSCallExpression) parent).getMethodExpression();
if (invokedMethod instanceof JSReferenceExpression) {
final String methodName = ((JSReferenceExpression) invokedMethod).getReferencedName();
if (methodName != null && FlexCssUtil.isStyleNameMethod(methodName)) {
Module module = findModuleForPsiElement(parent);
return module != null && ModuleType.get(module) == FlexModuleType.getInstance();
}
}
}
}
}
return false;
}
public boolean isClassAcceptable(Class hintClass) {
return true;
}
})), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
String value = element.getText();
if (FlexCssUtil.inQuotes(value)) {
return new PsiReference[] { new CssClassValueReference(element) };
}
return PsiReference.EMPTY_ARRAY;
}
});
registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class), new FlexPropertyReferenceProvider());
registrar.registerReferenceProvider(psiElement(JSAttributeNameValuePair.class), new FlexAttributeReferenceProvider());
}
Aggregations