Java Code Examples for com.intellij.util.PairProcessor#process()

The following examples show how to use com.intellij.util.PairProcessor#process() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PatternCondition.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean processParameters(final PairProcessor<String, Object> processor) {
  for (Class aClass = getClass(); aClass != null; aClass = aClass.getSuperclass()) {
    for (final Field field : aClass.getDeclaredFields()) {
      if (!Modifier.isStatic(field.getModifiers()) &&
          (((field.getModifiers() & 0x1000 /*Modifer.SYNTHETIC*/) == 0 && !aClass.equals(PatternCondition.class))
           || field.getName().startsWith(PARAMETER_FIELD_PREFIX))) {
        final String name = field.getName();
        final String fixedName = name.startsWith(PARAMETER_FIELD_PREFIX) ?
                                 name.substring(PARAMETER_FIELD_PREFIX.length()) : name;
        final Object value = getFieldValue(field);
        if (!processor.process(fixedName, value)) return false;
      }
    }
  }
  return true;
}
 
Example 2
Source File: QuerySearchRequest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public QuerySearchRequest(@Nonnull Query<PsiReference> query,
                          @Nonnull final SearchRequestCollector collector,
                          boolean inReadAction,
                          @Nonnull final PairProcessor<? super PsiReference, ? super SearchRequestCollector> processor) {
  this.query = query;
  this.collector = collector;
  if (inReadAction) {
    this.processor = new ReadActionProcessor<PsiReference>() {
      @Override
      public boolean processInReadAction(PsiReference psiReference) {
        return processor.process(psiReference, collector);
      }
    };
  }
  else {
    this.processor = psiReference -> processor.process(psiReference, collector);
  }
}
 
Example 3
Source File: AreaMap.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void getSimiliar(final Key key, final PairProcessor<Key, Val> consumer) {
  final int idx = Collections.binarySearch(myKeys, key, myComparator);
  if (idx < 0) {
    final int insertionIdx = - idx - 1;
    // take item before
    final int itemBeforeIdx = insertionIdx - 1;
    if (itemBeforeIdx >= 0) {
      for (ListIterator<Key> iterator = myKeys.listIterator(itemBeforeIdx + 1); iterator.hasPrevious(); ) {
        final Key candidate = iterator.previous();
        if (! myKeysResemblance.process(candidate, key)) continue;
        if (consumer.process(candidate, myMap.get(candidate))) break;     // if need only a part of keys
      }
    }
  } else {
    consumer.process(key, myMap.get(key));
  }
}
 
Example 4
Source File: MembershipMap.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void optimizeMap(final PairProcessor<Val, Val> valuesAreas) {
  int i = 0;
  for (Iterator<Key> iterator = myKeys.iterator(); iterator.hasNext();) {
    final Key key = iterator.next();
    final Val value = myMap.get(key);

    // go for parents
    for (int j = i - 1; j >= 0; -- j) {
      final Key innerKey = myKeys.get(j);
      if (myKeysResemblance.process(innerKey, key)) {
        if (valuesAreas.process(myMap.get(innerKey), value)) {
          -- i;
          iterator.remove();
          myMap.remove(key);
        }
        // otherwise we found a "parent", and do not remove the child
        break;
      }
    }
    ++ i;
  }
}
 
Example 5
Source File: ShowIntentionActionsHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Pair<PsiFile, Editor> chooseBetweenHostAndInjected(@Nonnull PsiFile hostFile,
                                                                 @Nonnull Editor hostEditor,
                                                                 @Nullable PsiFile injectedFile,
                                                                 @Nonnull PairProcessor<? super PsiFile, ? super Editor> predicate) {
  Editor editorToApply = null;
  PsiFile fileToApply = null;

  Editor injectedEditor = null;
  if (injectedFile != null) {
    injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile);
    if (predicate.process(injectedFile, injectedEditor)) {
      editorToApply = injectedEditor;
      fileToApply = injectedFile;
    }
  }

  if (editorToApply == null && hostEditor != injectedEditor && predicate.process(hostFile, hostEditor)) {
    editorToApply = hostEditor;
    fileToApply = hostFile;
  }
  if (editorToApply == null) return null;
  return Pair.create(fileToApply, editorToApply);
}
 
Example 6
Source File: ConfigurationErrors.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void _do(@Nonnull final ConfigurationError error, @Nonnull final Project project,
                       @Nonnull final PairProcessor<ConfigurationErrors, ConfigurationError> fun) {
  if (!project.isInitialized()) {
    StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
       @Override
       public void run() {
         fun.process(project.getMessageBus().syncPublisher(TOPIC), error);
       }
     });

    return;
  }

  final MessageBus bus = project.getMessageBus();
  if (EventQueue.isDispatchThread()) fun.process(bus.syncPublisher(TOPIC), error);
  else {
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        fun.process(bus.syncPublisher(TOPIC), error);
      }
    });
  }
}
 
Example 7
Source File: JavaClassQualifiedNameReference.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static PatternCondition<PsiElementBase> nameCondition(final ElementPattern pattern) {
  return new PatternConditionPlus<PsiElementBase, String>("_withPsiName", pattern) {
    @Override
    public boolean processValues(
        PsiElementBase t,
        ProcessingContext context,
        PairProcessor<String, ProcessingContext> processor) {
      return processor.process(t.getName(), context);
    }
  };
}
 
Example 8
Source File: PsiElementPattern.java    From consulo with Apache License 2.0 5 votes vote down vote up
private PatternCondition<T> _withText(final ElementPattern pattern) {
  return new PatternConditionPlus<T, String>("_withText", pattern) {
    @Override
    public boolean processValues(T t,
                                 ProcessingContext context,
                                 PairProcessor<String, ProcessingContext> processor) {
      return processor.process(t.getText(), context);
    }
  };
}
 
Example 9
Source File: PsiTreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean treeWalkUp(@Nonnull final PsiElement entrance, @Nullable final PsiElement maxScope, PairProcessor<PsiElement, PsiElement> eachScopeAndLastParent) {
  PsiElement prevParent = null;
  PsiElement scope = entrance;

  while (scope != null) {
    if (!eachScopeAndLastParent.process(scope, prevParent)) return false;

    if (scope == maxScope) break;
    prevParent = scope;
    scope = prevParent.getContext();
  }

  return true;

}
 
Example 10
Source File: SoftArrayHashMap.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean processLeafEntries(final PairProcessor<T, V> processor) {
  if (myValuesMap != null) {
    for (T t : myValuesMap.keySet()) {
      if (!processor.process(t, myValuesMap.get(t))) return false;
    }
  }
  if (myContinuationMap != null) {
    for (SoftArrayHashMap<T, V> map : myContinuationMap.values()) {
      if (!map.processLeafEntries(processor)) return false;
    }
  }
  return true;
}
 
Example 11
Source File: PropertyPatternCondition.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean processValues(T t, ProcessingContext context, PairProcessor<P, ProcessingContext> processor) {
  return processor.process(getPropertyValue(t), context);
}