use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.
the class WorkingContextManager method getContextHistory.
private synchronized List<ContextInfo> getContextHistory(String zipPostfix) {
JBZipFile archive = null;
try {
archive = getTasksArchive(zipPostfix);
List<JBZipEntry> entries = archive.getEntries();
return ContainerUtil.mapNotNull(entries, (NullableFunction<JBZipEntry, ContextInfo>) entry -> entry.getName().startsWith("/context") ? new ContextInfo(entry.getName(), entry.getTime(), entry.getComment()) : null);
} catch (IOException e) {
LOG.error(e);
return Collections.emptyList();
} finally {
closeArchive(archive);
}
}
use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.
the class ExpectedHighlightingData method composeText.
public static String composeText(final Map<String, ExpectedHighlightingSet> types, Collection<HighlightInfo> infos, String text) {
// filter highlighting data and map each highlighting to a tag name
List<Pair<String, HighlightInfo>> list = ContainerUtil.mapNotNull(infos, (NullableFunction<HighlightInfo, Pair<String, HighlightInfo>>) info -> {
for (Map.Entry<String, ExpectedHighlightingSet> entry : types.entrySet()) {
final ExpectedHighlightingSet set = entry.getValue();
if (set.enabled && set.severity == info.getSeverity() && set.endOfLine == info.isAfterEndOfLine()) {
return Pair.create(entry.getKey(), info);
}
}
return null;
});
boolean showAttributesKeys = false;
for (ExpectedHighlightingSet eachSet : types.values()) {
for (HighlightInfo eachInfo : eachSet.infos) {
if (eachInfo.forcedTextAttributesKey != null) {
showAttributesKeys = true;
break;
}
}
}
// sort filtered highlighting data by end offset in descending order
Collections.sort(list, (o1, o2) -> {
HighlightInfo i1 = o1.second;
HighlightInfo i2 = o2.second;
int byEnds = i2.endOffset - i1.endOffset;
if (byEnds != 0)
return byEnds;
if (!i1.isAfterEndOfLine() && !i2.isAfterEndOfLine()) {
int byStarts = i1.startOffset - i2.startOffset;
if (byStarts != 0)
return byStarts;
} else {
int byEOL = Comparing.compare(i2.isAfterEndOfLine(), i1.isAfterEndOfLine());
if (byEOL != 0)
return byEOL;
}
int bySeverity = i2.getSeverity().compareTo(i1.getSeverity());
if (bySeverity != 0)
return bySeverity;
return Comparing.compare(i1.getDescription(), i2.getDescription());
});
// combine highlighting data with original text
StringBuilder sb = new StringBuilder();
Couple<Integer> result = composeText(sb, list, 0, text, text.length(), 0, showAttributesKeys);
sb.insert(0, text.substring(0, result.second));
return sb.toString();
}
use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.
the class NonProjectFileAccessTest method typeAndCheck.
private void typeAndCheck(VirtualFile file, @Nullable final NonProjectFileWritingAccessProvider.UnlockOption option, boolean fileHasBeenChanged) {
Editor editor = getEditor(file);
NullableFunction<List<VirtualFile>, NonProjectFileWritingAccessProvider.UnlockOption> unlocker = files -> option;
NonProjectFileWritingAccessProvider.setCustomUnlocker(unlocker);
String before = editor.getDocument().getText();
typeInChar(editor, 'a');
if (fileHasBeenChanged) {
assertEquals("Text should be changed", 'a' + before, editor.getDocument().getText());
} else {
assertEquals("Text should not be changed", before, editor.getDocument().getText());
}
}
use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.
the class GppExpectedTypesContributor method addExpectedConstructorParameters.
private static List<TypeConstraint> addExpectedConstructorParameters(GrListOrMap list, GrExpression[] args, GrExpression arg) {
PsiType[] argTypes = ContainerUtil.map2Array(args, PsiType.class, (NullableFunction<GrExpression, PsiType>) grExpression -> grExpression.getType());
final ArrayList<TypeConstraint> result = new ArrayList<>();
for (PsiType type : GroovyExpectedTypesProvider.getDefaultExpectedTypes(list)) {
if (type instanceof PsiClassType) {
for (GroovyResolveResult resolveResult : PsiUtil.getConstructorCandidates((PsiClassType) type, argTypes, list)) {
final PsiElement method = resolveResult.getElement();
if (method instanceof PsiMethod && ((PsiMethod) method).isConstructor()) {
final Map<GrExpression, Pair<PsiParameter, PsiType>> map = GrClosureSignatureUtil.mapArgumentsToParameters(resolveResult, list, false, true, GrNamedArgument.EMPTY_ARRAY, args, GrClosableBlock.EMPTY_ARRAY);
if (map != null) {
final Pair<PsiParameter, PsiType> pair = map.get(arg);
if (pair != null) {
result.add(SubtypeConstraint.create(pair.second));
}
}
}
}
}
}
return result;
}
use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.
the class HierarchyBrowserBaseEx method createTree.
protected final JTree createTree(boolean dndAware) {
final Tree tree;
final NullableFunction<Object, PsiElement> toPsiConverter = o -> {
if (o instanceof HierarchyNodeDescriptor) {
return ((HierarchyNodeDescriptor) o).getContainingFile();
}
return null;
};
if (dndAware) {
//noinspection Duplicates
tree = new DnDAwareTree(new DefaultTreeModel(new DefaultMutableTreeNode(""))) {
@Override
public void removeNotify() {
super.removeNotify();
if (ScreenUtil.isStandardAddRemoveNotify(this))
myRefreshAction.unregisterCustomShortcutSet(this);
}
@Override
public boolean isFileColorsEnabled() {
return ProjectViewTree.isFileColorsEnabledFor(this);
}
@Override
public Color getFileColorFor(Object object) {
return ProjectViewTree.getColorForObject(object, myProject, toPsiConverter);
}
};
if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
DnDManager.getInstance().registerSource(new DnDSource() {
@Override
public boolean canStartDragging(final DnDAction action, final Point dragOrigin) {
return getSelectedElements().length > 0;
}
@Override
public DnDDragStartBean startDragging(final DnDAction action, final Point dragOrigin) {
return new DnDDragStartBean(new TransferableWrapper() {
@Override
public TreeNode[] getTreeNodes() {
return tree.getSelectedNodes(TreeNode.class, null);
}
@Override
public PsiElement[] getPsiElements() {
return getSelectedElements();
}
@Override
public List<File> asFileList() {
return PsiCopyPasteManager.asFileList(getPsiElements());
}
});
}
@Override
public Pair<Image, Point> createDraggedImage(final DnDAction action, final Point dragOrigin) {
return null;
}
@Override
public void dragDropEnd() {
}
@Override
public void dropActionChanged(final int gestureModifiers) {
}
}, tree);
}
} else {
//noinspection Duplicates
tree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode(""))) {
@Override
public void removeNotify() {
super.removeNotify();
if (ScreenUtil.isStandardAddRemoveNotify(this))
myRefreshAction.unregisterCustomShortcutSet(this);
}
@Override
public boolean isFileColorsEnabled() {
return ProjectViewTree.isFileColorsEnabledFor(this);
}
@Override
public Color getFileColorFor(Object object) {
return ProjectViewTree.getColorForObject(object, myProject, toPsiConverter);
}
};
}
configureTree(tree);
EditSourceOnDoubleClickHandler.install(tree);
EditSourceOnEnterKeyHandler.install(tree);
myRefreshAction.registerShortcutOn(tree);
return tree;
}
Aggregations