/* * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.intellij.psi.impl.source.resolve.reference.impl.providers; import com.intellij.lang.injection.MultiHostInjector; import com.intellij.lang.injection.MultiHostRegistrar; import com.intellij.patterns.XmlAttributeValuePattern; import com.intellij.patterns.XmlPatterns; import com.intellij.psi.ElementManipulators; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.xml.XmlAttributeValue; import com.intellij.xml.util.XmlUtil; import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; public class XsdRegExpInjector implements MultiHostInjector { private static final XmlAttributeValuePattern PATTERN = XmlPatterns.xmlAttributeValue("value").withSuperParent(2, XmlPatterns.xmlTag().withLocalName("pattern").withNamespace( XmlUtil.SCHEMA_URIS)); @Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { if (PATTERN.accepts(context)) { registrar.startInjecting(XsdRegExpParserDefinition.LANGUAGE). addPlace(null, null, (PsiLanguageInjectionHost)context, ElementManipulators.getValueTextRange(context)). doneInjecting(); } } @NotNull @Override public List<? extends Class<? extends PsiElement>> elementsToInjectIn() { return Collections.singletonList(XmlAttributeValue.class); } }