本文整理汇总了Java中com.intellij.openapi.util.Couple类的典型用法代码示例。如果您正苦于以下问题:Java Couple类的具体用法?Java Couple怎么用?Java Couple使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Couple类属于com.intellij.openapi.util包,在下文中一共展示了Couple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: duplicateLineOrSelectedBlockAtCaret
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
public static Couple<Integer> duplicateLineOrSelectedBlockAtCaret(Editor editor, final Document document, @NotNull Caret caret, final boolean moveCaret) {
if (caret.hasSelection()) {
int start = caret.getSelectionStart();
int end = caret.getSelectionEnd();
String s = document.getCharsSequence().subSequence(start, end).toString();
document.insertString(end, s);
if (moveCaret) {
// select newly copied lines and move there
caret.moveToOffset(end + s.length());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
caret.removeSelection();
caret.setSelection(end, end + s.length());
}
return Couple.of(end, end + s.length());
} else {
return duplicateLinesRange(editor, document, caret, caret.getOffset(), caret.getVisualPosition(), caret.getVisualPosition(), moveCaret);
}
}
示例2: collectDescriptorsRecursively
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
private static void collectDescriptorsRecursively(@NotNull ASTNode node,
@NotNull Document document,
@NotNull List<FoldingDescriptor> descriptors) {
final IElementType type = node.getElementType();
if (type == token(COMMENT)
&& spanMultipleLines(node, document)) {
descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
}
if (type == token(LINE_COMMENT)) {
final Couple<PsiElement> commentRange = expandLineCommentsRange(node.getPsi());
final int startOffset = commentRange.getFirst().getTextRange().getStartOffset();
final int endOffset = commentRange.getSecond().getTextRange().getEndOffset();
if (document.getLineNumber(startOffset) != document.getLineNumber(endOffset)) {
descriptors.add(new FoldingDescriptor(node, new TextRange(startOffset, endOffset)));
}
}
if (PROVIDERS.keySet().contains(type)
&& spanMultipleLines(node, document)) {
descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
}
for (ASTNode child : node.getChildren(null)) {
collectDescriptorsRecursively(child, document, descriptors);
}
}
示例3: collectExtensions
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
public Couple<List<String>> collectExtensions(GlobalSearchScope resolveScope) {
PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage("META-INF.services");
if (aPackage == null) {
return Couple.of(Collections.<String>emptyList(), Collections.<String>emptyList());
}
List<String> instanceClasses = new ArrayList<String>();
List<String> staticClasses = new ArrayList<String>();
for (PsiDirectory directory : aPackage.getDirectories(resolveScope)) {
PsiFile file = directory.findFile(ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE);
if (file instanceof PropertiesFile) {
IProperty inst = ((PropertiesFile)file).findPropertyByKey("extensionClasses");
IProperty stat = ((PropertiesFile)file).findPropertyByKey("staticExtensionClasses");
if (inst != null) collectClasses(inst, instanceClasses);
if (stat != null) collectClasses(stat, staticClasses);
}
}
return Couple.of(instanceClasses, staticClasses);
}
示例4: process
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
@Override
public boolean process(final PsiClass psiClass) {
final String inheritorName = psiClass.getName();
if (inheritorName == null) {
myAnonymousInheritorsCount++;
}
else {
final Couple<Integer> res = collectInheritorsInfo(psiClass,
myCollector,
myDisabledNames,
myProcessedElements,
myAllNotAnonymousInheritors);
myAnonymousInheritorsCount += res.getSecond();
if (!psiClass.isInterface()) {
myAllNotAnonymousInheritors.add(inheritorName);
}
}
return true;
}
示例5: invokeAction
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
@Nullable
protected Couple<String> invokeAction(@NotNull final Project project,
@NotNull PsiFile file,
@NotNull PsiElement psiElement,
@Nullable final String suggestedKey,
@Nullable String suggestedValue,
@Nullable final List<PropertiesFile> propertiesFiles) {
final PsiLiteralExpression literalExpression = psiElement instanceof PsiLiteralExpression ? (PsiLiteralExpression)psiElement : null;
final String propertyValue = suggestedValue == null ? "" : suggestedValue;
final I18nizeQuickFixDialog dialog = new JavaI18nizeQuickFixDialog(
project,
file,
literalExpression,
propertyValue,
createDefaultCustomization(suggestedKey, propertiesFiles),
false,
false
);
return doAction(project, psiElement, dialog);
}
示例6: getTemplateCouples
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
public Collection<Couple<TemplateResource>> getTemplateCouples() {
final LinkedHashMap<String, Couple<TemplateResource>> resources = new LinkedHashMap<String, Couple<TemplateResource>>();
for (TemplateResource resource : getAllTemplates()) {
final String baseName = getTemplateBaseName(resource);
TemplateResource eq = toEqualsName(baseName).equals(resource.getFileName()) ? resource : null;
TemplateResource hc = toHashCodeName(baseName).equals(resource.getFileName()) ? resource : null;
final Couple<TemplateResource> couple = resources.get(baseName);
if (couple != null) {
resources.put(baseName, Couple.of(couple.first != null ? couple.first : eq,
couple.second != null ? couple.second : hc));
}
else {
resources.put(baseName, Couple.of(eq, hc));
}
}
return resources.values();
}
示例7: getInternalCanonicalText
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
@Override
@NotNull
public String getInternalCanonicalText() {
Set<String> stringKeys = getStringKeys();
List<Couple<PsiType>> otherEntries = getOtherEntries();
if (stringKeys.isEmpty()) {
if (otherEntries.isEmpty()) return "[:]";
String name = getJavaClassName();
final PsiType[] params = getParameters();
return name + "<" + getInternalText(params[0]) + ", " + getInternalText(params[1]) + ">";
}
List<String> components = new ArrayList<String>();
for (String s : stringKeys) {
components.add("'" + s + "':" + getInternalCanonicalText(getTypeByStringKey(s)));
}
for (Couple<PsiType> entry : otherEntries) {
components.add(getInternalCanonicalText(entry.first) + ":" + getInternalCanonicalText(entry.second));
}
boolean tooMany = components.size() > 2;
final List<String> theFirst = components.subList(0, Math.min(2, components.size()));
return "[" + StringUtil.join(theFirst, ", ") + (tooMany ? ",..." : "") + "]";
}
示例8: walk
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
private static void walk(File root, MultiMap<Couple<Integer>, String> dimToPath, File file) throws IOException {
if (file.isDirectory()) {
for (File child : file.listFiles()) {
walk(root, dimToPath, child);
}
}
else {
if (IMAGE_EXTENSIONS.contains(FileUtilRt.getExtension(file.getName()))) {
String relativePath = file.getAbsolutePath().substring(root.getAbsolutePath().length() + 1);
Image image = loadImage(file);
File target;
int width = image.getWidth(null);
int height = image.getHeight(null);
if (height != width && (height > 100 || width > 100)) {
target = new File("/Users/max/images/other", relativePath);
}
else {
target = new File("/Users/max/images/icons", relativePath);
dimToPath.putValue(new Couple<Integer>(width, height), relativePath);
}
FileUtil.copy(file, target);
}
}
}
示例9: parseSelectors
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
@NotNull
private Map<String, String> parseSelectors() {
final Map<String, String> result = ContainerUtil.newLinkedHashMap();
List<Couple<String>> attrList = parseSelector();
while (attrList != null) {
for (Couple<String> attr : attrList) {
if (getClassAttributeName().equals(attr.first)) {
result.put(getClassAttributeName(), (StringUtil.notNullize(result.get(getClassAttributeName())) + " " + attr.second).trim());
}
else if (HtmlUtil.ID_ATTRIBUTE_NAME.equals(attr.first)) {
result.put(HtmlUtil.ID_ATTRIBUTE_NAME, (StringUtil.notNullize(result.get(HtmlUtil.ID_ATTRIBUTE_NAME)) + " " + attr.second).trim());
}
else {
result.put(attr.first, attr.second);
}
}
attrList = parseSelector();
}
return result;
}
示例10: process
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
public TextRange process(PsiElement element, TextRange range) {
if (!myPyCodeStyleSettings.SPACE_AFTER_NUMBER_SIGN) {
return range;
}
myRange = range;
final PsiDocumentManager manager = PsiDocumentManager.getInstance(myProject);
final Document document = manager.getDocument(element.getContainingFile());
if (document != null) {
manager.doPostponedOperationsAndUnblockDocument(document);
try {
// collect all comments
element.accept(this);
for (Couple<PsiComment> pair : myCommentReplacements) {
pair.getFirst().replace(pair.getSecond());
}
}
finally {
manager.commitDocument(document);
}
}
return TextRange.create(range.getStartOffset(), range.getEndOffset() + myDelta);
}
示例11: getPrecedingComments
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
/**
* Returns comments preceding given elements as pair of the first and the last such comments. Comments should not be
* separated by any empty line.
* @param element element comments should be adjacent to
* @return described range or {@code null} if there are no such comments
*/
@Nullable
public static Couple<PsiComment> getPrecedingComments(@NotNull PsiElement element) {
PsiComment firstComment = null, lastComment = null;
overComments:
while (true) {
int newLinesCount = 0;
for (element = element.getPrevSibling(); element instanceof PsiWhiteSpace; element = element.getPrevSibling()) {
newLinesCount += StringUtil.getLineBreakCount(element.getText());
if (newLinesCount > 1) {
break overComments;
}
}
if (element instanceof PsiComment) {
if (lastComment == null) {
lastComment = (PsiComment)element;
}
firstComment = (PsiComment)element;
}
else {
break;
}
}
return lastComment == null ? null : Couple.of(firstComment, lastComment);
}
示例12: computeHash
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
@NotNull
private Couple<Integer> computeHash(SingleChildDescriptor childDescriptor,
PsiFragment parentFragment,
NodeSpecificHasher nodeSpecificHasher) {
final PsiElement element = childDescriptor.getElement();
if (element == null) {
return Couple.of(0, 0);
}
final Couple<Integer> result = doComputeHash(childDescriptor, parentFragment, nodeSpecificHasher);
final DuplicatesProfileBase duplicatesProfile = ((NodeSpecificHasherBase)nodeSpecificHasher).getDuplicatesProfile();
final PsiElementRole role = duplicatesProfile.getRole(element);
if (role != null && !duplicatesProfile.getDuplocatorState(duplicatesProfile.getLanguage(element)).distinguishRole(role)) {
return Couple.of(0, result.second);
}
return result;
}
示例13: doAction
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
@Override
protected Couple<String> doAction(Project project, PsiElement psiElement, I18nizeQuickFixModel model) {
final Couple<String> result = super.doAction(project, psiElement, model);
if (result != null && psiElement instanceof PsiLiteralExpression) {
final String key = result.first;
final StringBuilder buffer = new StringBuilder();
buffer.append('"');
StringUtil.escapeStringCharacters(key.length(), key, buffer);
buffer.append('"');
final AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(JavaCreatePropertyFix.class);
try {
final PsiExpression newKeyLiteral = JavaPsiFacade.getElementFactory(project).createExpressionFromText(buffer.toString(), null);
psiElement.replace(newKeyLiteral);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
finally {
token.finish();
}
}
return result;
}
示例14: readExternal
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
public void readExternal(Element macro) {
setName(macro.getAttributeValue(ATTRIBUTE_NAME));
List actions = macro.getChildren();
for (final Object o : actions) {
Element action = (Element)o;
if (ELEMENT_TYPING.equals(action.getName())) {
Couple<List<Integer>> codes = parseKeyCodes(action.getAttributeValue(ATTRIBUTE_KEY_CODES));
String text = action.getText();
if (text == null || text.length() == 0) {
text = action.getAttributeValue(ATTRIBUTE_TEXT);
}
text = text.replaceAll(" ", " ");
if (!StringUtil.isEmpty(text)) {
myActions.add(new TypedDescriptor(text, codes.getFirst(), codes.getSecond()));
}
}
else if (ELEMENT_ACTION.equals(action.getName())) {
myActions.add(new IdActionDescriptor(action.getAttributeValue(ATTRIBUTE_ID)));
}
else if (ELEMENT_SHORTCUT.equals(action.getName())) {
myActions.add(new ShortcutActionDesciption(action.getAttributeValue(ATTRIBUTE_TEXT)));
}
}
}
示例15: editMacro
import com.intellij.openapi.util.Couple; //导入依赖的package包/类
public void editMacro() {
if (getSelectedRowCount() != 1) {
return;
}
final int selectedRow = getSelectedRow();
final Couple<String> pair = myMacros.get(selectedRow);
final String title = ApplicationBundle.message("title.edit.variable");
final String macroName = pair.getFirst();
final PathMacroEditor macroEditor = new PathMacroEditor(title, macroName, pair.getSecond(), new EditValidator());
if (macroEditor.showAndGet()) {
myMacros.remove(selectedRow);
myMacros.add(Couple.of(macroEditor.getName(), macroEditor.getValue()));
Collections.sort(myMacros, MACRO_COMPARATOR);
myTableModel.fireTableDataChanged();
}
}