mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
EA-27832 - assert: InjectorUtils.findInjectionSupport
This commit is contained in:
@@ -84,16 +84,11 @@ public class PatternCompilerImpl<T> implements PatternCompiler<T> {
|
||||
public ElementPattern<T> compileElementPattern(final String text) {
|
||||
final Node node = processElementPatternText(text, new Function<Frame, Object>() {
|
||||
public Node fun(final Frame frame) {
|
||||
try {
|
||||
final Object[] args = frame.params.toArray();
|
||||
for (int i = 0, argsLength = args.length; i < argsLength; i++) {
|
||||
args[i] = args[i] instanceof String ? myStringInterner.intern((String)args[i]) : args[i];
|
||||
}
|
||||
return new Node((Node)frame.target, myStringInterner.intern(frame.methodName), args);
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
throw new IllegalArgumentException(text, throwable);
|
||||
final Object[] args = frame.params.toArray();
|
||||
for (int i = 0, argsLength = args.length; i < argsLength; i++) {
|
||||
args[i] = args[i] instanceof String ? myStringInterner.intern((String)args[i]) : args[i];
|
||||
}
|
||||
return new Node((Node)frame.target, myStringInterner.intern(frame.methodName), args);
|
||||
}
|
||||
});
|
||||
return new LazyPresentablePattern(node);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ConcatenationInjector implements ConcatenationAwareInjector {
|
||||
public ConcatenationInjector(Configuration configuration, Project project) {
|
||||
myConfiguration = configuration;
|
||||
myProject = project;
|
||||
mySupport = InjectorUtils.findInjectionSupport(LanguageInjectionSupport.JAVA_SUPPORT_ID);
|
||||
mySupport = InjectorUtils.findNotNullInjectionSupport(LanguageInjectionSupport.JAVA_SUPPORT_ID);
|
||||
myXmlIndex = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Collection<String>>() {
|
||||
public Result<Collection<String>> compute() {
|
||||
final Map<ElementPattern<?>, BaseInjection> map = new THashMap<ElementPattern<?>, BaseInjection>();
|
||||
|
||||
@@ -27,9 +27,11 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiLanguageInjectionHost;
|
||||
import com.intellij.psi.impl.source.tree.injected.MultiHostRegistrarImpl;
|
||||
import com.intellij.psi.impl.source.tree.injected.Place;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
@@ -92,12 +94,24 @@ public class InjectorUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Class[] getPatternClasses(final String supportId) {
|
||||
final LanguageInjectionSupport support = findInjectionSupport(supportId);
|
||||
return support == null ? ArrayUtil.EMPTY_CLASS_ARRAY : support.getPatternClasses();
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static LanguageInjectionSupport findInjectionSupport(final String id) {
|
||||
final LanguageInjectionSupport result = ContainerUtil.find(getActiveInjectionSupports(), new Condition<LanguageInjectionSupport>() {
|
||||
return ContainerUtil.find(getActiveInjectionSupports(), new Condition<LanguageInjectionSupport>() {
|
||||
public boolean value(final LanguageInjectionSupport support) {
|
||||
return support.getId().equals(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LanguageInjectionSupport findNotNullInjectionSupport(final String id) {
|
||||
final LanguageInjectionSupport result = findInjectionSupport(id);
|
||||
assert result != null: id+" injector not found";
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ public class BaseInjection implements Injection, PersistentStateComponent<Elemen
|
||||
|
||||
|
||||
public PatternCompiler<PsiElement> getCompiler() {
|
||||
return PatternCompilerFactory.getFactory().getPatternCompiler(InjectorUtils.findInjectionSupport(getSupportId()).getPatternClasses());
|
||||
return PatternCompilerFactory.getFactory().getPatternCompiler(InjectorUtils.getPatternClasses(getSupportId()));
|
||||
}
|
||||
|
||||
public void generatePlaces() {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class BaseInjectionPanel extends AbstractInjectionPanel<BaseInjection> {
|
||||
public BaseInjectionPanel(BaseInjection injection, Project project) {
|
||||
super(injection, project);
|
||||
$$$setupUI$$$(); // see IDEA-9987
|
||||
myHelper = PatternCompilerFactory.getFactory().getPatternCompiler(InjectorUtils.findInjectionSupport(injection.getSupportId()).getPatternClasses());
|
||||
myHelper = injection.getCompiler();
|
||||
final FileType groovy = FileTypeManager.getInstance().getFileTypeByExtension("groovy");
|
||||
final FileType realFileType = groovy == UnknownFileType.INSTANCE ? FileTypes.PLAIN_TEXT : groovy;
|
||||
final PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText("injection." + realFileType.getDefaultExtension(), realFileType, "", 0, true);
|
||||
|
||||
@@ -61,7 +61,7 @@ public final class XmlLanguageInjector implements MultiHostInjector {
|
||||
|
||||
public XmlLanguageInjector(Configuration configuration) {
|
||||
myConfiguration = configuration;
|
||||
mySupport = InjectorUtils.findInjectionSupport(LanguageInjectionSupport.XML_SUPPORT_ID);
|
||||
mySupport = InjectorUtils.findNotNullInjectionSupport(LanguageInjectionSupport.XML_SUPPORT_ID);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -88,8 +88,7 @@ public class PatternEditorContextMembersProvider extends NonCodeMembersContribut
|
||||
@Override
|
||||
public Result<List<PsiElement>> compute() {
|
||||
return new Result<List<PsiElement>>(Collections.<PsiElement>singletonList(
|
||||
getRootByClasses(InjectorUtils.findInjectionSupport(injection.getSupportId()).getPatternClasses(), file.getProject())),
|
||||
ArrayUtil.EMPTY_OBJECT_ARRAY);
|
||||
getRootByClasses(InjectorUtils.getPatternClasses(injection.getSupportId()), file.getProject())), ArrayUtil.EMPTY_OBJECT_ARRAY);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user