Java 类com.intellij.psi.injection.ReferenceInjector 实例源码

项目:intellij-ce-playground    文件:MultiHostRegistrarImpl.java   
@Override
@NotNull
public MultiHostRegistrar startInjecting(@NotNull Language language) {
  escapers = new SmartList<LiteralTextEscaper<? extends PsiLanguageInjectionHost>>();
  shreds = new SmartList<PsiLanguageInjectionHost.Shred>();
  outChars = new StringBuilder();

  if (!cleared) {
    clear();
    throw new IllegalStateException("Seems you haven't called doneInjecting()");
  }

  if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null) {
    ReferenceInjector injector = ReferenceInjector.findById(language.getID());
    if (injector == null) {
      throw new UnsupportedOperationException("Cannot inject language '" + language + "' since its getParserDefinition() returns null");
    }
    myLanguage = null;
    myReferenceInjector = injector;
  }
  myLanguage = language;

  return this;
}
项目:intellij-ce-playground    文件:InjectionsSettingsUI.java   
public CfgInfo(Configuration cfg, final String title) {
  this.cfg = cfg;
  this.title = title;
  bundledInjections.addAll(cfg.getDefaultInjections());
  originalInjections = new ArrayList<BaseInjection>(ContainerUtil
    .concat(InjectorUtils.getActiveInjectionSupportIds(), new Function<String, Collection<? extends BaseInjection>>() {
      public Collection<? extends BaseInjection> fun(final String s) {
        List<BaseInjection> injections =
          CfgInfo.this.cfg instanceof Configuration.Prj ? ((Configuration.Prj)CfgInfo.this.cfg).getOwnInjections(s) : CfgInfo.this.cfg
            .getInjections(s);
        return ContainerUtil.findAll(injections, new Condition<BaseInjection>() {
            public boolean value(final BaseInjection injection) {
              String id = injection.getInjectedLanguageId();
              return InjectedLanguage.findLanguageById(id) != null || ReferenceInjector.findById(id) != null;
            }
          });
      }
    }));
  sortInjections(originalInjections);
  reset();
}
项目:tools-idea    文件:InjectionsSettingsUI.java   
public CfgInfo(Configuration cfg, final String title) {
  this.cfg = cfg;
  this.title = title;
  bundledInjections.addAll(cfg.getDefaultInjections());
  originalInjections = new ArrayList<BaseInjection>(ContainerUtil
    .concat(InjectorUtils.getActiveInjectionSupportIds(), new Function<String, Collection<? extends BaseInjection>>() {
      public Collection<? extends BaseInjection> fun(final String s) {
        List<BaseInjection> injections =
          CfgInfo.this.cfg instanceof Configuration.Prj ? ((Configuration.Prj)CfgInfo.this.cfg).getOwnInjections(s) : CfgInfo.this.cfg
            .getInjections(s);
        return ContainerUtil.findAll(injections, new Condition<BaseInjection>() {
            public boolean value(final BaseInjection injection) {
              String id = injection.getInjectedLanguageId();
              return InjectedLanguage.findLanguageById(id) != null || ReferenceInjector.findById(id) != null;
            }
          });
      }
    }));
  sortInjections(originalInjections);
  reset();
}
项目:intellij-ce-playground    文件:UnknownLanguageID.java   
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
  return new JavaElementVisitor() {
    final String annotationName = Configuration.getProjectInstance(holder.getProject()).getAdvancedConfiguration().getLanguageAnnotationClass();

    @Override
    public void visitNameValuePair(PsiNameValuePair valuePair) {
      final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(valuePair, PsiAnnotation.class);
      if (annotation != null) {
        final String qualifiedName = annotation.getQualifiedName();
        if (annotationName.equals(qualifiedName)) {
          final String name = valuePair.getName();
          if (name == null || "value".equals(name)) {
            final PsiAnnotationMemberValue value = valuePair.getValue();
            if (value instanceof PsiExpression) {
              final PsiExpression expression = (PsiExpression)value;
              final Object id = JavaPsiFacade.getInstance(expression.getProject()).
                getConstantEvaluationHelper().computeConstantExpression(expression);
              if (id instanceof String) {
                if (InjectedLanguage.findLanguageById((String)id) == null && ReferenceInjector.findById((String)id) == null) {
                  holder.registerProblem(expression, "Unknown language '" + id + "'", ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
                }
              }
            }
          }
        }
      }
    }
  };
}
项目:intellij-ce-playground    文件:InjectLanguageAction.java   
public static List<Injectable> getAllInjectables() {
  Language[] languages = InjectedLanguage.getAvailableLanguages();
  List<Injectable> list = new ArrayList<Injectable>();
  for (Language language : languages) {
    list.add(Injectable.fromLanguage(language));
  }
  list.addAll(Arrays.asList(ReferenceInjector.EXTENSION_POINT_NAME.getExtensions()));
  Collections.sort(list);
  return list;
}
项目:tools-idea    文件:InjectLanguageAction.java   
public static List<Injectable> getAllInjectables() {
  Language[] languages = InjectedLanguage.getAvailableLanguages();
  List<Injectable> list = new ArrayList<Injectable>();
  for (Language language : languages) {
    list.add(Injectable.fromLanguage(language));
  }
  list.addAll(Arrays.asList(ReferenceInjector.EXTENSION_POINT_NAME.getExtensions()));
  Collections.sort(list);
  return list;
}
项目:consulo    文件:InjectionRegistrarImpl.java   
void injectReference(@Nonnull LanguageVersion languageVersion, @Nonnull String prefix, @Nonnull String suffix, @Nonnull PsiLanguageInjectionHost host, @Nonnull TextRange rangeInsideHost) {
  ParserDefinition parser = LanguageParserDefinitions.INSTANCE.forLanguage(languageVersion.getLanguage());
  if (parser != null) {
    throw new IllegalArgumentException("Language " + languageVersion.getLanguage() + " being injected as reference must not have ParserDefinition and yet - " + parser);
  }
  ReferenceInjector injector = ReferenceInjector.findById(languageVersion.getLanguage().getID());
  if (injector == null) {
    throw new IllegalArgumentException("Language " + languageVersion.getLanguage() + " being injected as reference must register reference injector");
  }
  placeInfos = new SmartList<>();

  if (!cleared) {
    clear();
    throw new IllegalStateException("Seems you haven't called doneInjecting()");
  }

  myLanguageVersion = languageVersion;
  currentThread = Thread.currentThread();

  addPlace(prefix, suffix, host, rangeInsideHost);
  Place place = new Place();
  StringBuilder decodedChars = new StringBuilder();
  ShredImpl shred = createShred(placeInfos.get(0), decodedChars, myHostPsiFile);
  place.add(shred);
  if (resultReferences == null) {
    resultReferences = new SmartList<>();
  }
  resultReferences.add(Pair.create(injector, place));
  clear();
}
项目:consulo    文件:InjectionRegistrarImpl.java   
void addToResults(@Nonnull InjectionResult result) {
  if (result.files != null) {
    for (PsiFile file : result.files) {
      addFileToResults(file);
    }
  }
  if (result.references != null) {
    for (Pair<ReferenceInjector, Place> pair : result.references) {
      addReferenceToResults(pair);
    }
  }
}
项目:consulo    文件:InjectionResult.java   
boolean isValid() {
  if (files != null) {
    for (PsiFile file : files) {
      if (!file.isValid()) return false;
    }
  }
  else {
    for (Pair<ReferenceInjector, Place> pair : references) {
      Place place = pair.getSecond();
      if (!place.isValid()) return false;
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:MultiHostRegistrarImpl.java   
ReferenceInjector getReferenceInjector() {
  return myReferenceInjector;
}
项目:consulo    文件:InjectionRegistrarImpl.java   
private void addReferenceToResults(@Nonnull Pair<ReferenceInjector, Place> pair) {
  if (resultReferences == null) {
    resultReferences = new SmartList<>();
  }
  resultReferences.add(pair);
}
项目:consulo    文件:InjectionResult.java   
InjectionResult(List<PsiFile> files, List<Pair<ReferenceInjector, Place>> references) {
  this.files = files;
  this.references = references;
  if (files == null && references == null) throw new IllegalArgumentException("At least one argument must not be null");
}
项目:intellij-ce-playground    文件:InjectedReferenceVisitor.java   
public abstract void visitInjectedReference(@NotNull ReferenceInjector injector, @NotNull List<PsiLanguageInjectionHost.Shred> places);
项目:consulo    文件:InjectedReferenceVisitor.java   
public abstract void visitInjectedReference(@Nonnull ReferenceInjector injector, @Nonnull List<PsiLanguageInjectionHost.Shred> places);