use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.
the class CollectHighlightsUtil method getElementsToHighlight.
@NotNull
private static List<PsiElement> getElementsToHighlight(@NotNull PsiElement parent, final int startOffset, final int endOffset) {
final List<PsiElement> result = new ArrayList<>();
final int currentOffset = parent.getTextRange().getStartOffset();
final Condition<PsiElement>[] filters = Extensions.getExtensions(EP_NAME);
int offset = currentOffset;
final TIntStack starts = new TIntStack(STARTING_TREE_HEIGHT);
final Stack<PsiElement> elements = new Stack<>(STARTING_TREE_HEIGHT);
final Stack<PsiElement> children = new Stack<>(STARTING_TREE_HEIGHT);
PsiElement element = parent;
PsiElement child = PsiUtilCore.NULL_PSI_ELEMENT;
while (true) {
ProgressIndicatorProvider.checkCanceled();
for (Condition<PsiElement> filter : filters) {
if (!filter.value(element)) {
assert child == PsiUtilCore.NULL_PSI_ELEMENT;
// do not want to process children
child = null;
break;
}
}
boolean startChildrenVisiting;
if (child == PsiUtilCore.NULL_PSI_ELEMENT) {
startChildrenVisiting = true;
child = element.getFirstChild();
} else {
startChildrenVisiting = false;
}
if (child == null) {
if (startChildrenVisiting) {
// leaf element
offset += element.getTextLength();
}
if (elements.isEmpty())
break;
int start = starts.pop();
if (startOffset <= start && offset <= endOffset) {
assert element != null;
assert element != PsiUtilCore.NULL_PSI_ELEMENT;
result.add(element);
}
element = elements.pop();
child = children.pop();
} else {
// composite element
if (offset > endOffset)
break;
children.push(child.getNextSibling());
starts.push(offset);
assert element != null;
assert element != PsiUtilCore.NULL_PSI_ELEMENT;
elements.push(element);
element = child;
child = PsiUtilCore.NULL_PSI_ELEMENT;
}
}
return result;
}
use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.
the class JdkComboBox method setSetupButton.
public void setSetupButton(final JButton setUpButton, @Nullable final Project project, final ProjectSdksModel jdksModel, final JdkComboBoxItem firstItem, @Nullable final Condition<Sdk> additionalSetup, final String actionGroupTitle) {
mySetUpButton = setUpButton;
mySetUpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DefaultActionGroup group = new DefaultActionGroup();
jdksModel.createAddActions(group, JdkComboBox.this, getSelectedJdk(), jdk -> {
if (project != null) {
final JdkListConfigurable configurable = JdkListConfigurable.getInstance(project);
configurable.addJdkNode(jdk, false);
}
reloadModel(new ActualJdkComboBoxItem(jdk), project);
setSelectedJdk(jdk);
if (additionalSetup != null) {
if (additionalSetup.value(jdk)) {
setSelectedJdk(firstItem.getJdk());
}
}
}, myCreationFilter);
final DataContext dataContext = DataManager.getInstance().getDataContext(JdkComboBox.this);
if (group.getChildrenCount() > 1) {
JBPopupFactory.getInstance().createActionGroupPopup(actionGroupTitle, group, dataContext, JBPopupFactory.ActionSelectionAid.MNEMONICS, false).showUnderneathOf(setUpButton);
} else {
final AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0);
group.getChildren(event)[0].actionPerformed(event);
}
}
});
}
use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.
the class ExtractSuperClassUtil method createExtendingReference.
public static PsiJavaCodeReferenceElement createExtendingReference(final PsiClass superClass, final PsiClass derivedClass, final MemberInfo[] selectedMembers) throws IncorrectOperationException {
final PsiManager manager = derivedClass.getManager();
Set<PsiElement> movedElements = new com.intellij.util.containers.HashSet<>();
for (final MemberInfo info : selectedMembers) {
movedElements.add(info.getMember());
}
final Condition<PsiTypeParameter> filter = parameter -> findTypeParameterInDerived(derivedClass, parameter.getName()) == parameter;
final PsiTypeParameterList typeParameterList = RefactoringUtil.createTypeParameterListWithUsedTypeParameters(null, filter, PsiUtilCore.toPsiElementArray(movedElements));
final PsiTypeParameterList originalTypeParameterList = superClass.getTypeParameterList();
assert originalTypeParameterList != null;
final PsiTypeParameterList newList = typeParameterList != null ? (PsiTypeParameterList) originalTypeParameterList.replace(typeParameterList) : originalTypeParameterList;
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<>();
for (final PsiTypeParameter parameter : newList.getTypeParameters()) {
final PsiTypeParameter parameterInDerived = findTypeParameterInDerived(derivedClass, parameter.getName());
if (parameterInDerived != null) {
substitutionMap.put(parameter, factory.createType(parameterInDerived));
}
}
final PsiClassType type = factory.createType(superClass, factory.createSubstitutor(substitutionMap));
return factory.createReferenceElementByType(type);
}
use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.
the class CodeStyleGenerationConfigurable method createComponent.
public JComponent createComponent() {
myVisibilityPanel.add(myJavaVisibilityPanel, BorderLayout.CENTER);
GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH, new JBInsets(0, 0, 0, 0), 0, 0);
final Condition<PsiClass> isApplicable = aClass -> aClass.isAnnotationType();
//noinspection Convert2Diamond
myRepeatAnnotationsModel = new SortedListModel<String>(Comparator.naturalOrder());
myOverridePanel.add(SpecialAnnotationsUtil.createSpecialAnnotationsListControl("Annotations to Copy", false, isApplicable, myRepeatAnnotationsModel), gc);
return myPanel;
}
use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.
the class GitBranchWorker method checkoutNewBranch.
public void checkoutNewBranch(@NotNull final String name, @NotNull List<GitRepository> repositories) {
updateInfo(repositories);
repositories = ContainerUtil.filter(repositories, new Condition<GitRepository>() {
@Override
public boolean value(GitRepository repository) {
GitLocalBranch currentBranch = repository.getCurrentBranch();
return currentBranch == null || !currentBranch.getName().equals(name);
}
});
if (!repositories.isEmpty()) {
new GitCheckoutNewBranchOperation(myProject, myGit, myUiHandler, repositories, name).execute();
} else {
LOG.error("Creating new branch the same as current in all repositories: " + name);
}
}
Aggregations