下面列出了com.intellij.psi.codeStyle.CustomCodeStyleSettings#com.intellij.openapi.util.Trinity 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void removeNotification(Notification notification) {
synchronized (myNotifications) {
myNotifications.remove(notification);
}
Runnable handler = removeHandlers.remove(notification);
if (handler != null) {
UIUtil.invokeLaterIfNeeded(handler);
}
Trinity<Notification, String, Long> oldStatus = getStatusMessage();
if (oldStatus != null && notification == oldStatus.first) {
setStatusToImportant();
}
fireModelChanged();
}
void removeNotification(Notification notification) {
synchronized (myNotifications) {
myNotifications.remove(notification);
}
Runnable handler = removeHandlers.remove(notification);
if (handler != null) {
UIUtil.invokeLaterIfNeeded(handler);
}
Trinity<Notification, String, Long> oldStatus = getStatusMessage();
if (oldStatus != null && notification == oldStatus.first) {
setStatusToImportant();
}
fireModelChanged();
}
/**
* Order is deterministic. First element matches {@link FileViewProvider#getStubBindingRoot()}
*/
@Nonnull
public static List<Pair<IStubFileElementType, PsiFile>> getStubbedRoots(@Nonnull FileViewProvider viewProvider) {
final List<Trinity<Language, IStubFileElementType, PsiFile>> roots = new SmartList<>();
final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
for (Language language : viewProvider.getLanguages()) {
final PsiFile file = viewProvider.getPsi(language);
if (file instanceof PsiFileImpl) {
final IElementType type = ((PsiFileImpl)file).getElementTypeForStubBuilder();
if (type != null) {
roots.add(Trinity.create(language, (IStubFileElementType)type, file));
}
}
}
ContainerUtil.sort(roots, (o1, o2) -> {
if (o1.third == stubBindingRoot) return o2.third == stubBindingRoot ? 0 : -1;
else if (o2.third == stubBindingRoot) return 1;
else return StringUtil.compare(o1.first.getID(), o2.first.getID(), false);
});
return ContainerUtil.map(roots, trinity -> Pair.create(trinity.second, trinity.third));
}
@Override
public void showCustomOption(Class<? extends CustomCodeStyleSettings> settingsClass,
String fieldName,
String title,
String groupName,
@Nullable OptionAnchor anchor,
@Nullable String anchorFieldName,
Object... options) {
if (myIsFirstUpdate) {
myCustomOptions.putValue(groupName, Trinity.create(settingsClass, fieldName, title));
}
for (IntOption option : myOptions) {
if (option.myTarget.getName().equals(fieldName)) {
option.myIntField.setEnabled(true);
}
}
}
public TemplateKindCombo() {
getComboBox().setRenderer(new ColoredListCellRenderer() {
@Override
protected void customizeCellRenderer(@Nonnull JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof Trinity) {
append((String)((Trinity)value).first);
setIcon((Image)((Trinity)value).second);
}
}
});
new ComboboxSpeedSearch(getComboBox()) {
@Override
protected String getElementText(Object element) {
if (element instanceof Trinity) {
return (String)((Trinity)element).first;
}
return null;
}
};
setButtonListener(null);
}
@Nullable
public static Trinity<Notification, String, Long> getStatusMessage(@Nullable Project project) {
ConsoleLogModel model = getLogModel(project);
if(model != null) {
return model.getStatusMessage();
}
return null;
}
void setStatusMessage(@Nullable Notification statusMessage, long stamp) {
synchronized (myNotifications) {
if (myStatusMessage != null && myStatusMessage.first == statusMessage) return;
if (myStatusMessage == null && statusMessage == null) return;
myStatusMessage = statusMessage == null ? null : Trinity.create(statusMessage, myStatuses.get(statusMessage), stamp);
}
StatusBar.Info.set("", myProject, ConsoleLog.LOG_REQUESTOR);
}
@Nonnull
@RequiredReadAction
@Override
public Trinity<String, DotNetTypeRef, Boolean> getParameterInfo(@Nonnull DotNetParameter parameter)
{
return Trinity.create(parameter.getName(), parameter.toTypeRef(true), parameter.hasModifier(CSharpModifier.OPTIONAL));
}
@RequiredReadAction
@Nonnull
@Override
public Trinity<String, DotNetTypeRef, Boolean> getParameterInfo(@Nonnull CSharpSimpleParameterInfo parameter)
{
return Trinity.create(parameter.getNotNullName(), parameter.getTypeRef(), parameter.isOptional());
}
public abstract void collectFiles(CompileContext context,
TranslatingCompiler compiler,
Iterator<VirtualFile> scopeSrcIterator,
boolean forceCompile,
boolean isRebuild,
Collection<VirtualFile> toCompile,
Collection<Trinity<File, String, Boolean>> toDelete);
public static void packageFile(@Nonnull VirtualFile file, @Nonnull Project project, final Artifact[] artifacts) throws IOException {
LOG.debug("Start packaging file: " + file.getPath());
final Collection<Trinity<Artifact, PackagingElementPath, String>> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project, artifacts);
File ioFile = VfsUtilCore.virtualToIoFile(file);
for (Trinity<Artifact, PackagingElementPath, String> item : items) {
final Artifact artifact = item.getFirst();
final String outputPath = artifact.getOutputPath();
if (!StringUtil.isEmpty(outputPath)) {
PackageFileWorker worker = new PackageFileWorker(ioFile, item.getThird());
LOG.debug(" package to " + outputPath);
worker.packageFile(outputPath, item.getSecond().getParents());
}
}
}
void setStatusMessage(@Nullable Notification statusMessage, long stamp) {
synchronized (myNotifications) {
if (myStatusMessage != null && myStatusMessage.first == statusMessage) return;
if (myStatusMessage == null && statusMessage == null) return;
myStatusMessage = statusMessage == null ? null : Trinity.create(statusMessage, EventLog.formatForLog(statusMessage, "").status, stamp);
}
StatusBar.Info.set("", myProject, EventLog.LOG_REQUESTOR);
}
@Nullable
private <TRef extends PsiReference, TResult> TResult resolve(@Nonnull final TRef ref,
@Nonnull final AbstractResolver<? super TRef, TResult> resolver,
boolean needToPreventRecursion,
final boolean incompleteCode,
boolean isPoly,
boolean isPhysical) {
ProgressIndicatorProvider.checkCanceled();
if (isPhysical) {
ApplicationManager.getApplication().assertReadAccessAllowed();
}
int index = getIndex(incompleteCode, isPoly);
Map<TRef, TResult> map = getMap(isPhysical, index);
TResult result = map.get(ref);
if (result != null) {
return result;
}
RecursionGuard.StackStamp stamp = RecursionManager.markStack();
result = needToPreventRecursion
? RecursionManager.doPreventingRecursion(Trinity.create(ref, incompleteCode, isPoly), true, () -> resolver.resolve(ref, incompleteCode))
: resolver.resolve(ref, incompleteCode);
if (result instanceof ResolveResult) {
ensureValidPsi((ResolveResult)result);
}
else if (result instanceof ResolveResult[]) {
ensureValidResults((ResolveResult[])result);
}
else if (result instanceof PsiElement) {
PsiUtilCore.ensureValid((PsiElement)result);
}
if (stamp.mayCacheNow()) {
cache(ref, map, result);
}
return result;
}
@Override
public boolean process(Trinity<ProblemDescriptor, LocalInspectionToolWrapper, ProgressIndicator> trinity) {
ProgressIndicator indicator = trinity.getThird();
if (indicator.isCanceled()) {
return false;
}
ProblemDescriptor descriptor = trinity.first;
LocalInspectionToolWrapper tool = trinity.second;
PsiElement psiElement = descriptor.getPsiElement();
if (psiElement == null) return true;
PsiFile file = psiElement.getContainingFile();
Document thisDocument = documentManager.getDocument(file);
HighlightSeverity severity = inspectionProfile.getErrorLevel(HighlightDisplayKey.find(tool.getShortName()), file).getSeverity();
infos.clear();
createHighlightsForDescriptor(infos, emptyActionRegistered, ilManager, file, thisDocument, tool, severity, descriptor, psiElement);
for (HighlightInfo info : infos) {
final EditorColorsScheme colorsScheme = getColorsScheme();
UpdateHighlightersUtil
.addHighlighterToEditorIncrementally(myProject, myDocument, getFile(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset(),
info, colorsScheme, getId(), ranges2markersCache);
}
return true;
}
private void addDescriptorIncrementally(@Nonnull final ProblemDescriptor descriptor,
@Nonnull final LocalInspectionToolWrapper tool,
@Nonnull final ProgressIndicator indicator) {
if (myIgnoreSuppressed && SuppressionUtil.inspectionResultSuppressed(descriptor.getPsiElement(), tool.getTool())) {
return;
}
myTransferToEDTQueue.offer(Trinity.create(descriptor, tool, indicator));
}
@Override
public List<TextRange> select(final PsiElement e, final CharSequence editorText, final int cursorOffset, final Editor editor) {
final VirtualFile file = e.getContainingFile().getVirtualFile();
final FileType fileType = file == null? null : file.getFileType();
if (fileType == null) return super.select(e, editorText, cursorOffset, editor);
final int textLength = editorText.length();
final TextRange totalRange = e.getTextRange();
final HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(totalRange.getStartOffset());
final BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
final ArrayList<TextRange> result = new ArrayList<TextRange>();
final LinkedList<Trinity<Integer, Integer, IElementType>> stack = new LinkedList<Trinity<Integer, Integer, IElementType>>();
while (!iterator.atEnd() && iterator.getStart() < totalRange.getEndOffset()) {
final Trinity<Integer, Integer, IElementType> last;
if (braceMatcher.isLBraceToken(iterator, editorText, fileType)) {
stack.addLast(Trinity.create(iterator.getStart(), iterator.getEnd(), iterator.getTokenType()));
}
else if (braceMatcher.isRBraceToken(iterator, editorText, fileType)
&& !stack.isEmpty() && braceMatcher.isPairBraces((last = stack.getLast()).third, iterator.getTokenType())) {
stack.removeLast();
result.addAll(expandToWholeLine(editorText, new TextRange(last.first, iterator.getEnd())));
int bodyStart = last.second;
int bodyEnd = iterator.getStart();
while (bodyStart < textLength && Character.isWhitespace(editorText.charAt(bodyStart))) bodyStart ++;
while (bodyEnd > 0 && Character.isWhitespace(editorText.charAt(bodyEnd - 1))) bodyEnd --;
result.addAll(expandToWholeLine(editorText, new TextRange(bodyStart, bodyEnd)));
}
iterator.advance();
}
result.add(e.getTextRange());
return result;
}
@Nullable
private TokenParser findParser() {
final IElementType tokenType = getTokenType();
for (final Trinity<Integer, PathPattern, TokenParser> trinity : myRegistry.getParsers(tokenType)) {
if (trinity.first > myPriority && trinity.second.accepts(this)) {
return trinity.third;
}
}
return null;
}
public CreateWithTemplatesDialogPanel(@Nonnull List<Trinity<String, Image, String>> templates, @Nullable String selectedItem) {
super(templates, LIST_RENDERER);
myTemplatesList.addListSelectionListener(e -> {
Trinity<String, Image, String> selectedValue = myTemplatesList.getSelectedValue();
if (selectedValue != null) {
setTextFieldIcon(selectedValue.second);
}
});
selectTemplate(selectedItem);
setTemplatesListVisible(templates.size() > 1);
}
private void selectTemplate(@Nullable String selectedItem) {
if (selectedItem == null) {
myTemplatesList.setSelectedIndex(0);
return;
}
ListModel<Trinity<String, Image, String>> model = myTemplatesList.getModel();
for (int i = 0; i < model.getSize(); i++) {
String templateID = model.getElementAt(i).getThird();
if (selectedItem.equals(templateID)) {
myTemplatesList.setSelectedIndex(i);
return;
}
}
}
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
IdeView view = e.getData(LangDataKeys.IDE_VIEW);
Project project = e.getData(CommonDataKeys.PROJECT);
if (view == null || project == null) {
return;
}
PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
if (directory == null) {
return;
}
Trinity<ContentFolderTypeProvider, PsiDirectory, ChildType> info = getInfo(directory);
boolean isDirectory = info.getThird() == ChildType.Directory;
CreateDirectoryOrPackageHandler validator = new CreateDirectoryOrPackageHandler(project, directory, isDirectory, info.getThird().getSeparator());
String title = isDirectory ? IdeBundle.message("title.new.directory") : IdeBundle.message("title.new.package");
createLightWeightPopup(validator, title, element -> {
if (element != null) {
view.selectElement(element);
}
}).showCenteredInCurrentWindow(project);
}
@Nonnull
@RequiredUIAccess
private static Trinity<ContentFolderTypeProvider, PsiDirectory, ChildType> getInfo(PsiDirectory d) {
Project project = d.getProject();
ProjectFileIndex projectFileIndex = ProjectFileIndex.getInstance(project);
Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(d);
if (moduleForPsiElement != null) {
boolean isPackageSupported = false;
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForPsiElement);
List<PsiPackageSupportProvider> extensions = PsiPackageSupportProvider.EP_NAME.getExtensionList();
for (ModuleExtension moduleExtension : moduleRootManager.getExtensions()) {
for (PsiPackageSupportProvider supportProvider : extensions) {
if (supportProvider.isSupported(moduleExtension)) {
isPackageSupported = true;
break;
}
}
}
if (isPackageSupported) {
ContentFolderTypeProvider contentFolderTypeForFile = projectFileIndex.getContentFolderTypeForFile(d.getVirtualFile());
if (contentFolderTypeForFile != null) {
Image childPackageIcon = contentFolderTypeForFile.getChildPackageIcon();
return Trinity.create(contentFolderTypeForFile, d, childPackageIcon != null ? ChildType.Package : ChildType.Directory);
}
}
}
return Trinity.create(null, d, ChildType.Directory);
}
public String getSelectedName() {
//noinspection unchecked
final Trinity<String, Image, String> trinity = (Trinity<String, Image, String>)getComboBox().getSelectedItem();
if (trinity == null) {
// design time
return null;
}
return trinity.third;
}
public void setSelectedName(@Nullable String name) {
if (name == null) return;
ComboBoxModel model = getComboBox().getModel();
for (int i = 0, n = model.getSize(); i < n; i++) {
Trinity<String, Image, String> trinity = (Trinity<String, Image, String>)model.getElementAt(i);
if (name.equals(trinity.third)) {
getComboBox().setSelectedItem(trinity);
return;
}
}
}
@Nullable
Trinity<Notification, String, Long> getStatusMessage() {
synchronized (myNotifications) {
return myStatusMessage;
}
}
public List<Trinity<String, String, Long>> getEvents() {
return myEvents;
}
public void publishEvent(String entityName, String actionName){
myEvents.add(Trinity.create(entityName, actionName, System.currentTimeMillis()));
}
@Override
public void syncOutDir(Trinity<File, String, Boolean> trinity) throws CacheCorruptedException {
for (DependencyCache ourDependencyExtension : myDependencyCaches) {
ourDependencyExtension.syncOutDir(trinity);
}
}
@Nullable
Trinity<Notification, String, Long> getStatusMessage() {
synchronized (myNotifications) {
return myStatusMessage;
}
}
private void initCustomOptions(OptionGroup optionGroup, String groupName) {
for (Trinity<Class<? extends CustomCodeStyleSettings>, String, String> each : myCustomOptions.get(groupName)) {
doCreateOption(optionGroup, each.third, new IntOption(each.third, each.first, each.second), each.second);
}
}
@Nonnull
private static Trinity<Project, String, String> createExecutionId(String executorId, @Nonnull ExecutionEnvironment environment) {
return Trinity.create(environment.getProject(), executorId, environment.getRunner().getRunnerId());
}