Пример #1
0
 @SuppressWarnings({"unchecked"})
 private static <T extends BaseInjection> List<T> readExternal(
     Element element, Factory<T> factory) {
   final List<T> injections = new ArrayList<T>();
   if (element != null) {
     final List<Element> list = element.getChildren(ENTRY_NAME);
     for (Element entry : list) {
       final T o = factory.create();
       o.loadState(entry);
       injections.add(o);
     }
   }
   return injections;
 }
 void applyFilter(@NotNull final List<T> requests, final ThreadReference thread) {
   for (T request : requests) {
     try {
       final boolean wasEnabled = request.isEnabled();
       if (wasEnabled) {
         request.disable();
       }
       addFilter(request, thread);
       if (wasEnabled) {
         request.enable();
       }
     } catch (InternalException e) {
       LOG.info(e);
     }
   }
 }
  @SuppressWarnings({"unchecked"})
  @NotNull
  public static <T extends PsiType> T originalize(@NotNull T type) {
    if (!type.isValid()) {
      return type;
    }

    T result =
        new PsiTypeMapper() {
          private final Set<PsiClassType> myVisited = ContainerUtil.newIdentityTroveSet();

          @Override
          public PsiType visitClassType(final PsiClassType classType) {
            if (!myVisited.add(classType)) return classType;

            final PsiClassType.ClassResolveResult classResolveResult = classType.resolveGenerics();
            final PsiClass psiClass = classResolveResult.getElement();
            final PsiSubstitutor substitutor = classResolveResult.getSubstitutor();
            if (psiClass == null) return classType;

            return new PsiImmediateClassType(
                CompletionUtil.getOriginalOrSelf(psiClass), originalizeSubstitutor(substitutor));
          }

          private PsiSubstitutor originalizeSubstitutor(final PsiSubstitutor substitutor) {
            PsiSubstitutor originalSubstitutor = PsiSubstitutor.EMPTY;
            for (final Map.Entry<PsiTypeParameter, PsiType> entry :
                substitutor.getSubstitutionMap().entrySet()) {
              final PsiType value = entry.getValue();
              originalSubstitutor =
                  originalSubstitutor.put(
                      CompletionUtil.getOriginalOrSelf(entry.getKey()),
                      value == null ? null : mapType(value));
            }
            return originalSubstitutor;
          }

          @Override
          public PsiType visitType(PsiType type) {
            return type;
          }
        }.mapType(type);
    if (result == null) {
      throw new AssertionError("Null result for type " + type + " of class " + type.getClass());
    }
    return result;
  }
Пример #4
0
 public static <T> void assertOneOf(T value, T... values) {
   boolean found = false;
   for (T v : values) {
     if (value == v || value != null && value.equals(v)) {
       found = true;
     }
   }
   Assert.assertTrue(value + " should be equal to one of " + Arrays.toString(values), found);
 }
 @NotNull
 public <T extends PsiPolyVariantReference> ResolveResult[] resolveWithCaching(
     @NotNull T ref,
     @NotNull PolyVariantResolver<T> resolver,
     boolean needToPreventRecursion,
     boolean incompleteCode) {
   return resolveWithCaching(
       ref,
       resolver,
       needToPreventRecursion,
       incompleteCode,
       ref.getElement().getContainingFile());
 }