mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 09:03:31 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
Generated
+9
@@ -0,0 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="DTDParser">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/dtdparser113.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
Regular → Executable
@@ -26,8 +26,7 @@ import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectClasspathTraversing;
|
||||
import com.intellij.openapi.roots.ProjectRootsTraversing;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
@@ -78,7 +77,7 @@ public class HotSwapManager extends AbstractProjectComponent {
|
||||
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
final List<VirtualFile> allClasses = ProjectRootsTraversing.collectRoots(myProject, ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE).getRootDirs();
|
||||
final List<VirtualFile> allClasses = OrderEnumerator.orderEntries(myProject).getPathsList().getRootDirs();
|
||||
|
||||
final VirtualFile[] allDirs = VfsUtil.toVirtualFileArray(allClasses);
|
||||
final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
|
||||
|
||||
@@ -280,7 +280,7 @@ public class ChangeContextUtil {
|
||||
return refMemberClass;
|
||||
}
|
||||
|
||||
private static boolean canRemoveQualifier(PsiReferenceExpression refExpr) {
|
||||
public static boolean canRemoveQualifier(PsiReferenceExpression refExpr) {
|
||||
try{
|
||||
PsiExpression qualifier = refExpr.getQualifierExpression();
|
||||
if (!(qualifier instanceof PsiReferenceExpression)) return false;
|
||||
|
||||
+3
-3
@@ -27,9 +27,9 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -91,7 +91,7 @@ public class AddSingleMemberStaticImportAction extends PsiElementBaseIntentionAc
|
||||
}
|
||||
});
|
||||
|
||||
((PsiReferenceExpressionImpl)refExpr).bindToElementViaStaticImport(((PsiMember)resolved).getContainingClass(), ((PsiNamedElement)resolved).getName(), ((PsiJavaFile)file).getImportList());
|
||||
RefactoringUtil.bindToElementViaStaticImport(((PsiMember)resolved).getContainingClass(), ((PsiNamedElement)resolved).getName(), ((PsiJavaFile)file).getImportList());
|
||||
|
||||
file.accept(new JavaRecursiveElementVisitor() {
|
||||
@Override public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
@@ -134,4 +134,4 @@ public class AddSingleMemberStaticImportAction extends PsiElementBaseIntentionAc
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocToken;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ConvertToBasicLatinAction extends PsiElementBaseIntentionAction {
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) {
|
||||
final Pair<PsiElement, Handler> pair = findHandler(element);
|
||||
if (pair == null) return false;
|
||||
|
||||
final String text = pair.first.getText();
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (shouldConvert(text.charAt(i))) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return CodeInsightBundle.message("intention.convert.to.basic.latin");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return getFamilyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
|
||||
final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
if (element == null) return;
|
||||
|
||||
final Pair<PsiElement, Handler> pair = findHandler(element);
|
||||
if (pair == null) return;
|
||||
|
||||
final String text = pair.first.getText();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
final char ch = text.charAt(i);
|
||||
if (!shouldConvert(ch)) {
|
||||
sb.append(ch);
|
||||
}
|
||||
else {
|
||||
pair.second.convert(sb, ch);
|
||||
}
|
||||
}
|
||||
|
||||
pair.first.replace(pair.second.createReplacement(project, sb.toString(), pair.first.getParent()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<PsiElement, Handler> findHandler(final PsiElement element) {
|
||||
for (final Handler handler : ourHandlers) {
|
||||
final PsiElement applicable = handler.findApplicable(element);
|
||||
if (applicable != null) {
|
||||
return Pair.create(applicable, handler);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private interface Handler {
|
||||
@Nullable
|
||||
PsiElement findApplicable(PsiElement element);
|
||||
PsiElement createReplacement(Project project, String text, PsiElement context);
|
||||
void convert(StringBuilder sb, char ch);
|
||||
}
|
||||
|
||||
private static final List<? extends Handler> ourHandlers = Arrays.asList(
|
||||
new Handler() {
|
||||
public PsiElement findApplicable(final PsiElement element) {
|
||||
return element instanceof PsiJavaToken && ourLiterals.contains(((PsiJavaToken)element).getTokenType()) ?
|
||||
element.getParent() : null;
|
||||
}
|
||||
|
||||
public PsiElement createReplacement(final Project project, final String text, final PsiElement context) {
|
||||
return JavaPsiFacade.getElementFactory(project).createExpressionFromText(text, context);
|
||||
}
|
||||
|
||||
public void convert(final StringBuilder sb, final char ch) {
|
||||
sb.append(String.format("\\u%04x", (int)ch));
|
||||
}
|
||||
},
|
||||
|
||||
new Handler() {
|
||||
public PsiElement findApplicable(final PsiElement element) {
|
||||
if (element instanceof PsiDocComment) return element;
|
||||
if (element instanceof PsiDocToken) return element.getParent();
|
||||
if (element instanceof PsiWhiteSpace) return PsiTreeUtil.getParentOfType(element, PsiDocComment.class);
|
||||
return null;
|
||||
}
|
||||
|
||||
public PsiElement createReplacement(final Project project, final String text, final PsiElement context) {
|
||||
return JavaPsiFacade.getElementFactory(project).createDocCommentFromText(text, context);
|
||||
}
|
||||
|
||||
public void convert(final StringBuilder sb, final char ch) {
|
||||
convertHtmlChar(sb, ch);
|
||||
}
|
||||
},
|
||||
|
||||
new Handler() {
|
||||
public PsiElement findApplicable(final PsiElement element) {
|
||||
if (element instanceof PsiComment) return element;
|
||||
if (element instanceof PsiWhiteSpace) return PsiTreeUtil.getParentOfType(element, PsiComment.class);
|
||||
return null;
|
||||
}
|
||||
|
||||
public PsiElement createReplacement(final Project project, final String text, final PsiElement context) {
|
||||
return JavaPsiFacade.getElementFactory(project).createCommentFromText(text, context);
|
||||
}
|
||||
|
||||
public void convert(final StringBuilder sb, final char ch) {
|
||||
convertHtmlChar(sb, ch);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
private static boolean shouldConvert(final char ch) {
|
||||
return Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.BASIC_LATIN;
|
||||
}
|
||||
|
||||
private static final TokenSet ourLiterals = TokenSet.create(JavaTokenType.CHARACTER_LITERAL, JavaTokenType.STRING_LITERAL);
|
||||
|
||||
// todo: use standard HTML entities (e.g. U+00E9 -> é)
|
||||
private static void convertHtmlChar(final StringBuilder sb, final char ch) {
|
||||
sb.append("&#x").append(Integer.toHexString(ch)).append(';');
|
||||
}
|
||||
}
|
||||
+215
-27
@@ -15,28 +15,35 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.actions;
|
||||
|
||||
import com.intellij.codeInsight.ChangeContextUtil;
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.codeInsight.actions.OptimizeImportsProcessor;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.DirectClassInheritorsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class ReplaceImplementsWithStaticImportAction implements IntentionAction {
|
||||
public class ReplaceImplementsWithStaticImportAction extends PsiElementBaseIntentionAction {
|
||||
private static final Logger LOG = Logger.getInstance("#" + ReplaceImplementsWithStaticImportAction.class.getName());
|
||||
@NonNls private static final String FIND_CONSTANT_FIELD_USAGES = "Find constant field usages...";
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
@@ -48,8 +55,14 @@ public class ReplaceImplementsWithStaticImportAction implements IntentionAction
|
||||
return getText();
|
||||
}
|
||||
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
if (!(file instanceof PsiJavaFile)) return false;
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
if (!(element.getContainingFile() instanceof PsiJavaFile)) return false;
|
||||
if (element instanceof PsiIdentifier) {
|
||||
final PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiClass) {
|
||||
return isEmptyClass(project, (PsiClass)parent) && DirectClassInheritorsSearch.search((PsiClass)parent).findFirst() != null;
|
||||
}
|
||||
}
|
||||
final PsiReference psiReference = TargetElementUtilBase.findReference(editor);
|
||||
if (psiReference == null) return false;
|
||||
|
||||
@@ -64,11 +77,13 @@ public class ReplaceImplementsWithStaticImportAction implements IntentionAction
|
||||
final PsiElement target = psiReference.resolve();
|
||||
if (target == null || !(target instanceof PsiClass)) return false;
|
||||
|
||||
PsiClass targetClass = (PsiClass)target;
|
||||
return isEmptyClass(project, (PsiClass)target);
|
||||
}
|
||||
|
||||
private static boolean isEmptyClass(Project project, PsiClass targetClass) {
|
||||
if (!targetClass.isInterface()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiReferenceList extendsList = targetClass.getExtendsList();
|
||||
LOG.assertTrue(extendsList != null);
|
||||
if (extendsList.getReferencedTypes().length > 0) {
|
||||
@@ -78,7 +93,8 @@ public class ReplaceImplementsWithStaticImportAction implements IntentionAction
|
||||
if (objectClass == null) return false;
|
||||
methods.removeAll(Arrays.asList(objectClass.getMethods()));
|
||||
if (methods.size() > 0) return false;
|
||||
} else if (targetClass.getMethods().length > 0){
|
||||
}
|
||||
else if (targetClass.getMethods().length > 0) {
|
||||
return false;
|
||||
}
|
||||
return targetClass.getAllFields().length > 0;
|
||||
@@ -87,30 +103,202 @@ public class ReplaceImplementsWithStaticImportAction implements IntentionAction
|
||||
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
|
||||
if (!CodeInsightUtilBase.preparePsiElementForWrite(file)) return;
|
||||
|
||||
final PsiReference psiReference = file.findReferenceAt(editor.getCaretModel().getOffset());
|
||||
LOG.assertTrue(psiReference != null);
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
final PsiReference psiReference = file.findReferenceAt(offset);
|
||||
if (psiReference != null) {
|
||||
final PsiElement element = psiReference.getElement();
|
||||
|
||||
final PsiElement element = psiReference.getElement();
|
||||
final PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
|
||||
LOG.assertTrue(psiClass != null);
|
||||
|
||||
final PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
|
||||
LOG.assertTrue(psiClass != null);
|
||||
final PsiElement target = psiReference.resolve();
|
||||
LOG.assertTrue(target instanceof PsiClass);
|
||||
|
||||
final PsiElement target = psiReference.resolve();
|
||||
LOG.assertTrue(target instanceof PsiClass);
|
||||
final PsiClass targetClass = (PsiClass)target;
|
||||
new WriteCommandAction(project, getText()) {
|
||||
protected void run(Result result) throws Throwable {
|
||||
for (PsiField constField : targetClass.getAllFields()) {
|
||||
final String fieldName = constField.getName();
|
||||
final PsiClass containingClass = constField.getContainingClass();
|
||||
for (PsiReference ref : ReferencesSearch.search(constField)) {
|
||||
final PsiElement psiElement = ref.getElement();
|
||||
if (ref instanceof PsiReferenceExpression) {
|
||||
final PsiElement qualifier = ((PsiReferenceExpression)ref).getQualifier();
|
||||
if (qualifier != null) {
|
||||
if (qualifier instanceof PsiReferenceExpression) {
|
||||
final PsiElement resolved = ((PsiReferenceExpression)qualifier).resolve();
|
||||
if (resolved instanceof PsiClass && !InheritanceUtil.isInheritorOrSelf(psiClass, (PsiClass)resolved, true)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
qualifier.putCopyableUserData(ChangeContextUtil.CAN_REMOVE_QUALIFIER_KEY,
|
||||
ChangeContextUtil.canRemoveQualifier((PsiReferenceExpression)ref));
|
||||
}
|
||||
}
|
||||
bindReference(psiElement.getContainingFile(), constField, containingClass, fieldName, ref, project);
|
||||
}
|
||||
}
|
||||
element.delete();
|
||||
JavaCodeStyleManager.getInstance(project).optimizeImports(file);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
else {
|
||||
final PsiElement identifier = file.findElementAt(offset);
|
||||
LOG.assertTrue(identifier instanceof PsiIdentifier);
|
||||
final PsiElement element = identifier.getParent();
|
||||
LOG.assertTrue(element instanceof PsiClass);
|
||||
final PsiClass targetClass = (PsiClass)element;
|
||||
final Map<PsiFile, Map<PsiField, Set<PsiReference>>> refs = new HashMap<PsiFile, Map<PsiField, Set<PsiReference>>>();
|
||||
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
|
||||
public void run() {
|
||||
for (PsiField field : targetClass.getAllFields()) {
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
for (PsiReference reference : ReferencesSearch.search(field)) {
|
||||
if (reference == null) {
|
||||
continue;
|
||||
}
|
||||
final PsiElement refElement = reference.getElement();
|
||||
if (encodeQualifier(containingClass, reference, targetClass)) continue;
|
||||
final PsiFile psiFile = refElement.getContainingFile();
|
||||
if (psiFile instanceof PsiJavaFile) {
|
||||
Map<PsiField, Set<PsiReference>> references = refs.get(psiFile);
|
||||
if (references == null) {
|
||||
references = new HashMap<PsiField, Set<PsiReference>>();
|
||||
refs.put(psiFile, references);
|
||||
}
|
||||
Set<PsiReference> fieldsRefs = references.get(field);
|
||||
if (fieldsRefs == null) {
|
||||
fieldsRefs = new HashSet<PsiReference>();
|
||||
references.put(field, fieldsRefs);
|
||||
}
|
||||
fieldsRefs.add(reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, FIND_CONSTANT_FIELD_USAGES, true, project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiClass targetClass = (PsiClass)target;
|
||||
final Set<PsiJavaCodeReferenceElement> refs2Unimplement = new HashSet<PsiJavaCodeReferenceElement>();
|
||||
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
|
||||
public void run() {
|
||||
for (PsiClass psiClass : DirectClassInheritorsSearch.search(targetClass)) {
|
||||
PsiFile containingFile = psiClass.getContainingFile();
|
||||
if (!refs.containsKey(containingFile)) {
|
||||
refs.put(containingFile, new HashMap<PsiField, Set<PsiReference>>());
|
||||
}
|
||||
if (collectExtendsImplements(targetClass, psiClass.getExtendsList(), refs2Unimplement)) continue;
|
||||
collectExtendsImplements(targetClass, psiClass.getImplementsList(), refs2Unimplement);
|
||||
}
|
||||
}
|
||||
}, "Find references in implement/extends lists...", true, project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (PsiField constField : targetClass.getAllFields()) {
|
||||
for (PsiReference ref : ReferencesSearch.search(constField, new LocalSearchScope(psiClass))) {
|
||||
((PsiReferenceExpressionImpl)ref).bindToElementViaStaticImport(targetClass, constField.getName(), ((PsiJavaFile)file).getImportList());
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
for (PsiFile psiFile : refs.keySet()) {
|
||||
final Map<PsiField, Set<PsiReference>> map = refs.get(psiFile);
|
||||
for (PsiField psiField : map.keySet()) {
|
||||
final PsiClass containingClass = psiField.getContainingClass();
|
||||
final String fieldName = psiField.getName();
|
||||
for (PsiReference reference : map.get(psiField)) {
|
||||
bindReference(psiFile, psiField, containingClass, fieldName, reference, project);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiJavaCodeReferenceElement referenceElement : refs2Unimplement) {
|
||||
referenceElement.delete();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final Set<SmartPsiElementPointer<PsiImportStatementBase>> redundant = new HashSet<SmartPsiElementPointer<PsiImportStatementBase>>();
|
||||
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
|
||||
final SmartPointerManager pointerManager = SmartPointerManager.getInstance(project);
|
||||
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable(){
|
||||
public void run() {
|
||||
for (PsiFile psiFile : refs.keySet()) {
|
||||
final Collection<PsiImportStatementBase> red = codeStyleManager.findRedundantImports((PsiJavaFile)psiFile);
|
||||
if (red != null) {
|
||||
for (PsiImportStatementBase statementBase : red) {
|
||||
redundant.add(pointerManager.createSmartPsiElementPointer(statementBase));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, "Collect redundant imports...", true, project)) return;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
for (SmartPsiElementPointer<PsiImportStatementBase> pointer : redundant) {
|
||||
final PsiImportStatementBase statementBase = pointer.getElement();
|
||||
if (statementBase != null) statementBase.delete();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean encodeQualifier(PsiClass containingClass, PsiReference reference, PsiClass targetClass) {
|
||||
if (reference instanceof PsiReferenceExpression) {
|
||||
final PsiElement qualifier = ((PsiReferenceExpression)reference).getQualifier();
|
||||
if (qualifier != null) {
|
||||
if (qualifier instanceof PsiReferenceExpression) {
|
||||
final PsiElement resolved = ((PsiReferenceExpression)qualifier).resolve();
|
||||
if (resolved == containingClass || resolved instanceof PsiClass && InheritanceUtil.isInheritorOrSelf(targetClass, (PsiClass)resolved, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
qualifier.putCopyableUserData(ChangeContextUtil.CAN_REMOVE_QUALIFIER_KEY,
|
||||
ChangeContextUtil.canRemoveQualifier((PsiReferenceExpression)reference));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
element.delete();
|
||||
new OptimizeImportsProcessor(project, file).run();
|
||||
private static void bindReference(PsiFile psiFile,
|
||||
PsiField psiField,
|
||||
PsiClass containingClass,
|
||||
String fieldName,
|
||||
PsiReference reference,
|
||||
Project project) {
|
||||
if (reference instanceof PsiReferenceExpression) {
|
||||
RefactoringUtil.bindToElementViaStaticImport(containingClass, fieldName, ((PsiJavaFile)psiFile).getImportList());
|
||||
final PsiElement qualifier = ((PsiReferenceExpression)reference).getQualifier();
|
||||
if (qualifier != null) {
|
||||
final Boolean canRemoveQualifier = qualifier.getCopyableUserData(ChangeContextUtil.CAN_REMOVE_QUALIFIER_KEY);
|
||||
if (canRemoveQualifier != null && canRemoveQualifier.booleanValue()) {
|
||||
qualifier.delete();
|
||||
} else {
|
||||
final PsiJavaCodeReferenceElement classReferenceElement =
|
||||
JavaPsiFacade.getElementFactory(project).createReferenceExpression(containingClass);
|
||||
qualifier.replace(classReferenceElement);
|
||||
}
|
||||
}
|
||||
} else if (reference.getElement() instanceof PsiDocMethodOrFieldRef){
|
||||
reference.bindToElement(psiField); //todo refs through inheritors
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean collectExtendsImplements(final PsiClass targetClass,
|
||||
final PsiReferenceList referenceList,
|
||||
final Set<PsiJavaCodeReferenceElement> refs) {
|
||||
if (referenceList != null) {
|
||||
for (PsiJavaCodeReferenceElement referenceElement : referenceList.getReferenceElements()) {
|
||||
if (referenceElement.resolve() == targetClass) {
|
||||
refs.add(referenceElement);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,7 @@ import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootsTraversing;
|
||||
import com.intellij.openapi.roots.ProjectClasspathTraversing;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
|
||||
public final class ClasspathMacro extends Macro {
|
||||
public String getName() {
|
||||
@@ -34,6 +33,6 @@ public final class ClasspathMacro extends Macro {
|
||||
public String expand(DataContext dataContext) {
|
||||
Project project = PlatformDataKeys.PROJECT.getData(dataContext);
|
||||
if (project == null) return null;
|
||||
return ProjectRootsTraversing.collectRoots(project, ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE).getPathsString();
|
||||
return OrderEnumerator.orderEntries(project).getPathsList().getPathsString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,14 +36,12 @@ import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.ex.PathUtilEx;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ProjectRootsTraversing;
|
||||
import com.intellij.openapi.roots.SourceFolder;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.PathsList;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -224,16 +222,22 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl
|
||||
|
||||
parameters.addParametersString(OTHER_OPTIONS);
|
||||
|
||||
final String classPath = jdk.getSdkType() instanceof JavaSdk
|
||||
? ProjectRootsTraversing.collectRoots(myProject, ProjectRootsTraversing.PROJECT_LIBRARIES).getPathsString()
|
||||
: ProjectRootsTraversing.collectRoots(myProject, ProjectRootsTraversing.LIBRARIES_AND_JDK).getPathsString(); //libraries are included into jdk
|
||||
if (classPath.length() >0) {
|
||||
final PathsList classPath;
|
||||
if (jdk.getSdkType() instanceof JavaSdk) {
|
||||
classPath = OrderEnumerator.orderEntries(myProject).withoutSdk().withoutThisModuleContent().getPathsList();
|
||||
}
|
||||
else {
|
||||
//libraries are included into jdk
|
||||
classPath = OrderEnumerator.orderEntries(myProject).withoutThisModuleContent().getPathsList();
|
||||
}
|
||||
final String classPathString = classPath.getPathsString();
|
||||
if (classPathString.length() > 0) {
|
||||
parameters.add("-classpath");
|
||||
parameters.add(classPath);
|
||||
parameters.add(classPathString);
|
||||
}
|
||||
|
||||
parameters.add("-sourcepath");
|
||||
parameters.add(ProjectRootsTraversing.collectRoots(myProject, ProjectRootsTraversing.PROJECT_SOURCES).getPathsString());
|
||||
parameters.add(OrderEnumerator.orderEntries(myProject).withoutSdk().withoutLibraries().getSourcePathsList().getPathsString());
|
||||
|
||||
if (OUTPUT_DIRECTORY != null) {
|
||||
parameters.add("-d");
|
||||
|
||||
+2
-33
@@ -17,7 +17,6 @@ package com.intellij.psi.impl.source.tree.java;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
@@ -47,9 +46,9 @@ import com.intellij.psi.scope.processor.MethodResolverProcessor;
|
||||
import com.intellij.psi.scope.util.PsiScopesUtil;
|
||||
import com.intellij.psi.tree.ChildRoleBase;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.CharTable;
|
||||
import com.intellij.util.Function;
|
||||
@@ -59,8 +58,6 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PsiReferenceExpressionImpl extends ExpressionPsiElement implements PsiReferenceExpression, SourceJavaCodeReference {
|
||||
@@ -105,7 +102,7 @@ public class PsiReferenceExpressionImpl extends ExpressionPsiElement implements
|
||||
doImportStatic = false;
|
||||
}
|
||||
if (doImportStatic) {
|
||||
bindToElementViaStaticImport(qualifierClass, staticName, importList);
|
||||
RefactoringUtil.bindToElementViaStaticImport(qualifierClass, staticName, importList);
|
||||
}
|
||||
else {
|
||||
PsiManagerEx manager = getManager();
|
||||
@@ -118,34 +115,6 @@ public class PsiReferenceExpressionImpl extends ExpressionPsiElement implements
|
||||
return this;
|
||||
}
|
||||
|
||||
public void bindToElementViaStaticImport(final PsiClass qualifierClass, final String staticName, final PsiImportList importList)
|
||||
throws IncorrectOperationException {
|
||||
final String qualifiedName = qualifierClass.getQualifiedName();
|
||||
final List<PsiJavaCodeReferenceElement> refs = getImportsFromClass(importList, qualifiedName);
|
||||
if (refs.size() < CodeStyleSettingsManager.getSettings(getProject()).NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND) {
|
||||
importList.add(JavaPsiFacade.getInstance(getProject()).getElementFactory().createImportStaticStatement(qualifierClass, staticName));
|
||||
} else {
|
||||
for (PsiJavaCodeReferenceElement ref : refs) {
|
||||
final PsiImportStaticStatement importStatement = PsiTreeUtil.getParentOfType(ref, PsiImportStaticStatement.class);
|
||||
if (importStatement != null) {
|
||||
importStatement.delete();
|
||||
}
|
||||
}
|
||||
importList.add(JavaPsiFacade.getInstance(getProject()).getElementFactory().createImportStaticStatement(qualifierClass, "*"));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<PsiJavaCodeReferenceElement> getImportsFromClass(@NotNull PsiImportList importList, String className){
|
||||
final List<PsiJavaCodeReferenceElement> array = new ArrayList<PsiJavaCodeReferenceElement>();
|
||||
for (PsiImportStaticStatement staticStatement : importList.getImportStaticStatements()) {
|
||||
final PsiClass psiClass = staticStatement.resolveTargetClass();
|
||||
if (psiClass != null && Comparing.strEqual(psiClass.getQualifiedName(), className)) {
|
||||
array.add(staticStatement.getImportReference());
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void setQualifierExpression(@Nullable PsiExpression newQualifier) throws IncorrectOperationException {
|
||||
final PsiExpression oldQualifier = getQualifierExpression();
|
||||
if (newQualifier == null) {
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.controlFlow.ControlFlowUtil;
|
||||
@@ -62,6 +63,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.psi.JavaTokenType.*;
|
||||
|
||||
public class RefactoringUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.util.RefactoringUtil");
|
||||
public static final int EXPR_COPY_SAFE = 0;
|
||||
@@ -882,6 +885,34 @@ public class RefactoringUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void bindToElementViaStaticImport(final PsiClass qualifierClass, final String staticName, final PsiImportList importList)
|
||||
throws IncorrectOperationException {
|
||||
final String qualifiedName = qualifierClass.getQualifiedName();
|
||||
final List<PsiJavaCodeReferenceElement> refs = getImportsFromClass(importList, qualifiedName);
|
||||
if (refs.size() < CodeStyleSettingsManager.getSettings(qualifierClass.getProject()).NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND) {
|
||||
importList.add(JavaPsiFacade.getInstance(qualifierClass.getProject()).getElementFactory().createImportStaticStatement(qualifierClass, staticName));
|
||||
} else {
|
||||
for (PsiJavaCodeReferenceElement ref : refs) {
|
||||
final PsiImportStaticStatement importStatement = PsiTreeUtil.getParentOfType(ref, PsiImportStaticStatement.class);
|
||||
if (importStatement != null) {
|
||||
importStatement.delete();
|
||||
}
|
||||
}
|
||||
importList.add(JavaPsiFacade.getInstance(qualifierClass.getProject()).getElementFactory().createImportStaticStatement(qualifierClass, "*"));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PsiJavaCodeReferenceElement> getImportsFromClass(@NotNull PsiImportList importList, String className){
|
||||
final List<PsiJavaCodeReferenceElement> array = new ArrayList<PsiJavaCodeReferenceElement>();
|
||||
for (PsiImportStaticStatement staticStatement : importList.getImportStaticStatements()) {
|
||||
final PsiClass psiClass = staticStatement.resolveTargetClass();
|
||||
if (psiClass != null && Comparing.strEqual(psiClass.getQualifiedName(), className)) {
|
||||
array.add(staticStatement.getImportReference());
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static interface ImplicitConstructorUsageVisitor {
|
||||
void visitConstructor(PsiMethod constructor, PsiMethod baseConstructor);
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class C {
|
||||
char ch = '<caret>©';
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class C {
|
||||
char ch = '\u00a9';
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**<caret>
|
||||
* Copyright © 2000-2010 JetBrains s.r.o.
|
||||
*/
|
||||
class C {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Copyright © 2000-2010 JetBrains s.r.o.
|
||||
*/
|
||||
class C {
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class C {
|
||||
//<caret> © 2010 JetBrains
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class C {
|
||||
// © 2010 JetBrains
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class C {
|
||||
String s = "<caret>Áî";
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class C {
|
||||
String s = "\u00c1\u00ee";
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
|
||||
import static In.FOO;
|
||||
|
||||
interface In {
|
||||
int FOO = 0;
|
||||
}
|
||||
|
||||
class II {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class II1 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class Uc {
|
||||
static final String FOO = "";
|
||||
void g() {
|
||||
System.out.println("" + In.FOO);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
|
||||
import static In.FOO;
|
||||
|
||||
interface In {
|
||||
int FOO = 0;
|
||||
}
|
||||
|
||||
class II {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link In.FOO}
|
||||
*/
|
||||
class II1 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class Uc {
|
||||
static final String FOO = "";
|
||||
void g() {
|
||||
System.out.println("" + In.FOO);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
|
||||
import static In.FOO;
|
||||
|
||||
interface In {
|
||||
int FOO = 0;
|
||||
}
|
||||
|
||||
class II {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link I#FOO}
|
||||
*/
|
||||
class II1 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class Uc {
|
||||
static final String FOO = "";
|
||||
void g() {
|
||||
System.out.println("" + In.FOO);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
|
||||
import static I.BAZZ;
|
||||
import static I.FOO;
|
||||
import static I1.BAZZ;
|
||||
|
||||
public class X {
|
||||
void bar() {
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
|
||||
import static I1.BAZZ;
|
||||
|
||||
public class X implements I {
|
||||
void bar() {
|
||||
System.out.println(FOO);
|
||||
System.out.println(BAZZ);
|
||||
}
|
||||
}
|
||||
|
||||
interface I {
|
||||
String FOO = "foo";
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
String BAZZ = "bazz";
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
|
||||
import static I1.BAZZ;
|
||||
import static II.FOO;
|
||||
|
||||
public class X {
|
||||
void bar() {
|
||||
System.out.println(FOO);
|
||||
System.out.println(BAZZ);
|
||||
}
|
||||
}
|
||||
|
||||
interface II extends I1{
|
||||
String FOO = "foo";
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
String BAZZ = "bazz";
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
|
||||
import static In.FOO;
|
||||
|
||||
interface In {
|
||||
int FOO = 0;
|
||||
}
|
||||
|
||||
class II {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class II1 {
|
||||
int FOO = 9;
|
||||
public static void main(String[] args) {
|
||||
System.out.println(In.FOO);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
interface I<caret>n {
|
||||
int FOO = 0;
|
||||
}
|
||||
|
||||
class II implements In {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class II1 implements In {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(II1.FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class Uc {
|
||||
static final String FOO = "";
|
||||
void g() {
|
||||
System.out.println("" + II.FOO);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
interface I<caret>n {
|
||||
int FOO = 0;
|
||||
}
|
||||
|
||||
class II implements In {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link In.FOO}
|
||||
*/
|
||||
class II1 implements In {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(II1.FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class Uc {
|
||||
static final String FOO = "";
|
||||
void g() {
|
||||
System.out.println("" + II.FOO);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
|
||||
interface I<caret>n {
|
||||
int FOO = 0;
|
||||
}
|
||||
|
||||
class II implements In {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link I#FOO}
|
||||
*/
|
||||
class II1 implements In {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(II1.FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class Uc {
|
||||
static final String FOO = "";
|
||||
void g() {
|
||||
System.out.println("" + II.FOO);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
public class X implements I {
|
||||
void bar() {
|
||||
System.out.println(FOO);
|
||||
System.out.println(BAZZ);
|
||||
}
|
||||
}
|
||||
|
||||
interface I extends I1{
|
||||
String FOO = "foo";
|
||||
}
|
||||
|
||||
interface I<caret>1 {
|
||||
String BAZZ = "bazz";
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
public class X implements II {
|
||||
void bar() {
|
||||
System.out.println(FOO);
|
||||
System.out.println(BAZZ);
|
||||
}
|
||||
}
|
||||
|
||||
interface I<caret>I extends I1{
|
||||
String FOO = "foo";
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
String BAZZ = "bazz";
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace Implements with Static Import" "true"
|
||||
interface I<caret>n {
|
||||
int FOO = 0;
|
||||
}
|
||||
|
||||
class II implements In {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class II1 implements In {
|
||||
int FOO = 9;
|
||||
public static void main(String[] args) {
|
||||
System.out.println(In.FOO);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: mike
|
||||
* Date: Aug 22, 2002
|
||||
* Time: 2:58:42 PM
|
||||
* To change template for new class use
|
||||
* Code Style | Class Templates options (Tools | IDE Options).
|
||||
*/
|
||||
package com.intellij.codeInsight.intention;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
|
||||
|
||||
public class ConvertToBasicLatinTest extends JavaCodeInsightFixtureTestCase {
|
||||
|
||||
private String myIntention;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myIntention = CodeInsightBundle.message("intention.convert.to.basic.latin");
|
||||
}
|
||||
|
||||
public void testConvertCharLiteral() throws Exception {
|
||||
CodeInsightTestUtil.doIntentionTest(myFixture, myIntention, "CharLiteral.java", "CharLiteral_after.java");
|
||||
}
|
||||
|
||||
public void testConvertStringLiteral() throws Exception {
|
||||
CodeInsightTestUtil.doIntentionTest(myFixture, myIntention, "StringLiteral.java", "StringLiteral_after.java");
|
||||
}
|
||||
|
||||
public void testConvertPlainComment() throws Exception {
|
||||
CodeInsightTestUtil.doIntentionTest(myFixture, myIntention, "PlainComment.java", "PlainComment_after.java");
|
||||
}
|
||||
|
||||
public void testConvertDocComment() throws Exception {
|
||||
CodeInsightTestUtil.doIntentionTest(myFixture, myIntention, "DocComment.java", "DocComment_after.java");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/codeInsight/convertToBasicLatin/";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,9 +43,9 @@ public class DependencyScopeTest extends ModuleTestCase {
|
||||
final VirtualFile[] productionCompilationClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES);
|
||||
assertEquals(0, productionCompilationClasspath.length);
|
||||
|
||||
final PathsList pathsList = ProjectRootsTraversing.collectRoots(moduleA, ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE);
|
||||
final PathsList pathsList = OrderEnumerator.orderEntries(moduleA).recursively().getPathsList();
|
||||
assertEquals(1, pathsList.getPathList().size());
|
||||
final PathsList pathsListWithoutTests = ProjectRootsTraversing.collectRoots(moduleA, ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS);
|
||||
final PathsList pathsListWithoutTests = OrderEnumerator.orderEntries(moduleA).productionOnly().recursively().getPathsList();
|
||||
assertEquals(0, pathsListWithoutTests.getPathList().size());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.intellij.roots;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathsList;
|
||||
|
||||
import static com.intellij.openapi.roots.OrderEnumerator.orderEntries;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class OrderEnumeratorTest extends ModuleRootManagerTestCase {
|
||||
|
||||
public void testLibrary() throws Exception {
|
||||
addLibraryDependency(myModule, createJDomLibrary());
|
||||
|
||||
assertClassRoots(orderEntries(myModule), getRtJar(), getJDomJar());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk(), getJDomJar());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().productionOnly().runtimeOnly(), getJDomJar());
|
||||
assertClassRoots(orderEntries(myModule).withoutLibraries(), getRtJar());
|
||||
assertSourceRoots(orderEntries(myModule), getJDomSources());
|
||||
}
|
||||
|
||||
public void testModuleSources() throws Exception {
|
||||
final VirtualFile srcRoot = addSourceRoot(myModule, false);
|
||||
final VirtualFile testRoot = addSourceRoot(myModule, true);
|
||||
final VirtualFile output = setModuleOutput(myModule, false);
|
||||
final VirtualFile testOutput = setModuleOutput(myModule, true);
|
||||
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk(), testOutput, output);
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().productionOnly(), output);
|
||||
assertSourceRoots(orderEntries(myModule), srcRoot, testRoot);
|
||||
assertSourceRoots(orderEntries(myModule).productionOnly(), srcRoot);
|
||||
}
|
||||
|
||||
public void testLibraryScope() throws Exception {
|
||||
addLibraryDependency(myModule, createJDomLibrary(), DependencyScope.RUNTIME, false);
|
||||
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk(), getJDomJar());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().exportedOnly());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().compileOnly());
|
||||
}
|
||||
|
||||
public void testModuleDependency() throws Exception {
|
||||
final Module dep = createModule("dep");
|
||||
final VirtualFile srcRoot = addSourceRoot(dep, false);
|
||||
final VirtualFile testRoot = addSourceRoot(dep, true);
|
||||
final VirtualFile output = setModuleOutput(dep, false);
|
||||
final VirtualFile testOutput = setModuleOutput(dep, true);
|
||||
addLibraryDependency(dep, createJDomLibrary(), DependencyScope.COMPILE, true);
|
||||
addModuleDependency(myModule, dep, DependencyScope.COMPILE, true);
|
||||
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk(), testOutput, output);
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().recursively(), testOutput, output, getJDomJar());
|
||||
assertSourceRoots(orderEntries(myModule), srcRoot, testRoot);
|
||||
assertSourceRoots(orderEntries(myModule).recursively(), srcRoot, testRoot, getJDomSources());
|
||||
}
|
||||
|
||||
public void testModuleDependencyScope() throws Exception {
|
||||
final Module dep = createModule("dep");
|
||||
addLibraryDependency(dep, createJDomLibrary(), DependencyScope.COMPILE, true);
|
||||
addModuleDependency(myModule, dep, DependencyScope.TEST, true);
|
||||
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().recursively(), getJDomJar());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().exportedOnly().recursively(), getJDomJar());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().productionOnly().recursively());
|
||||
|
||||
assertClassRoots(ProjectRootManager.getInstance(myProject).orderEntries().withoutSdk(), getJDomJar());
|
||||
assertClassRoots(ProjectRootManager.getInstance(myProject).orderEntries().withoutSdk().productionOnly(), getJDomJar());
|
||||
}
|
||||
|
||||
public void testNotExportedLibrary() throws Exception {
|
||||
final Module dep = createModule("dep");
|
||||
addLibraryDependency(dep, createJDomLibrary(), DependencyScope.COMPILE, false);
|
||||
addLibraryDependency(myModule, createAsmLibrary(), DependencyScope.COMPILE, false);
|
||||
addModuleDependency(myModule, dep, DependencyScope.COMPILE, false);
|
||||
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk(), getAsmJar());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().recursively(), getAsmJar(), getJDomJar());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().recursively().exportedOnly(), getAsmJar());
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().exportedOnly().recursively());
|
||||
}
|
||||
|
||||
private static void assertClassRoots(final OrderEnumerator enumerator, VirtualFile... files) {
|
||||
assertRoots(enumerator.getPathsList(), files);
|
||||
}
|
||||
|
||||
private static void assertSourceRoots(final OrderEnumerator enumerator, VirtualFile... files) {
|
||||
final PathsList result = new PathsList();
|
||||
enumerator.collectSourcePaths(result);
|
||||
assertRoots(result, files);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.roots;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.roots.ProjectClasspathTraversing;
|
||||
import com.intellij.openapi.roots.ProjectRootsTraversing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathsList;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
@SuppressWarnings({"deprecation"})
|
||||
public class ProjectClasspathTraversingTest extends ModuleRootManagerTestCase {
|
||||
public void testLibrary() throws Exception {
|
||||
addLibraryDependency(myModule, createJDomLibrary());
|
||||
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH, getRtJar(), getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASS_RECURSIVE_WO_JDK, getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE, getRtJar(), getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_JDK_AND_TESTS, getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS, getRtJar(), getJDomJar());
|
||||
}
|
||||
|
||||
public void testModuleOutput() throws Exception {
|
||||
addSourceRoot(myModule, false);
|
||||
final VirtualFile output = setModuleOutput(myModule, false);
|
||||
final VirtualFile testOutput = setModuleOutput(myModule, true);
|
||||
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH, getRtJar(), testOutput, output);
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASS_RECURSIVE_WO_JDK, testOutput, output);
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE, getRtJar(), testOutput, output);
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_JDK_AND_TESTS, output);
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS, getRtJar(), output);
|
||||
}
|
||||
|
||||
public void testLibraryScope() throws Exception {
|
||||
addLibraryDependency(myModule, createJDomLibrary(), DependencyScope.TEST, true);
|
||||
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH, getRtJar(), getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASS_RECURSIVE_WO_JDK, getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE, getRtJar(), getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_JDK_AND_TESTS);
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS, getRtJar());
|
||||
}
|
||||
|
||||
public void testModuleDependency() throws Exception {
|
||||
final Module dep = createModule("dep");
|
||||
final VirtualFile output = setModuleOutput(dep, false);
|
||||
final VirtualFile testOutput = setModuleOutput(dep, true);
|
||||
addLibraryDependency(dep, createJDomLibrary());
|
||||
addModuleDependency(myModule, dep);
|
||||
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH, getRtJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASS_RECURSIVE_WO_JDK, testOutput, output, getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE, getRtJar(), testOutput, output, getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_JDK_AND_TESTS, output, getJDomJar());
|
||||
doTest(ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS, getRtJar(), output, getJDomJar());
|
||||
}
|
||||
|
||||
private void doTest(ProjectRootsTraversing.RootTraversePolicy policy, VirtualFile... roots) {
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, policy), roots);
|
||||
assertRoots(collectByOrderEnumerator(policy), roots);
|
||||
}
|
||||
|
||||
private PathsList collectByOrderEnumerator(ProjectRootsTraversing.RootTraversePolicy policy) {
|
||||
if (policy == ProjectClasspathTraversing.FULL_CLASSPATH) {
|
||||
return OrderEnumerator.orderEntries(myModule).withoutDepModules().getPathsList();
|
||||
}
|
||||
if (policy == ProjectClasspathTraversing.FULL_CLASS_RECURSIVE_WO_JDK) {
|
||||
return OrderEnumerator.orderEntries(myModule).withoutSdk().recursively().getPathsList();
|
||||
}
|
||||
if (policy == ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE) {
|
||||
return OrderEnumerator.orderEntries(myModule).recursively().getPathsList();
|
||||
}
|
||||
if (policy == ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_JDK_AND_TESTS) {
|
||||
return OrderEnumerator.orderEntries(myModule).withoutSdk().productionOnly().recursively().getPathsList();
|
||||
}
|
||||
if (policy == ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS) {
|
||||
return OrderEnumerator.orderEntries(myModule).productionOnly().recursively().getPathsList();
|
||||
}
|
||||
throw new AssertionError(policy);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,38 @@
|
||||
package com.intellij.roots;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.roots.ProjectRootsTraversing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathsList;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
@SuppressWarnings({"deprecation"})
|
||||
public class ProjectRootsTraversingTest extends ModuleRootManagerTestCase {
|
||||
|
||||
public void testLibrary() throws Exception {
|
||||
addLibraryDependency(myModule, createJDomLibrary());
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, ProjectRootsTraversing.LIBRARIES_AND_JDK),
|
||||
getRtJar(), getJDomJar());
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, ProjectRootsTraversing.PROJECT_LIBRARIES),
|
||||
getJDomJar());
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, ProjectRootsTraversing.PROJECT_SOURCES));
|
||||
doTest(ProjectRootsTraversing.LIBRARIES_AND_JDK, getRtJar(), getJDomJar());
|
||||
doTest(ProjectRootsTraversing.PROJECT_LIBRARIES, getJDomJar());
|
||||
doTest(ProjectRootsTraversing.PROJECT_SOURCES);
|
||||
}
|
||||
|
||||
public void testModuleSources() throws Exception {
|
||||
final VirtualFile srcRoot = addSourceRoot(myModule, false);
|
||||
final VirtualFile testRoot = addSourceRoot(myModule, true);
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, ProjectRootsTraversing.LIBRARIES_AND_JDK),
|
||||
getRtJar());
|
||||
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, ProjectRootsTraversing.PROJECT_SOURCES),
|
||||
srcRoot, testRoot);
|
||||
doTest(ProjectRootsTraversing.LIBRARIES_AND_JDK, getRtJar());
|
||||
doTest(ProjectRootsTraversing.PROJECT_SOURCES, srcRoot, testRoot);
|
||||
}
|
||||
|
||||
|
||||
public void testModuleOutput() throws Exception {
|
||||
setModuleOutput(myModule, false);
|
||||
setModuleOutput(myModule, true);
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, ProjectRootsTraversing.LIBRARIES_AND_JDK),
|
||||
getRtJar());
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, ProjectRootsTraversing.PROJECT_SOURCES));
|
||||
|
||||
doTest(ProjectRootsTraversing.LIBRARIES_AND_JDK, getRtJar());
|
||||
doTest(ProjectRootsTraversing.PROJECT_SOURCES);
|
||||
}
|
||||
|
||||
public void testModuleDependency() throws Exception {
|
||||
@@ -44,8 +43,26 @@ public class ProjectRootsTraversingTest extends ModuleRootManagerTestCase {
|
||||
addSourceRoot(dep, true);
|
||||
addLibraryDependency(dep, createJDomLibrary());
|
||||
addModuleDependency(myModule, dep);
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, ProjectRootsTraversing.PROJECT_LIBRARIES),
|
||||
getJDomJar());
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, ProjectRootsTraversing.PROJECT_SOURCES));
|
||||
|
||||
doTest(ProjectRootsTraversing.PROJECT_LIBRARIES, getJDomJar());
|
||||
doTest(ProjectRootsTraversing.PROJECT_SOURCES);
|
||||
}
|
||||
|
||||
private void doTest(final ProjectRootsTraversing.RootTraversePolicy policy, VirtualFile... roots) {
|
||||
assertRoots(ProjectRootsTraversing.collectRoots(myModule, policy), roots);
|
||||
assertRoots(collectByOrderEnumerator(policy), roots);
|
||||
}
|
||||
|
||||
private PathsList collectByOrderEnumerator(ProjectRootsTraversing.RootTraversePolicy policy) {
|
||||
if (policy == ProjectRootsTraversing.LIBRARIES_AND_JDK) {
|
||||
return OrderEnumerator.orderEntries(myModule).withoutDepModules().withoutThisModuleContent().getPathsList();
|
||||
}
|
||||
if (policy == ProjectRootsTraversing.PROJECT_SOURCES) {
|
||||
return OrderEnumerator.orderEntries(myModule).withoutSdk().withoutLibraries().withoutDepModules().getSourcePathsList();
|
||||
}
|
||||
if (policy == ProjectRootsTraversing.PROJECT_LIBRARIES) {
|
||||
return OrderEnumerator.orderEntries(myModule).withoutSdk().withoutThisModuleContent().recursively().getPathsList();
|
||||
}
|
||||
throw new AssertionError(policy);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -50,11 +50,7 @@ public class PsiClassPattern extends PsiMemberPattern<PsiClass, PsiClassPattern>
|
||||
public PsiClassPattern inheritorOf(final boolean strict, final String className) {
|
||||
return with(new PatternCondition<PsiClass>("inheritorOf") {
|
||||
public boolean accepts(@NotNull PsiClass psiClass, final ProcessingContext context) {
|
||||
final PsiClass baseClass = JavaPsiFacade.getInstance(psiClass.getProject()).findClass(className, psiClass.getResolveScope());
|
||||
if (baseClass == null) {
|
||||
return false;
|
||||
}
|
||||
return strict ? psiClass.isInheritor(baseClass, true) : InheritanceUtil.isInheritorOrSelf(psiClass, baseClass, true);
|
||||
return InheritanceUtil.isInheritor(psiClass, strict, className);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -66,27 +62,30 @@ public class PsiClassPattern extends PsiMemberPattern<PsiClass, PsiClassPattern>
|
||||
}
|
||||
});}
|
||||
|
||||
public PsiClassPattern withMember(final ElementPattern<? extends PsiMember> memberPattern) {
|
||||
return with(new PatternCondition<PsiClass>("withMember") {
|
||||
public PsiClassPattern withMethod(final boolean checkDeep, final ElementPattern<? extends PsiMethod> memberPattern) {
|
||||
return with(new PatternCondition<PsiClass>("withMethod") {
|
||||
public boolean accepts(@NotNull final PsiClass psiClass, final ProcessingContext context) {
|
||||
for (PsiMethod method : psiClass.getMethods()) {
|
||||
for (PsiMethod method : (checkDeep ? psiClass.getAllMethods() : psiClass.getMethods())) {
|
||||
if (memberPattern.accepts(method, context)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (PsiField field : psiClass.getFields()) {
|
||||
if (memberPattern.accepts(field, context)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (PsiClass inner : psiClass.getInnerClasses()) {
|
||||
if (memberPattern.accepts(inner, context)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});}
|
||||
});
|
||||
}
|
||||
public PsiClassPattern withField(final boolean checkDeep, final ElementPattern<? extends PsiField> memberPattern) {
|
||||
return with(new PatternCondition<PsiClass>("withField") {
|
||||
public boolean accepts(@NotNull final PsiClass psiClass, final ProcessingContext context) {
|
||||
for (PsiField field : (checkDeep ? psiClass.getAllFields() : psiClass.getFields())) {
|
||||
if (memberPattern.accepts(field, context)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public PsiClassPattern nonAnnotationType() {
|
||||
return with(new PatternCondition<PsiClass>("nonAnnotationType") {
|
||||
@@ -103,6 +102,13 @@ public class PsiClassPattern extends PsiMemberPattern<PsiClass, PsiClassPattern>
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public PsiClassPattern withQualifiedName(@NonNls @NotNull final ElementPattern<String> qname) {
|
||||
return with(new PatternCondition<PsiClass>("withQualifiedName") {
|
||||
public boolean accepts(@NotNull final PsiClass psiClass, final ProcessingContext context) {
|
||||
return qname.accepts(psiClass.getQualifiedName(), context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package com.intellij.psi.util;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.Processor;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -81,18 +78,20 @@ public class InheritanceUtil {
|
||||
}
|
||||
|
||||
public static boolean isInheritor(@Nullable PsiClass psiClass, final String baseClassName) {
|
||||
return isInheritor(psiClass, false, baseClassName);
|
||||
}
|
||||
|
||||
public static boolean isInheritor(@Nullable PsiClass psiClass, final boolean strict, final String baseClassName) {
|
||||
if (psiClass == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !processSupers(psiClass, true, new Processor<PsiClass>() {
|
||||
public boolean process(PsiClass psiClass) {
|
||||
if (baseClassName.equals(psiClass.getQualifiedName())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
final PsiClass base = JavaPsiFacade.getInstance(psiClass.getProject()).findClass(baseClassName, psiClass.getResolveScope());
|
||||
if (base == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strict ? psiClass.isInheritor(base, true) : isInheritorOrSelf(psiClass, base, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Binary file not shown.
@@ -60,7 +60,10 @@ public class ConfigurationContext {
|
||||
final ConfigurationContext context = new ConfigurationContext(dataContext);
|
||||
final DataManager dataManager = DataManager.getInstance();
|
||||
ConfigurationContext sharedContext = dataManager.loadFromDataContext(dataContext, SHARED_CONTEXT);
|
||||
if (sharedContext == null || !Comparing.equal(sharedContext.getLocation().getPsiElement(), context.getLocation().getPsiElement())) {
|
||||
if (sharedContext == null ||
|
||||
sharedContext.getLocation() == null ||
|
||||
context.getLocation() == null ||
|
||||
!Comparing.equal(sharedContext.getLocation().getPsiElement(), context.getLocation().getPsiElement())) {
|
||||
sharedContext = context;
|
||||
dataManager.saveInDataContext(dataContext, SHARED_CONTEXT, sharedContext);
|
||||
}
|
||||
|
||||
@@ -148,6 +148,12 @@ public interface ModuleRootModel {
|
||||
*/
|
||||
<R> R processOrder(RootPolicy<R> policy, R initialValue);
|
||||
|
||||
/**
|
||||
* @since 10
|
||||
*/
|
||||
@NotNull
|
||||
OrderEnumerator orderEntries();
|
||||
|
||||
/**
|
||||
* Returns list of module names <i>this module</i> depends on.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathsList;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class OrderEnumerator {
|
||||
public abstract OrderEnumerator productionOnly();
|
||||
|
||||
public abstract OrderEnumerator compileOnly();
|
||||
public abstract OrderEnumerator runtimeOnly();
|
||||
|
||||
|
||||
public abstract OrderEnumerator withoutSdk();
|
||||
public abstract OrderEnumerator withoutLibraries();
|
||||
public abstract OrderEnumerator withoutDepModules();
|
||||
public abstract OrderEnumerator withoutThisModuleContent();
|
||||
|
||||
public abstract OrderEnumerator recursively();
|
||||
public abstract OrderEnumerator exportedOnly();
|
||||
|
||||
public abstract OrderEnumerator satisfying(Condition<OrderEntry> condition);
|
||||
|
||||
|
||||
public abstract Collection<VirtualFile> getClassesRoots();
|
||||
public abstract Collection<VirtualFile> getSourceRoots();
|
||||
|
||||
public abstract PathsList getPathsList();
|
||||
public abstract void collectPaths(PathsList list);
|
||||
public abstract PathsList getSourcePathsList();
|
||||
public abstract void collectSourcePaths(PathsList list);
|
||||
|
||||
public abstract void forEach(Processor<OrderEntry> processor);
|
||||
public abstract void forEachLibrary(Processor<Library> processor);
|
||||
|
||||
public static OrderEnumerator orderEntries(@NotNull Module module) {
|
||||
return ModuleRootManager.getInstance(module).orderEntries();
|
||||
}
|
||||
|
||||
public static OrderEnumerator orderEntries(@NotNull Project project) {
|
||||
return ProjectRootManager.getInstance(project).orderEntries();
|
||||
}
|
||||
}
|
||||
@@ -40,26 +40,44 @@ public class OrderRootType {
|
||||
|
||||
/**
|
||||
* Runtime classpath.
|
||||
* Includes:
|
||||
* <li> production and test output for modules
|
||||
* <li> classes roots for libraries unless scope is 'provided'
|
||||
* <li> recursively for module dependencies with scope != 'provided'
|
||||
*/
|
||||
public static final OrderRootType CLASSES_AND_OUTPUT = new OrderRootType("CLASSES_AND_OUTPUT");
|
||||
|
||||
/**
|
||||
* Classpath for compilation
|
||||
* Classpath for compilation.
|
||||
* Includes:
|
||||
* <li> production and test output for modules
|
||||
* <li> classes roots for libraries
|
||||
* <li> recursively for module dependencies: only exported items
|
||||
*/
|
||||
public static final OrderRootType COMPILATION_CLASSES = new OrderRootType("COMPILATION_CLASSES");
|
||||
|
||||
/**
|
||||
* Classpath for compilation without tests
|
||||
* Classpath for compilation without tests.
|
||||
* Includes:
|
||||
* <li> production output for modules
|
||||
* <li> classes roots for libraries with scope suitable for production compile
|
||||
* <li> recursively for module dependencies with scope suitable for production compile: only exported items
|
||||
*/
|
||||
public static final OrderRootType PRODUCTION_COMPILATION_CLASSES = new OrderRootType("PRODUCTION_COMPILATION_CLASSES");
|
||||
|
||||
/**
|
||||
* Classpath without output directories for this module.
|
||||
* Includes:
|
||||
* <li> classes roots for libraries
|
||||
* <li> recursively for module dependencies: only exported items
|
||||
*/
|
||||
public static final OrderRootType CLASSES = new PersistentOrderRootType("CLASSES", "classPath", null, "classPathEntry");
|
||||
|
||||
/**
|
||||
* Sources.
|
||||
* Includes:
|
||||
* <li> production and test source roots for modules
|
||||
* <li> recursively for module dependencies: only exported items
|
||||
*/
|
||||
public static final OrderRootType SOURCES = new PersistentOrderRootType("SOURCES", "sourcePath", null, "sourcePathEntry");
|
||||
|
||||
|
||||
@@ -21,20 +21,42 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.util.SmartList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ProjectClasspathTraversing {
|
||||
public static final AddModuleOutput ALL_OUTPUTS = new AddModuleOutput(true);
|
||||
public static final AddModuleOutput GENERAL_OUTPUT = new AddModuleOutput(false);
|
||||
|
||||
/**
|
||||
* @deprecated use <code>OrderEnumerator.orderEntries().withoutDepModules().getPathsList()</code> instead
|
||||
*/
|
||||
public static final ProjectRootsTraversing.RootTraversePolicy FULL_CLASSPATH =
|
||||
new ProjectRootsTraversing.RootTraversePolicy(ALL_OUTPUTS, ProjectRootsTraversing.RootTraversePolicy.ADD_CLASSES, ProjectRootsTraversing.RootTraversePolicy.ADD_CLASSES, null);
|
||||
|
||||
/**
|
||||
* @deprecated use <code>OrderEnumerator.orderEntries(module).withoutSdk().recursively().getPathsList()</code> or
|
||||
* <code>OrderEnumerator.orderEntries(project).withoutSdk().getPathsList()</code> instead
|
||||
*/
|
||||
public static final ProjectRootsTraversing.RootTraversePolicy FULL_CLASS_RECURSIVE_WO_JDK =
|
||||
new ProjectRootsTraversing.RootTraversePolicy(ALL_OUTPUTS, null, ProjectRootsTraversing.RootTraversePolicy.ADD_CLASSES, ProjectRootsTraversing.RootTraversePolicy.RECURSIVE);
|
||||
|
||||
/**
|
||||
* @deprecated use <code>OrderEnumerator.orderEntries(module).recursively().getPathsList()</code> or
|
||||
* <code>OrderEnumerator.orderEntries(project).getPathsList()</code> instead
|
||||
*/
|
||||
public static final ProjectRootsTraversing.RootTraversePolicy FULL_CLASSPATH_RECURSIVE =
|
||||
new ProjectRootsTraversing.RootTraversePolicy(ALL_OUTPUTS, ProjectRootsTraversing.RootTraversePolicy.ADD_CLASSES, ProjectRootsTraversing.RootTraversePolicy.ADD_CLASSES, ProjectRootsTraversing.RootTraversePolicy.RECURSIVE);
|
||||
|
||||
/**
|
||||
* @deprecated use <code>OrderEnumerator.orderEntries(module).withoutSdk().productionOnly().recursively().getPathsList()</code>
|
||||
* or <code>OrderEnumerator.orderEntries(project).withoutSdk().productionOnly().getPathsList()</code> instead
|
||||
*/
|
||||
public static final ProjectRootsTraversing.RootTraversePolicy FULL_CLASSPATH_WITHOUT_JDK_AND_TESTS =
|
||||
new ProjectRootsTraversing.RootTraversePolicy(GENERAL_OUTPUT, null, ProjectRootsTraversing.RootTraversePolicy.ADD_CLASSES_WITHOUT_TESTS, ProjectRootsTraversing.RootTraversePolicy.RECURSIVE_WITHOUT_TESTS);
|
||||
|
||||
/**
|
||||
* @deprecated use <code>OrderEnumerator.orderEntries(module).productionOnly().recursively().getPathsList()</code>
|
||||
* or <code>OrderEnumerator.orderEntries(project).productionOnly().getPathsList()</code> instead
|
||||
*/
|
||||
public static final ProjectRootsTraversing.RootTraversePolicy FULL_CLASSPATH_WITHOUT_TESTS =
|
||||
new ProjectRootsTraversing.RootTraversePolicy(GENERAL_OUTPUT, ProjectRootsTraversing.RootTraversePolicy.ADD_CLASSES_WITHOUT_TESTS, ProjectRootsTraversing.RootTraversePolicy.ADD_CLASSES_WITHOUT_TESTS, ProjectRootsTraversing.RootTraversePolicy.RECURSIVE_WITHOUT_TESTS);
|
||||
|
||||
|
||||
@@ -73,6 +73,8 @@ public abstract class ProjectRootManager implements ModificationTracker {
|
||||
|
||||
public abstract VirtualFile[] getFilesFromAllModules(OrderRootType type);
|
||||
|
||||
public abstract OrderEnumerator orderEntries();
|
||||
|
||||
/**
|
||||
* Unlike getContentRoots(), this includes the project base dir. Is this really necessary?
|
||||
* TODO: remove this method?
|
||||
|
||||
@@ -30,13 +30,24 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ProjectRootsTraversing {
|
||||
|
||||
/**
|
||||
* @deprecated use <code>OrderEnumerator.orderEntries(module).withoutDepModules().withoutThisModuleContent().getPathsList()</code>
|
||||
* or <code>OrderEnumerator.orderEntries(project).withoutThisModuleContent().getPathsList()</code> instead
|
||||
*/
|
||||
public static final RootTraversePolicy LIBRARIES_AND_JDK =
|
||||
new RootTraversePolicy(null, RootTraversePolicy.ADD_CLASSES, RootTraversePolicy.ADD_CLASSES, null);
|
||||
|
||||
/**
|
||||
* @deprecated use <code>OrderEnumerator.orderEntries(module).withoutSdk().withoutLibraries().withoutDepModules().getSourcePathsList()</code>
|
||||
* or <code>OrderEnumerator.orderEntries(project).withoutSdk().withoutLibraries().getSourcePathsList()</code> instead
|
||||
*/
|
||||
public static final RootTraversePolicy PROJECT_SOURCES =
|
||||
new RootTraversePolicy(RootTraversePolicy.SOURCES, null, null, null);
|
||||
|
||||
/**
|
||||
* @deprecated use <code>OrderEnumerator.orderEntries().withoutSdk().withoutThisModuleContent().recursively().getPathsList()</code>
|
||||
* or <code>OrderEnumerator.orderEntries().withoutSdk().withoutThisModuleContent().getPathsList()</code> instead
|
||||
*/
|
||||
public static final RootTraversePolicy PROJECT_LIBRARIES =
|
||||
new RootTraversePolicy(null, null, RootTraversePolicy.ADD_CLASSES, RootTraversePolicy.RECURSIVE);
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ public class PathsList {
|
||||
add(PathUtil.getCanonicalPath(file.getAbsolutePath()).replace('/', File.separatorChar));
|
||||
}
|
||||
|
||||
public void addVirtualFiles(List<VirtualFile> files) {
|
||||
public void addVirtualFiles(Collection<VirtualFile> files) {
|
||||
for (final VirtualFile file : files) {
|
||||
add(file);
|
||||
}
|
||||
|
||||
+2
-2
@@ -338,8 +338,8 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
protected void run(Result result) throws Throwable {
|
||||
String uniqueText = _uniqueText;
|
||||
|
||||
if (item.getObject() instanceof DeferredUserLookupValue && item instanceof LookupItem) {
|
||||
if (!((DeferredUserLookupValue)item.getObject()).handleUserSelection((LookupItem)item, context.project)) {
|
||||
if (item.getObject() instanceof DeferredUserLookupValue && item.as(LookupItem.class) != null) {
|
||||
if (!((DeferredUserLookupValue)item.getObject()).handleUserSelection(item.as(LookupItem.class), context.project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -753,7 +753,7 @@ public class DocumentationManager {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static DocumentationProvider getProviderFromElement(@Nullable PsiElement element, @Nullable PsiElement originalElement) {
|
||||
public static DocumentationProvider getProviderFromElement(@Nullable PsiElement element, @Nullable PsiElement originalElement) {
|
||||
if (element != null && !element.isValid()) {
|
||||
element = null;
|
||||
}
|
||||
|
||||
+12
-2
@@ -149,13 +149,23 @@ public final class IntentionActionMetaData {
|
||||
return urls.isEmpty() ? null : urls.toArray(new TextDescriptor[urls.size()]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static URL getIntentionDescriptionDirURL(ClassLoader aClassLoader, String intentionFolderName) {
|
||||
final URL pageURL = aClassLoader.getResource(INTENTION_DESCRIPTION_FOLDER + "/" + intentionFolderName);
|
||||
final URL pageURL = aClassLoader.getResource(INTENTION_DESCRIPTION_FOLDER + "/" + intentionFolderName+"/"+ DESCRIPTION_FILE_NAME);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Path:"+"intentionDescriptions/" + intentionFolderName);
|
||||
LOG.debug("URL:"+pageURL);
|
||||
}
|
||||
return pageURL;
|
||||
if (pageURL != null) {
|
||||
try {
|
||||
final String url = pageURL.toExternalForm();
|
||||
return new URL(url.substring(0, url.lastIndexOf('/')));
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private URL getDirURL() {
|
||||
|
||||
@@ -223,8 +223,8 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String generateInfo(PsiElement element) {
|
||||
final DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(element);
|
||||
private static String generateInfo(PsiElement element, PsiElement atPointer) {
|
||||
final DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(element, atPointer);
|
||||
|
||||
String info = documentationProvider.getQuickNavigateInfo(element);
|
||||
if (info != null) {
|
||||
@@ -305,7 +305,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
|
||||
@Nullable
|
||||
public String getInfo() {
|
||||
try {
|
||||
return generateInfo(myTargetElement);
|
||||
return generateInfo(myTargetElement, myElementAtPointer);
|
||||
}
|
||||
catch (IndexNotReadyException e) {
|
||||
showDumbModeNotification(myTargetElement.getProject());
|
||||
|
||||
+14
-11
@@ -45,7 +45,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseRunConfigurationAction extends ActionGroup {
|
||||
private static final Logger LOG = Logger.getInstance("#" + BaseRunConfigurationAction.class.getName());
|
||||
protected static final Logger LOG = Logger.getInstance("#" + BaseRunConfigurationAction.class.getName());
|
||||
|
||||
protected BaseRunConfigurationAction(final String text, final String description, final Icon icon) {
|
||||
super(text, description, icon);
|
||||
@@ -175,12 +175,15 @@ public abstract class BaseRunConfigurationAction extends ActionGroup {
|
||||
public void update(final AnActionEvent event){
|
||||
final ConfigurationContext context = ConfigurationContext.getFromContext(event.getDataContext());
|
||||
final Presentation presentation = event.getPresentation();
|
||||
RunnerAndConfigurationSettings configuration;
|
||||
try {
|
||||
configuration = context.getConfiguration();
|
||||
}
|
||||
catch (IndexNotReadyException e) {
|
||||
configuration = null;
|
||||
final RunnerAndConfigurationSettings existing = context.findExisting();
|
||||
RunnerAndConfigurationSettings configuration = existing;
|
||||
if (configuration == null) {
|
||||
try {
|
||||
configuration = context.getConfiguration();
|
||||
}
|
||||
catch (IndexNotReadyException e) {
|
||||
configuration = null;
|
||||
}
|
||||
}
|
||||
if (configuration == null){
|
||||
presentation.setEnabled(false);
|
||||
@@ -189,13 +192,13 @@ public abstract class BaseRunConfigurationAction extends ActionGroup {
|
||||
else{
|
||||
presentation.setEnabled(true);
|
||||
presentation.setVisible(true);
|
||||
final String name = suggestRunActionName((LocatableConfiguration)configuration.getConfiguration());
|
||||
final List<RuntimeConfigurationProducer> producers = getEnabledProducers(context);
|
||||
if (!producers.isEmpty()) {
|
||||
//todo[nik,anna] it's dirty fix. Otherwise wrong configuration will be returned from context.getConfiguration()
|
||||
if (existing == null && !producers.isEmpty()) {
|
||||
//todo[nik,anna] it's dirty fix. Otherwise wrong configuration will be returned from context.getConfiguration()
|
||||
context.getConfiguration(producers.get(0));
|
||||
}
|
||||
updatePresentation(presentation, context.findExisting() != null || producers.size() <= 1 ? " " + name : "", context);
|
||||
final String name = suggestRunActionName((LocatableConfiguration)configuration.getConfiguration());
|
||||
updatePresentation(presentation, existing != null || producers.size() <= 1 ? " " + name : "", context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ProjectRootsTraversing;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
|
||||
public final class ModulePathMacro extends Macro {
|
||||
public String getName() {
|
||||
@@ -36,6 +36,6 @@ public final class ModulePathMacro extends Macro {
|
||||
if (module == null) {
|
||||
return null;
|
||||
}
|
||||
return ProjectRootsTraversing.collectRoots(module, ProjectRootsTraversing.PROJECT_SOURCES).getPathsString();
|
||||
return OrderEnumerator.orderEntries(module).withoutSdk().withoutLibraries().getSourcePathsList().getPathsString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootsTraversing;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
|
||||
public final class ProjectPathMacro extends Macro {
|
||||
public String getName() {
|
||||
@@ -34,6 +34,6 @@ public final class ProjectPathMacro extends Macro {
|
||||
public String expand(DataContext dataContext) {
|
||||
Project project = PlatformDataKeys.PROJECT.getData(dataContext);
|
||||
if (project == null) return null;
|
||||
return ProjectRootsTraversing.collectRoots(project, ProjectRootsTraversing.PROJECT_SOURCES).getPathsString();
|
||||
return OrderEnumerator.orderEntries(project).withoutSdk().withoutLibraries().getSourcePathsList().getPathsString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootsTraversing;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
|
||||
public final class SourcepathMacro extends Macro {
|
||||
public String getName() {
|
||||
@@ -34,6 +34,6 @@ public final class SourcepathMacro extends Macro {
|
||||
public String expand(DataContext dataContext) {
|
||||
Project project = PlatformDataKeys.PROJECT.getData(dataContext);
|
||||
if (project == null) return null;
|
||||
return ProjectRootsTraversing.collectRoots(project, ProjectRootsTraversing.PROJECT_SOURCES).getPathsString();
|
||||
return OrderEnumerator.orderEntries(project).withoutSdk().withoutLibraries().getSourcePathsList().getPathsString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,8 +398,8 @@ public class EditorWindow implements EditorEx, UserDataHolderEx {
|
||||
myDelegate.setBackgroundColor(color);
|
||||
}
|
||||
|
||||
public Color getBackroundColor() {
|
||||
return myDelegate.getBackroundColor();
|
||||
public Color getBackgroundColor() {
|
||||
return myDelegate.getBackgroundColor();
|
||||
}
|
||||
|
||||
public int getMaxWidthInRange(final int startOffset, final int endOffset) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.util.Processor;
|
||||
import gnu.trove.THashSet;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ModuleOrderEnumerator extends OrderEnumeratorBase {
|
||||
private final RootModelImpl myRootModel;
|
||||
|
||||
public ModuleOrderEnumerator(RootModelImpl rootModel) {
|
||||
myRootModel = rootModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Processor<OrderEntry> processor) {
|
||||
processEntries(myRootModel, processor, myRecursively ? new THashSet<Module>() : null, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -204,9 +203,9 @@ public class ModuleRootManagerImpl extends ModuleRootManager implements ModuleCo
|
||||
Set<VirtualFilePointer> cachedFiles = myCachedFiles.get(type);
|
||||
if (cachedFiles == null) {
|
||||
cachedFiles = new LinkedHashSet<VirtualFilePointer>();
|
||||
final Iterator orderIterator = myRootModel.getOrderIterator();
|
||||
final Iterator<OrderEntry> orderIterator = myRootModel.getOrderIterator();
|
||||
while (orderIterator.hasNext()) {
|
||||
OrderEntry entry = (OrderEntry)orderIterator.next();
|
||||
OrderEntry entry = orderIterator.next();
|
||||
final String [] urls;
|
||||
if (entry instanceof ModuleOrderEntryImpl) {
|
||||
List<String> list = ((ModuleOrderEntryImpl)entry).getUrls(type, processed);
|
||||
@@ -358,13 +357,16 @@ public class ModuleRootManagerImpl extends ModuleRootManager implements ModuleCo
|
||||
return myRootModel.processOrder(policy, initialValue);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public OrderEnumerator orderEntries() {
|
||||
return myRootModel.orderEntries();
|
||||
}
|
||||
|
||||
List<String> getUrlsForOtherModules(OrderRootType rootType, Set<Module> processed) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
if (OrderRootType.SOURCES.equals(rootType) || OrderRootType.COMPILATION_CLASSES.equals(rootType) || OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(rootType)) {
|
||||
addExportedUrls(myRootModel, rootType, result, processed);
|
||||
return result;
|
||||
}
|
||||
else if (OrderRootType.CLASSES.equals(rootType)) {
|
||||
if (OrderRootType.SOURCES.equals(rootType) || OrderRootType.COMPILATION_CLASSES.equals(rootType)
|
||||
|| OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(rootType) || OrderRootType.CLASSES.equals(rootType)) {
|
||||
addExportedUrls(myRootModel, rootType, result, processed);
|
||||
return result;
|
||||
}
|
||||
@@ -396,10 +398,8 @@ public class ModuleRootManagerImpl extends ModuleRootManager implements ModuleCo
|
||||
if (filePointers == null) {
|
||||
filePointers = new LinkedHashSet<VirtualFilePointer>();
|
||||
List<String> result = new ArrayList<String>();
|
||||
if (OrderRootType.SOURCES.equals(rootType) || OrderRootType.COMPILATION_CLASSES.equals(rootType) || OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(rootType)) {
|
||||
addExportedUrls(myRootModel, rootType, result, processed);
|
||||
}
|
||||
else if (OrderRootType.CLASSES.equals(rootType)) {
|
||||
if (OrderRootType.SOURCES.equals(rootType) || OrderRootType.COMPILATION_CLASSES.equals(rootType)
|
||||
|| OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(rootType) || OrderRootType.CLASSES.equals(rootType)) {
|
||||
addExportedUrls(myRootModel, rootType, result, processed);
|
||||
}
|
||||
else if (OrderRootType.CLASSES_AND_OUTPUT.equals(rootType)) {
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathsList;
|
||||
import com.intellij.util.Processor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class OrderEnumeratorBase extends OrderEnumerator {
|
||||
private boolean myProductionOnly;
|
||||
private boolean myCompileOnly;
|
||||
private boolean myRuntimeOnly;
|
||||
private boolean myWithoutJdk;
|
||||
private boolean myWithoutLibraries;
|
||||
protected boolean myWithoutDepModules;
|
||||
private boolean myWithoutThisModuleContent;
|
||||
protected boolean myRecursively;
|
||||
private boolean myRecursivelyExportedOnly;
|
||||
private boolean myExportedOnly;
|
||||
private Condition<OrderEntry> myCondition;
|
||||
|
||||
@Override
|
||||
public OrderEnumerator productionOnly() {
|
||||
myProductionOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator compileOnly() {
|
||||
myCompileOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator runtimeOnly() {
|
||||
myRuntimeOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator withoutSdk() {
|
||||
myWithoutJdk = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator withoutLibraries() {
|
||||
myWithoutLibraries = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator withoutDepModules() {
|
||||
myWithoutDepModules = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator withoutThisModuleContent() {
|
||||
myWithoutThisModuleContent = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator recursively() {
|
||||
myRecursively = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator exportedOnly() {
|
||||
if (myRecursively) {
|
||||
myRecursivelyExportedOnly = true;
|
||||
}
|
||||
else {
|
||||
myExportedOnly = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator satisfying(Condition<OrderEntry> condition) {
|
||||
myCondition = condition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathsList getPathsList() {
|
||||
final PathsList list = new PathsList();
|
||||
collectPaths(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectPaths(final PathsList list) {
|
||||
list.addVirtualFiles(getClassesRoots());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathsList getSourcePathsList() {
|
||||
final PathsList list = new PathsList();
|
||||
collectSourcePaths(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectSourcePaths(PathsList list) {
|
||||
list.addVirtualFiles(getSourceRoots());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<VirtualFile> getClassesRoots() {
|
||||
final List<VirtualFile> files = new ArrayList<VirtualFile>();
|
||||
collectPaths(files, false);
|
||||
return files;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<VirtualFile> getSourceRoots() {
|
||||
final List<VirtualFile> files = new ArrayList<VirtualFile>();
|
||||
collectPaths(files, true);
|
||||
return files;
|
||||
}
|
||||
|
||||
private void collectPaths(final List<VirtualFile> list, final boolean collectSources) {
|
||||
forEach(new Processor<OrderEntry>() {
|
||||
@Override
|
||||
public boolean process(OrderEntry orderEntry) {
|
||||
if (orderEntry instanceof ModuleSourceOrderEntry) {
|
||||
collectModulePaths(((ModuleSourceOrderEntry)orderEntry).getRootModel(), list, collectSources);
|
||||
}
|
||||
else if (orderEntry instanceof ModuleOrderEntry) {
|
||||
final Module module = ((ModuleOrderEntry)orderEntry).getModule();
|
||||
if (module != null) {
|
||||
collectModulePaths(ModuleRootManager.getInstance(module), list, collectSources);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Collections.addAll(list, orderEntry.getFiles(collectSources ? OrderRootType.SOURCES : OrderRootType.CLASSES));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void processEntries(final ModuleRootModel rootModel,
|
||||
Processor<OrderEntry> processor,
|
||||
Set<Module> processed, boolean firstLevel) {
|
||||
if (processed != null && !processed.add(rootModel.getModule())) return;
|
||||
|
||||
for (OrderEntry entry : rootModel.getOrderEntries()) {
|
||||
if (myWithoutJdk && entry instanceof JdkOrderEntry
|
||||
|| myWithoutLibraries && entry instanceof LibraryOrderEntry
|
||||
|| myWithoutDepModules && entry instanceof ModuleOrderEntry
|
||||
|| myWithoutThisModuleContent && entry instanceof ModuleSourceOrderEntry) continue;
|
||||
|
||||
if (entry instanceof ExportableOrderEntry) {
|
||||
ExportableOrderEntry exportableEntry = (ExportableOrderEntry)entry;
|
||||
final DependencyScope scope = exportableEntry.getScope();
|
||||
if (myProductionOnly && !scope.isForProductionCompile() && !scope.isForProductionRuntime()) continue;
|
||||
if (myCompileOnly && !scope.isForProductionCompile() && !scope.isForTestCompile()) continue;
|
||||
if (myRuntimeOnly && !scope.isForProductionRuntime() && !scope.isForTestRuntime()) continue;
|
||||
if (!exportableEntry.isExported()) {
|
||||
if (myExportedOnly) continue;
|
||||
if (myRecursivelyExportedOnly && !firstLevel) continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (myCondition != null && !myCondition.value(entry)) continue;
|
||||
|
||||
if (myRecursively && entry instanceof ModuleOrderEntry) {
|
||||
final Module module = ((ModuleOrderEntry)entry).getModule();
|
||||
if (module != null) {
|
||||
processEntries(ModuleRootManager.getInstance(module), processor, processed, false);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!processor.process(entry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void collectModulePaths(ModuleRootModel rootModel, List<VirtualFile> list, final boolean collectSources) {
|
||||
if (collectSources) {
|
||||
if (myProductionOnly) {
|
||||
ContentEntry[] contentEntries = rootModel.getContentEntries();
|
||||
for (ContentEntry contentEntry : contentEntries) {
|
||||
for (SourceFolder folder : contentEntry.getSourceFolders()) {
|
||||
VirtualFile root = folder.getFile();
|
||||
if (root != null && !folder.isTestSource()) {
|
||||
list.add(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Collections.addAll(list, rootModel.getSourceRoots());
|
||||
}
|
||||
}
|
||||
else {
|
||||
final CompilerModuleExtension extension = rootModel.getModuleExtension(CompilerModuleExtension.class);
|
||||
if (extension != null) {
|
||||
VirtualFile testOutput = extension.getCompilerOutputPathForTests();
|
||||
if (myProductionOnly) {
|
||||
testOutput = null;
|
||||
}
|
||||
|
||||
if (testOutput != null) {
|
||||
list.add(testOutput);
|
||||
}
|
||||
VirtualFile output = extension.getCompilerOutputPath();
|
||||
if (output != null && !output.equals(testOutput)) {
|
||||
list.add(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void forEach(Processor<OrderEntry> processor);
|
||||
|
||||
@Override
|
||||
public void forEachLibrary(final Processor<Library> processor) {
|
||||
forEach(new Processor<OrderEntry>() {
|
||||
@Override
|
||||
public boolean process(OrderEntry orderEntry) {
|
||||
if (orderEntry instanceof LibraryOrderEntry) {
|
||||
final Library library = ((LibraryOrderEntry)orderEntry).getLibrary();
|
||||
if (library != null) {
|
||||
return processor.process(library);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.util.Processor;
|
||||
import gnu.trove.THashSet;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ProjectOrderEnumerator extends OrderEnumeratorBase {
|
||||
private Project myProject;
|
||||
|
||||
public ProjectOrderEnumerator(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Processor<OrderEntry> processor) {
|
||||
myRecursively = false;
|
||||
myWithoutDepModules = true;
|
||||
final THashSet<Module> processed = new THashSet<Module>();
|
||||
for (Module module : ModuleManager.getInstance(myProject).getSortedModules()) {
|
||||
processEntries(ModuleRootManager.getInstance(module), processor, processed, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -303,6 +303,11 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj
|
||||
return VfsUtil.toVirtualFileArray(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator orderEntries() {
|
||||
return new ProjectOrderEnumerator(myProject);
|
||||
}
|
||||
|
||||
public VirtualFile[] getContentRootsFromAllModules() {
|
||||
List<VirtualFile> result = new ArrayList<VirtualFile>();
|
||||
final Module[] modules = getModuleManager().getSortedModules();
|
||||
|
||||
@@ -521,6 +521,12 @@ public class RootModelImpl implements ModifiableRootModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public OrderEnumerator orderEntries() {
|
||||
return new ModuleOrderEnumerator(this);
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return myProjectRootManager.getProject();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.psi.impl;
|
||||
|
||||
import com.intellij.ide.IconProvider;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.*;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -164,6 +165,14 @@ public class PomTargetPsiElementImpl extends RenameableFakePsiElement implements
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Language getLanguage() {
|
||||
if (myTarget instanceof PsiTarget) {
|
||||
return ((PsiTarget)myTarget).getNavigationElement().getLanguage();
|
||||
}
|
||||
return Language.ANY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Project getProject() {
|
||||
|
||||
@@ -51,6 +51,9 @@ import com.intellij.psi.impl.source.PsiFileImpl;
|
||||
import com.intellij.psi.impl.source.resolve.FileContextUtil;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.FileContentUtil;
|
||||
import com.intellij.util.containers.ConcurrentHashMap;
|
||||
@@ -379,15 +382,24 @@ public class FileManagerImpl implements FileManager {
|
||||
return getDefaultResolveScope(vFile);
|
||||
}
|
||||
|
||||
public GlobalSearchScope getDefaultResolveScope(VirtualFile vFile) {
|
||||
GlobalSearchScope scope = getInherentResolveScope(vFile);
|
||||
for (ResolveScopeEnlarger enlarger : ResolveScopeEnlarger.EP_NAME.getExtensions()) {
|
||||
final SearchScope extra = enlarger.getAdditionalResolveScope(vFile, myManager.getProject());
|
||||
if (extra != null) {
|
||||
scope = scope.union(extra);
|
||||
|
||||
public GlobalSearchScope getDefaultResolveScope(final VirtualFile vFile) {
|
||||
final Project project = myManager.getProject();
|
||||
final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
|
||||
assert psiFile != null;
|
||||
return CachedValuesManager.getManager(project).getCachedValue(psiFile, new CachedValueProvider<GlobalSearchScope>() {
|
||||
@Override
|
||||
public Result<GlobalSearchScope> compute() {
|
||||
GlobalSearchScope scope = getInherentResolveScope(vFile);
|
||||
for (ResolveScopeEnlarger enlarger : ResolveScopeEnlarger.EP_NAME.getExtensions()) {
|
||||
final SearchScope extra = enlarger.getAdditionalResolveScope(vFile, project);
|
||||
if (extra != null) {
|
||||
scope = scope.union(extra);
|
||||
}
|
||||
}
|
||||
return Result.create(scope, PsiModificationTracker.MODIFICATION_COUNT, ProjectRootManager.getInstance(project));
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
});
|
||||
}
|
||||
|
||||
private GlobalSearchScope getInherentResolveScope(VirtualFile vFile) {
|
||||
|
||||
+5
@@ -97,6 +97,11 @@ public abstract class StubProjectRootManagerEx extends ProjectRootManagerEx {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderEnumerator orderEntries() {
|
||||
throw new UnsupportedOperationException("'orderEntries' not implemented in " + getClass().getName());
|
||||
}
|
||||
|
||||
public VirtualFile[] getContentRootsFromAllModules() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ import org.jetbrains.annotations.NonNls;
|
||||
* single logical <code>(line; column)</code> pair matches soft wrap-introduced virtual space, i.e. different visual positions
|
||||
* correspond to the same logical position. It's convenient to store exact visual location details within the logical
|
||||
* position in order to relief further {@code 'logical position' -> 'visual position'} mapping.
|
||||
* <p/>
|
||||
* <b>Note:</b> two objects of this class are considered equal if their logical line and column are equal. I.e. all logical positions
|
||||
* for soft wrap-introduced virtual space and the first document symbol after soft wrap are considered to be equal.
|
||||
*
|
||||
* @see Editor#offsetToLogicalPosition(int)
|
||||
* @see Editor#logicalPositionToOffset(LogicalPosition)
|
||||
@@ -134,18 +137,11 @@ public class LogicalPosition implements Comparable<LogicalPosition> {
|
||||
if (!(o instanceof LogicalPosition)) return false;
|
||||
final LogicalPosition logicalPosition = (LogicalPosition) o;
|
||||
|
||||
return column == logicalPosition.column && line == logicalPosition.line && softWrapLines == logicalPosition.softWrapLines
|
||||
&& linesFromActiveSoftWrap == logicalPosition.linesFromActiveSoftWrap
|
||||
&& softWrapColumnDiff == logicalPosition.softWrapColumnDiff && foldedLines == logicalPosition.foldedLines
|
||||
&& foldingColumnDiff == logicalPosition.foldingColumnDiff;
|
||||
return column == logicalPosition.column && line == logicalPosition.line;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = 29 * line + column;
|
||||
result = result * 29 + softWrapLines;
|
||||
result = 29 * result + softWrapColumnDiff;
|
||||
result = 29 * result + foldedLines;
|
||||
return 29 * result + foldingColumnDiff;
|
||||
return 29 * line + column;
|
||||
}
|
||||
|
||||
@NonNls
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.intellij.openapi.editor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Defines contract for the services that bring <code>'soft wrapping'</code> to the editor.
|
||||
* <p/>
|
||||
@@ -85,6 +87,15 @@ public interface SoftWrapModel {
|
||||
@Nullable
|
||||
TextChange getSoftWrap(int offset);
|
||||
|
||||
/**
|
||||
* Allows to ask current model about all soft wraps registered for the given document line.
|
||||
*
|
||||
* @param documentLine target document line
|
||||
* @return all soft wraps registered for the given document line
|
||||
*/
|
||||
@NotNull
|
||||
List<TextChange> getSoftWrapsForLine(int documentLine);
|
||||
|
||||
/**
|
||||
* Notifies current model that target document is about to be changed at location identified by the given visual position.
|
||||
* <p/>
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.fileChooser;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class FileTypeDescriptor extends FileChooserDescriptor {
|
||||
private final ArrayList<String> ext;
|
||||
|
||||
public FileTypeDescriptor(String title, @NotNull String... extensions) {
|
||||
super(true, false, false, true, false, false);
|
||||
assert extensions.length > 0 : "There should be at least one extension";
|
||||
ext = new ArrayList<String>(Arrays.asList(extensions));
|
||||
setTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
|
||||
final String ex = file.getExtension();
|
||||
return file.isDirectory() || (ex != null && ext.contains(ex.toLowerCase()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFileSelectable(VirtualFile file) {
|
||||
return !file.isDirectory() && isFileVisible(file, true);
|
||||
}
|
||||
}
|
||||
@@ -15,14 +15,20 @@
|
||||
*/
|
||||
package com.intellij.openapi.ui;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.wm.IdeGlassPane;
|
||||
import com.intellij.openapi.wm.IdeGlassPaneUtil;
|
||||
import com.intellij.ui.UIBundle;
|
||||
import com.intellij.util.ui.update.LazyUiDisposable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* @author Vladimir Kondratyev
|
||||
@@ -58,6 +64,7 @@ public class ThreeComponentsSplitter extends JPanel {
|
||||
private int myLastSize = 10;
|
||||
|
||||
private boolean myShowDividerControls;
|
||||
private int myDividerZone;
|
||||
|
||||
|
||||
/**
|
||||
@@ -85,6 +92,10 @@ public class ThreeComponentsSplitter extends JPanel {
|
||||
setOrientation(myVerticalSplit);
|
||||
}
|
||||
|
||||
public void setDividerMouseZoneSize(int size) {
|
||||
myDividerZone = size;
|
||||
}
|
||||
|
||||
public boolean isHonorMinimumSize() {
|
||||
return myHonorMinimumSize;
|
||||
}
|
||||
@@ -262,7 +273,7 @@ public class ThreeComponentsSplitter extends JPanel {
|
||||
}
|
||||
|
||||
public void setDividerWidth(int width) {
|
||||
if (width <= 0) {
|
||||
if (width < 0) {
|
||||
throw new IllegalArgumentException("Wrong divider width: " + width);
|
||||
}
|
||||
if (myDividerWidth != width) {
|
||||
@@ -382,17 +393,79 @@ public class ThreeComponentsSplitter extends JPanel {
|
||||
return lastVisible() ? myLastSize : 0;
|
||||
}
|
||||
|
||||
protected class Divider extends JPanel {
|
||||
protected class Divider extends JPanel implements Disposable {
|
||||
protected boolean myDragging;
|
||||
protected Point myPoint;
|
||||
private final boolean myIsFirst;
|
||||
|
||||
private MouseAdapter myListener = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, Divider.this);
|
||||
processMouseEvent(event);
|
||||
if (event.isConsumed()) {
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, Divider.this);
|
||||
processMouseEvent(event);
|
||||
if (event.isConsumed()) {
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, Divider.this);
|
||||
processMouseMotionEvent(event);
|
||||
if (event.isConsumed()) {
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
};
|
||||
private boolean myWasPressedOnMe;
|
||||
|
||||
public Divider(boolean isFirst) {
|
||||
super(new GridBagLayout());
|
||||
setFocusable(false);
|
||||
enableEvents(MouseEvent.MOUSE_EVENT_MASK | MouseEvent.MOUSE_MOTION_EVENT_MASK);
|
||||
myIsFirst = isFirst;
|
||||
setOrientation(myVerticalSplit);
|
||||
|
||||
new LazyUiDisposable<Divider>(null, this, this) {
|
||||
@Override
|
||||
protected void initialize(@NotNull Disposable parent, @NotNull Divider child, @Nullable Project project) {
|
||||
init();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isInside(Point p) {
|
||||
if (myVerticalSplit) {
|
||||
if (getHeight() > 0) {
|
||||
return p.y >= 0 && p.y < getHeight();
|
||||
} else {
|
||||
return p.y >= -myDividerZone / 2 && p.y < myDividerZone / 2;
|
||||
}
|
||||
} else {
|
||||
if (getWidth() > 0) {
|
||||
return p.x >= 0 && p.x < getWidth();
|
||||
} else {
|
||||
return p.x >= -myDividerZone / 2 && p.x < myDividerZone / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
IdeGlassPane gp = IdeGlassPaneUtil.find(this);
|
||||
gp.addMouseMotionPreprocessor(myListener, this);
|
||||
gp.addMousePreprocessor(myListener, this);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
private void setOrientation(boolean isVerticalSplit) {
|
||||
@@ -485,13 +558,13 @@ public class ThreeComponentsSplitter extends JPanel {
|
||||
|
||||
protected void processMouseMotionEvent(MouseEvent e) {
|
||||
super.processMouseMotionEvent(e);
|
||||
if (MouseEvent.MOUSE_DRAGGED == e.getID()) {
|
||||
if (MouseEvent.MOUSE_DRAGGED == e.getID() && myWasPressedOnMe) {
|
||||
myDragging = true;
|
||||
setCursor(getOrientation() ? Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR) : Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
|
||||
myPoint = SwingUtilities.convertPoint(this, e.getPoint(), ThreeComponentsSplitter.this);
|
||||
float proportion;
|
||||
if (getOrientation()) {
|
||||
if (getHeight() > 0) {
|
||||
if (getHeight() > 0 || myDividerZone > 0) {
|
||||
if (myIsFirst) {
|
||||
setFirstSize(Math.max(getMinSize(myFirstComponent), myPoint.y));
|
||||
}
|
||||
@@ -501,7 +574,7 @@ public class ThreeComponentsSplitter extends JPanel {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (getWidth() > 0) {
|
||||
if (getWidth() > 0 || myDividerZone > 0) {
|
||||
if (myIsFirst) {
|
||||
setFirstSize(Math.max(getMinSize(myFirstComponent), myPoint.x));
|
||||
}
|
||||
@@ -512,6 +585,10 @@ public class ThreeComponentsSplitter extends JPanel {
|
||||
}
|
||||
ThreeComponentsSplitter.this.doLayout();
|
||||
}
|
||||
|
||||
if (myWasPressedOnMe) {
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
|
||||
private int getMinSize(JComponent component) {
|
||||
@@ -545,11 +622,21 @@ public class ThreeComponentsSplitter extends JPanel {
|
||||
}
|
||||
case MouseEvent.MOUSE_PRESSED:
|
||||
{
|
||||
setCursor(getOrientation() ? Cursor.getPredefinedCursor(9) : Cursor.getPredefinedCursor(11));
|
||||
if (isInside(e.getPoint())) {
|
||||
myWasPressedOnMe = true;
|
||||
setCursor(getOrientation() ? Cursor.getPredefinedCursor(9) : Cursor.getPredefinedCursor(11));
|
||||
e.consume();
|
||||
} else {
|
||||
myWasPressedOnMe = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MouseEvent.MOUSE_RELEASED:
|
||||
{
|
||||
if (myWasPressedOnMe) {
|
||||
e.consume();
|
||||
}
|
||||
myWasPressedOnMe = false;
|
||||
myDragging = false;
|
||||
myPoint = null;
|
||||
break;
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.NotNullLazyKey;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
import com.intellij.openapi.util.UserDataHolderEx;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class CachedValuesManager {
|
||||
@@ -85,4 +86,25 @@ public abstract class CachedValuesManager {
|
||||
@NotNull Key<CachedValue<T>> key,
|
||||
@NotNull CachedValueProvider<T> provider,
|
||||
boolean trackValue);
|
||||
|
||||
public <T, D extends UserDataHolder> T getCachedValue(@NotNull D dataHolder,
|
||||
@NotNull CachedValueProvider<T> provider) {
|
||||
return getCachedValue(dataHolder, new MemoizationKey<CachedValue<T>>("$CachedValue$" + provider.getClass().getName()), provider, false);
|
||||
}
|
||||
|
||||
public static class MemoizationKey<T> extends Key<T> {
|
||||
public MemoizationKey(@NotNull @NonNls String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof MemoizationKey && toString().equals(obj.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
package com.intellij.util.ui.update;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.AsyncResult;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataKey;
|
||||
@@ -58,10 +60,18 @@ public abstract class LazyUiDisposable<T extends Disposable> implements Activata
|
||||
if (myWasEverShown) return;
|
||||
|
||||
try {
|
||||
final Disposable parent = findParentDisposable();
|
||||
initialize(parent, myChild, findProject());
|
||||
Disposer.register(parent, myChild);
|
||||
} finally {
|
||||
findParentDisposable().doWhenDone(new AsyncResult.Handler<Disposable>() {
|
||||
public void run(Disposable parent) {
|
||||
Project project = null;
|
||||
if (ApplicationManager.getApplication() != null) {
|
||||
project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
|
||||
}
|
||||
initialize(parent, myChild, project);
|
||||
Disposer.register(parent, myChild);
|
||||
}
|
||||
});
|
||||
}
|
||||
finally {
|
||||
myWasEverShown = true;
|
||||
}
|
||||
}
|
||||
@@ -72,26 +82,32 @@ public abstract class LazyUiDisposable<T extends Disposable> implements Activata
|
||||
protected abstract void initialize(@NotNull Disposable parent, @NotNull T child, @Nullable Project project);
|
||||
|
||||
@NotNull
|
||||
private Disposable findParentDisposable() {
|
||||
final Disposable parent = findObject(myParent, PlatformDataKeys.UI_DISPOSABLE);
|
||||
return parent != null ? parent : Disposer.get("ui");
|
||||
private AsyncResult<Disposable> findParentDisposable() {
|
||||
return findDisposable(myParent, PlatformDataKeys.UI_DISPOSABLE);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private Project findProject() {
|
||||
return (Project) findObject(myProject, PlatformDataKeys.PROJECT);
|
||||
}
|
||||
|
||||
private Disposable findObject(Disposable defaultValue, DataKey<? extends Disposable> key) {
|
||||
private static AsyncResult<Disposable> findDisposable(Disposable defaultValue, final DataKey<? extends Disposable> key) {
|
||||
if (defaultValue == null) {
|
||||
if (ApplicationManager.getApplication() != null) {
|
||||
return key.getData(DataManager.getInstance().getDataContext());
|
||||
} else {
|
||||
final AsyncResult<Disposable> result = new AsyncResult<Disposable>();
|
||||
DataManager.getInstance().getDataContextFromFocus().doWhenDone(new AsyncResult.Handler<DataContext>() {
|
||||
public void run(DataContext context) {
|
||||
Disposable disposable = key.getData(context);
|
||||
if (disposable == null) {
|
||||
disposable = Disposer.get("ui");
|
||||
}
|
||||
result.setDone(disposable);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
else {
|
||||
return new AsyncResult.Done<Disposable>(defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ public class EditorFragmentComponent extends JPanel {
|
||||
int endLine,
|
||||
boolean showFolding, boolean showGutter) {
|
||||
final EditorEx editorEx = (EditorEx)editor;
|
||||
final Color old = editorEx.getBackroundColor();
|
||||
final Color old = editorEx.getBackgroundColor();
|
||||
Color backColor = getBackgroundColor(editor);
|
||||
editorEx.setBackgroundColor(backColor);
|
||||
EditorFragmentComponent fragmentComponent = new EditorFragmentComponent(editorEx, startLine, endLine,
|
||||
|
||||
@@ -54,6 +54,7 @@ public class PerformanceWatcher implements ApplicationComponent {
|
||||
private List<StackTraceElement> myStacktraceCommonPart;
|
||||
|
||||
private int UNRESPONSIVE_THRESHOLD = 5;
|
||||
private int UNRESPONSIVE_INTERVAL = 5;
|
||||
|
||||
@NotNull
|
||||
public String getComponentName() {
|
||||
@@ -72,7 +73,16 @@ public class PerformanceWatcher implements ApplicationComponent {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (UNRESPONSIVE_THRESHOLD == 0) {
|
||||
final String interval = System.getProperty("performance.watcher.interval");
|
||||
if (interval != null) {
|
||||
try {
|
||||
UNRESPONSIVE_INTERVAL = Integer.parseInt(interval);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (UNRESPONSIVE_THRESHOLD == 0 || UNRESPONSIVE_INTERVAL == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -145,7 +155,7 @@ public class PerformanceWatcher implements ApplicationComponent {
|
||||
private void checkEDTResponsiveness() {
|
||||
while(true) {
|
||||
try {
|
||||
if (myShutdownSemaphore.tryAcquire(1, TimeUnit.SECONDS)) {
|
||||
if (myShutdownSemaphore.tryAcquire(UNRESPONSIVE_INTERVAL, TimeUnit.SECONDS)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+228
-88
@@ -24,6 +24,11 @@
|
||||
*/
|
||||
package com.intellij.openapi.editor.actions;
|
||||
|
||||
import com.intellij.ide.ui.customization.CustomActionsSchema;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.ActionPlaces;
|
||||
import com.intellij.openapi.actionSystem.ActionPopupMenu;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.event.EditorMouseEvent;
|
||||
import com.intellij.openapi.editor.event.EditorMouseEventArea;
|
||||
@@ -31,17 +36,20 @@ import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.EditorPopupHandler;
|
||||
import com.intellij.ide.ui.customization.CustomActionsSchema;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
public class EditorActionUtil {
|
||||
protected static final Object EDIT_COMMAND_GROUP = Key.create("EditGroup");
|
||||
protected static final Object DELETE_COMMAND_GROUP = Key.create("DeleteGroup");
|
||||
|
||||
private EditorActionUtil() {
|
||||
}
|
||||
|
||||
public static void scrollRelatively(Editor editor, int lineShift) {
|
||||
if (lineShift != 0) {
|
||||
editor.getScrollingModel().scrollVertically(
|
||||
@@ -69,10 +77,10 @@ public class EditorActionUtil {
|
||||
int columnShift,
|
||||
int lineShift,
|
||||
boolean withSelection) {
|
||||
Rectangle viewRect = editor.getScrollingModel().getVisibleArea();
|
||||
Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
|
||||
VisualPosition pos = editor.getCaretModel().getVisualPosition();
|
||||
Point caretLocation = editor.visualPositionToXY(pos);
|
||||
int caretVShift = caretLocation.y - viewRect.y;
|
||||
int caretVShift = caretLocation.y - visibleArea.y;
|
||||
|
||||
editor.getCaretModel().moveCaretRelatively(columnShift, lineShift, withSelection, false, false);
|
||||
|
||||
@@ -82,6 +90,7 @@ public class EditorActionUtil {
|
||||
editor.getScrollingModel().scrollVertically(caretLocation2.y - caretVShift);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"AssignmentToForLoopParameter"})
|
||||
public static void indentLine(Project project, Editor editor, int lineNumber, int indent) {
|
||||
EditorSettings editorSettings = editor.getSettings();
|
||||
Document document = editor.getDocument();
|
||||
@@ -172,21 +181,21 @@ public class EditorActionUtil {
|
||||
char current = text.charAt(offset);
|
||||
char next = offset + 1 < text.length() ? text.charAt(offset + 1) : 0;
|
||||
|
||||
final boolean firstIsIdentifiePart = Character.isJavaIdentifierPart(prev);
|
||||
final boolean firstIsIdentifierPart = Character.isJavaIdentifierPart(prev);
|
||||
final boolean secondIsIdentifierPart = Character.isJavaIdentifierPart(current);
|
||||
if (firstIsIdentifiePart && !secondIsIdentifierPart) {
|
||||
if (firstIsIdentifierPart && !secondIsIdentifierPart) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isCamel) {
|
||||
if (firstIsIdentifiePart && secondIsIdentifierPart &&
|
||||
if (firstIsIdentifierPart && secondIsIdentifierPart &&
|
||||
(Character.isLowerCase(prev) && Character.isUpperCase(current) || prev != '_' && current == '_' ||
|
||||
Character.isUpperCase(prev) && Character.isUpperCase(current) && Character.isLowerCase(next))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return !Character.isWhitespace(prev) && !firstIsIdentifiePart &&
|
||||
return !Character.isWhitespace(prev) && !firstIsIdentifierPart &&
|
||||
(Character.isWhitespace(current) || secondIsIdentifierPart);
|
||||
}
|
||||
|
||||
@@ -198,98 +207,200 @@ public class EditorActionUtil {
|
||||
LogicalPosition blockSelectionStart = selectionModel.hasBlockSelection()
|
||||
? selectionModel.getBlockStart()
|
||||
: caretModel.getLogicalPosition();
|
||||
|
||||
int columnNumber = editor.getCaretModel().getLogicalPosition().column;
|
||||
int lineNumber = editor.getCaretModel().getLogicalPosition().line;
|
||||
|
||||
VisualPosition visCaret = editor.getCaretModel().getVisualPosition();
|
||||
while (lineNumber >= 0 && editor.logicalToVisualPosition(new LogicalPosition(lineNumber, 0)).line == visCaret.line) lineNumber--;
|
||||
lineNumber++;
|
||||
|
||||
EditorSettings editorSettings = editor.getSettings();
|
||||
if (!editorSettings.isSmartHome()) {
|
||||
LogicalPosition pos = new LogicalPosition(lineNumber, 0);
|
||||
editor.getCaretModel().moveToLogicalPosition(pos);
|
||||
|
||||
int logCaretLine = caretModel.getLogicalPosition().line;
|
||||
VisualPosition currentVisCaret = caretModel.getVisualPosition();
|
||||
VisualPosition caretLogLineStartVis = editor.offsetToVisualPosition(document.getLineStartOffset(logCaretLine));
|
||||
|
||||
if (currentVisCaret.line > caretLogLineStartVis.line) {
|
||||
// Caret is located not at the first visual line of soft-wrapped logical line.
|
||||
moveCaretToStartOfSoftWrappedLine(editor, currentVisCaret);
|
||||
setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart);
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
return;
|
||||
}
|
||||
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
if (lineNumber >= document.getLineCount() || offset >= document.getTextLength()) {
|
||||
int newColNumber = 0;
|
||||
if (columnNumber == 0) {
|
||||
newColNumber = findSmartIndent(editor, offset);
|
||||
// Skip folded lines.
|
||||
int logLineToUse = logCaretLine - 1;
|
||||
while (logLineToUse >= 0 && editor.offsetToVisualPosition(document.getLineEndOffset(logLineToUse)).line == currentVisCaret.line) {
|
||||
logLineToUse--;
|
||||
}
|
||||
logLineToUse++;
|
||||
|
||||
if (logLineToUse >= document.getLineCount()) {
|
||||
editor.getCaretModel().moveToVisualPosition(new VisualPosition(logLineToUse, 0));
|
||||
}
|
||||
else if (logLineToUse == logCaretLine) {
|
||||
int line = currentVisCaret.line;
|
||||
int column;
|
||||
if (currentVisCaret.column == 0) {
|
||||
column = findSmartIndentColumn(editor, currentVisCaret.line);
|
||||
}
|
||||
LogicalPosition pos = new LogicalPosition(lineNumber, newColNumber);
|
||||
editor.getCaretModel().moveToLogicalPosition(pos);
|
||||
|
||||
setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart);
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
return;
|
||||
else {
|
||||
column = findFirstNonSpaceColumnOnTheLine(editor, currentVisCaret.line);
|
||||
}
|
||||
caretModel.moveToVisualPosition(new VisualPosition(line, column));
|
||||
}
|
||||
|
||||
int start = findFirstNonspaceOffsetOnTheLine(document, lineNumber);
|
||||
int lineEnd = document.getLineEndOffset(lineNumber);
|
||||
if (lineNumber > 0 && lineEnd == start && columnNumber == 0) {
|
||||
int newColNumber = findSmartIndent(editor, offset);
|
||||
LogicalPosition pos = new LogicalPosition(lineNumber, newColNumber);
|
||||
editor.getCaretModel().moveToLogicalPosition(pos);
|
||||
setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart);
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
return;
|
||||
else {
|
||||
LogicalPosition logLineEndLog = editor.offsetToLogicalPosition(document.getLineEndOffset(logLineToUse));
|
||||
VisualPosition logLineEndVis = editor.logicalToVisualPosition(logLineEndLog);
|
||||
if (logLineEndLog.isOnSoftWrappedLine()) {
|
||||
moveCaretToStartOfSoftWrappedLine(editor, logLineEndVis);
|
||||
}
|
||||
else {
|
||||
int line = logLineEndVis.line;
|
||||
int column = 0;
|
||||
if (currentVisCaret.column == 0 && editorSettings.isSmartHome()) {
|
||||
findSmartIndentColumn(editor, line);
|
||||
}
|
||||
caretModel.moveToVisualPosition(new VisualPosition(line, column));
|
||||
}
|
||||
}
|
||||
|
||||
int lineStart = document.getLineStartOffset(lineNumber);
|
||||
int newOffset = lineStart;
|
||||
if (start < offset || columnNumber == 0) {
|
||||
newOffset = start;
|
||||
}
|
||||
editor.getCaretModel().moveToOffset(newOffset);
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
|
||||
setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart);
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
}
|
||||
|
||||
private static int findSmartIndent(Editor editor, int offset) {
|
||||
int nonSpaceLineNumber = findFirstNonspaceLineBack(editor.getDocument(), offset);
|
||||
if (nonSpaceLineNumber >= 0) {
|
||||
int newOffset = findFirstNonspaceOffsetOnTheLine(editor.getDocument(), nonSpaceLineNumber);
|
||||
return editor.offsetToLogicalPosition(newOffset).column;
|
||||
private static void moveCaretToStartOfSoftWrappedLine(Editor editor, VisualPosition currentVisual) {
|
||||
CaretModel caretModel = editor.getCaretModel();
|
||||
int line = currentVisual.line;
|
||||
int column = 0;
|
||||
|
||||
if (currentVisual.column == 0) {
|
||||
line--;
|
||||
int nonSpaceColumn = findFirstNonSpaceColumnOnTheLine(editor, line);
|
||||
column = nonSpaceColumn >= 0 ? nonSpaceColumn : 0;
|
||||
}
|
||||
else {
|
||||
int nonSpaceColumn = findFirstNonSpaceColumnOnTheLine(editor, currentVisual.line);
|
||||
if (nonSpaceColumn > 0 /* current visual line is not empty */ && nonSpaceColumn != currentVisual.column) {
|
||||
column = nonSpaceColumn;
|
||||
}
|
||||
}
|
||||
|
||||
caretModel.moveToVisualPosition(new VisualPosition(line, column));
|
||||
}
|
||||
|
||||
private static int findSmartIndentColumn(Editor editor, int visualLine) {
|
||||
for (int i = visualLine; i >= 0; i--) {
|
||||
int column = findFirstNonSpaceColumnOnTheLine(editor, visualLine);
|
||||
if (column >= 0) {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int findFirstNonspaceLineBack(Document document, int offset) {
|
||||
CharSequence text = document.getCharsSequence();
|
||||
int foundOffset = offset - 1;
|
||||
for (; foundOffset > 0; foundOffset--) {
|
||||
char c = text.charAt(foundOffset);
|
||||
if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
|
||||
break;
|
||||
/**
|
||||
* Tries to find visual column that points to the first non-white space symbol at the visual line at the given editor.
|
||||
*
|
||||
* @param editor target editor
|
||||
* @param visualLineNumber target visual line
|
||||
* @return visual column that points to the first non-white space symbol at the target visual line if the one exists;
|
||||
* <code>'-1'</code> otherwise
|
||||
*/
|
||||
public static int findFirstNonSpaceColumnOnTheLine(Editor editor, int visualLineNumber) {
|
||||
Document document = editor.getDocument();
|
||||
VisualPosition visLine = new VisualPosition(visualLineNumber, 0);
|
||||
int logLine = editor.visualToLogicalPosition(visLine).line;
|
||||
int logLineStartOffset = document.getLineStartOffset(logLine);
|
||||
int logLineEndOffset = document.getLineEndOffset(logLine);
|
||||
LogicalPosition logLineStart = editor.offsetToLogicalPosition(logLineStartOffset);
|
||||
VisualPosition visLineStart = editor.logicalToVisualPosition(logLineStart);
|
||||
|
||||
boolean softWrapIntroducedLine = visLineStart.line != visualLineNumber;
|
||||
if (!softWrapIntroducedLine) {
|
||||
int offset = findFirstNonSpaceOffsetInRange(document.getCharsSequence(), logLineStartOffset, logLineEndOffset);
|
||||
if (offset >= 0) {
|
||||
return EditorUtil.calcColumnNumber(editor, document.getCharsSequence(), logLineStartOffset, offset);
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (foundOffset == -1) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return document.getLineNumber(foundOffset);
|
||||
|
||||
int lineFeedsToSkip = visualLineNumber - visLineStart.line;
|
||||
List<TextChange> softWraps = editor.getSoftWrapModel().getSoftWrapsForLine(logLine);
|
||||
for (TextChange softWrap : softWraps) {
|
||||
int softWrapLineFeedsNumber = StringUtil.countNewLines(softWrap.getText());
|
||||
|
||||
if (softWrapLineFeedsNumber < lineFeedsToSkip) {
|
||||
lineFeedsToSkip -= softWrapLineFeedsNumber;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Point to the first non-white space symbol at the target soft wrap visual line or to the first non-white space symbol
|
||||
// of document line that follows it if possible.
|
||||
CharSequence softWrapText = softWrap.getText();
|
||||
int softWrapTextLength = softWrapText.length();
|
||||
boolean skip = true;
|
||||
for (int j = 0; j < softWrapTextLength; j++) {
|
||||
if (softWrapText.charAt(j) == '\n') {
|
||||
skip = --lineFeedsToSkip > 0;
|
||||
continue;
|
||||
}
|
||||
if (skip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int nextSoftWrapLineFeedOffset = StringUtil.indexOf(softWrapText, '\n', j, softWrapTextLength);
|
||||
|
||||
int end = findFirstNonSpaceOffsetInRange(softWrapText, j, softWrapTextLength);
|
||||
if (end >= 0) {
|
||||
// Non space symbol is contained at soft wrap text after offset that corresponds to the target visual line start.
|
||||
if (nextSoftWrapLineFeedOffset < 0 || end < nextSoftWrapLineFeedOffset) {
|
||||
return EditorUtil.calcColumnNumber(editor, softWrapText, j, end);
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextSoftWrapLineFeedOffset >= 0) {
|
||||
// There are soft wrap-introduced visual lines after the target one
|
||||
return -1;
|
||||
}
|
||||
|
||||
end = findFirstNonSpaceOffsetInRange(document.getCharsSequence(), softWrap.getStart(), logLineEndOffset);
|
||||
if (end >= 0) {
|
||||
// Width of soft wrap virtual text that is located at the target visual line.
|
||||
int result = EditorUtil.calcColumnNumber(editor, softWrapText, j, softWrapTextLength);
|
||||
result += EditorUtil.calcColumnNumber(editor, document.getCharsSequence(), softWrap.getStart(), end);
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int findFirstNonspaceOffsetOnTheLine(Document document, int lineNumber) {
|
||||
public static int findFirstNonSpaceOffsetOnTheLine(Document document, int lineNumber) {
|
||||
int lineStart = document.getLineStartOffset(lineNumber);
|
||||
int lineEnd = document.getLineEndOffset(lineNumber);
|
||||
CharSequence text = document.getCharsSequence();
|
||||
int start = lineStart;
|
||||
for (; start < lineEnd; start++) {
|
||||
int result = findFirstNonSpaceOffsetInRange(document.getCharsSequence(), lineStart, lineEnd);
|
||||
return result >= 0 ? result : lineEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find non white space symbol at the given range at the given document.
|
||||
*
|
||||
* @param text text to be inspected
|
||||
* @param start target start offset (inclusive)
|
||||
* @param end target end offset (exclusive)
|
||||
* @return index of the first non-white space character at the given document at the given range if the one is found;
|
||||
* <code>'-1'</code> otherwise
|
||||
*/
|
||||
public static int findFirstNonSpaceOffsetInRange(CharSequence text, int start, int end) {
|
||||
for (; start < end; start++) {
|
||||
char c = text.charAt(start);
|
||||
if (c != ' ' && c != '\t') {
|
||||
return start;
|
||||
}
|
||||
}
|
||||
return lineEnd;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void moveCaretToLineEnd(Editor editor, boolean isWithSelection) {
|
||||
@@ -309,10 +420,33 @@ public class EditorActionUtil {
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
return;
|
||||
}
|
||||
VisualPosition visCaret = editor.getCaretModel().getVisualPosition();
|
||||
visCaret = new VisualPosition(visCaret.line, EditorUtil.getLastVisualLineColumnNumber(editor, visCaret.line));
|
||||
VisualPosition currentVisualCaret = editor.getCaretModel().getVisualPosition();
|
||||
VisualPosition visualEndOfLineWithCaret
|
||||
= new VisualPosition(currentVisualCaret.line, EditorUtil.getLastVisualLineColumnNumber(editor, currentVisualCaret.line));
|
||||
|
||||
LogicalPosition logLineEnd = editor.visualToLogicalPosition(visCaret);
|
||||
// There is a possible case that the caret is already located at the visual end of line and the line is soft wrapped.
|
||||
// We want to move the caret to the end of the next visual line then.
|
||||
if (currentVisualCaret.equals(visualEndOfLineWithCaret)) {
|
||||
LogicalPosition logical = editor.visualToLogicalPosition(visualEndOfLineWithCaret);
|
||||
int offset = editor.logicalPositionToOffset(logical);
|
||||
if (offset < editor.getDocument().getTextLength()) {
|
||||
SoftWrapModel softWrapModel = editor.getSoftWrapModel();
|
||||
TextChange softWrap = softWrapModel.getSoftWrap(offset);
|
||||
if (softWrap == null) {
|
||||
// Same offset may correspond to positions on different visual lines in case of soft wraps presence
|
||||
// (all soft-wrap introduced virtual text is mapped to the same offset as the first document symbol after soft wrap).
|
||||
// Hence, we check for soft wraps presence at two offsets.
|
||||
softWrap = softWrapModel.getSoftWrap(offset + 1);
|
||||
}
|
||||
if (softWrap != null) {
|
||||
int line = currentVisualCaret.line + 1;
|
||||
int column = EditorUtil.getLastVisualLineColumnNumber(editor, line);
|
||||
visualEndOfLineWithCaret = new VisualPosition(line, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogicalPosition logLineEnd = editor.visualToLogicalPosition(visualEndOfLineWithCaret);
|
||||
int offset = editor.logicalPositionToOffset(logLineEnd);
|
||||
lineNumber = logLineEnd.line;
|
||||
int newOffset = offset;
|
||||
@@ -325,11 +459,17 @@ public class EditorActionUtil {
|
||||
newOffset = i;
|
||||
}
|
||||
|
||||
if (newOffset == editor.getCaretModel().getOffset()) {
|
||||
newOffset = offset;
|
||||
// Check if there are white space symbols between the current caret position and visual line end.
|
||||
if (newOffset == offset) {
|
||||
caretModel.moveToVisualPosition(visualEndOfLineWithCaret);
|
||||
}
|
||||
else {
|
||||
if (newOffset == caretModel.getOffset()) {
|
||||
newOffset = offset;
|
||||
}
|
||||
caretModel.moveToOffset(newOffset);
|
||||
}
|
||||
|
||||
editor.getCaretModel().moveToOffset(newOffset);
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
|
||||
setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart);
|
||||
@@ -416,9 +556,9 @@ public class EditorActionUtil {
|
||||
public static void moveCaretPageUp(Editor editor, boolean isWithSelection) {
|
||||
((EditorEx)editor).stopOptimizedScrolling();
|
||||
int lineHeight = editor.getLineHeight();
|
||||
Rectangle viewRect = editor.getScrollingModel().getVisibleArea();
|
||||
int linesIncrement = viewRect.height / lineHeight;
|
||||
editor.getScrollingModel().scrollVertically(viewRect.y - viewRect.y % lineHeight - linesIncrement * lineHeight);
|
||||
Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
|
||||
int linesIncrement = visibleArea.height / lineHeight;
|
||||
editor.getScrollingModel().scrollVertically(visibleArea.y - visibleArea.y % lineHeight - linesIncrement * lineHeight);
|
||||
int lineShift = -linesIncrement;
|
||||
editor.getCaretModel().moveCaretRelatively(0, lineShift, isWithSelection, editor.isColumnMode(), true);
|
||||
}
|
||||
@@ -426,11 +566,11 @@ public class EditorActionUtil {
|
||||
public static void moveCaretPageDown(Editor editor, boolean isWithSelection) {
|
||||
((EditorEx)editor).stopOptimizedScrolling();
|
||||
int lineHeight = editor.getLineHeight();
|
||||
Rectangle viewRect = editor.getScrollingModel().getVisibleArea();
|
||||
int linesIncrement = viewRect.height / lineHeight;
|
||||
int allowedBottom = ((EditorEx)editor).getContentSize().height - viewRect.height;
|
||||
Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
|
||||
int linesIncrement = visibleArea.height / lineHeight;
|
||||
int allowedBottom = ((EditorEx)editor).getContentSize().height - visibleArea.height;
|
||||
editor.getScrollingModel().scrollVertically(
|
||||
Math.min(allowedBottom, viewRect.y - viewRect.y % lineHeight + linesIncrement * lineHeight));
|
||||
Math.min(allowedBottom, visibleArea.y - visibleArea.y % lineHeight + linesIncrement * lineHeight));
|
||||
editor.getCaretModel().moveCaretRelatively(0, linesIncrement, isWithSelection, editor.isColumnMode(), true);
|
||||
}
|
||||
|
||||
@@ -442,9 +582,9 @@ public class EditorActionUtil {
|
||||
LogicalPosition blockSelectionStart = selectionModel.hasBlockSelection()
|
||||
? selectionModel.getBlockStart()
|
||||
: caretModel.getLogicalPosition();
|
||||
Rectangle viewRect = editor.getScrollingModel().getVisibleArea();
|
||||
int lineNumber = viewRect.y / lineHeight;
|
||||
if (viewRect.y % lineHeight > 0) {
|
||||
Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
|
||||
int lineNumber = visibleArea.y / lineHeight;
|
||||
if (visibleArea.y % lineHeight > 0) {
|
||||
lineNumber++;
|
||||
}
|
||||
VisualPosition pos = new VisualPosition(lineNumber, editor.getCaretModel().getVisualPosition().column);
|
||||
@@ -460,8 +600,8 @@ public class EditorActionUtil {
|
||||
LogicalPosition blockSelectionStart = selectionModel.hasBlockSelection()
|
||||
? selectionModel.getBlockStart()
|
||||
: caretModel.getLogicalPosition();
|
||||
Rectangle viewRect = editor.getScrollingModel().getVisibleArea();
|
||||
int lineNumber = (viewRect.y + viewRect.height) / lineHeight - 1;
|
||||
Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
|
||||
int lineNumber = (visibleArea.y + visibleArea.height) / lineHeight - 1;
|
||||
VisualPosition pos = new VisualPosition(lineNumber, editor.getCaretModel().getVisualPosition().column);
|
||||
editor.getCaretModel().moveToVisualPosition(pos);
|
||||
setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart);
|
||||
|
||||
@@ -107,7 +107,7 @@ public interface EditorEx extends Editor {
|
||||
|
||||
void setFontSize(int fontSize);
|
||||
|
||||
Color getBackroundColor();
|
||||
Color getBackgroundColor();
|
||||
|
||||
void setBackgroundColor(Color color);
|
||||
|
||||
|
||||
@@ -43,6 +43,16 @@ public interface SoftWrapModelEx extends SoftWrapModel {
|
||||
@NotNull
|
||||
LogicalPosition adjustLogicalPosition(@NotNull LogicalPosition defaultLogical, @NotNull VisualPosition visual);
|
||||
|
||||
/**
|
||||
* Asks current model to adjust logical position for the given document offset.
|
||||
*
|
||||
* @param defaultLogical default logical position that corresponds to the given document offset
|
||||
* @param offset target editor document offset
|
||||
* @return logical position for the given editor document offset
|
||||
*/
|
||||
@NotNull
|
||||
LogicalPosition adjustLogicalPosition(LogicalPosition defaultLogical, int offset);
|
||||
|
||||
/**
|
||||
* Asks current model to adjust visual position that corresponds to the given logical position if necessary.
|
||||
* <p/>
|
||||
@@ -55,15 +65,6 @@ public interface SoftWrapModelEx extends SoftWrapModel {
|
||||
@NotNull
|
||||
VisualPosition adjustVisualPosition(@NotNull LogicalPosition logical, @NotNull VisualPosition defaultVisual);
|
||||
|
||||
/**
|
||||
* Asks current model to calculate logical position for the given editor document offset.
|
||||
*
|
||||
* @param offset target editor document offset
|
||||
* @return logical position for the given editor document offset
|
||||
*/
|
||||
@NotNull
|
||||
LogicalPosition offsetToLogicalPosition(int offset);
|
||||
|
||||
/**
|
||||
* @return unmodifiable collection of soft wraps currently registered within the current model
|
||||
*/
|
||||
|
||||
@@ -17,55 +17,115 @@ package com.intellij.openapi.editor.ex.util;
|
||||
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorModificationUtil;
|
||||
import com.intellij.openapi.editor.LogicalPosition;
|
||||
import com.intellij.openapi.editor.VisualPosition;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.impl.ComplementaryFontsRegistry;
|
||||
import com.intellij.openapi.editor.impl.FontInfo;
|
||||
import com.intellij.openapi.editor.impl.IterationState;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public class EditorUtil {
|
||||
private EditorUtil() { }
|
||||
|
||||
public static int getLastVisualLineColumnNumber(Editor editor, int line) {
|
||||
Document document = editor.getDocument();
|
||||
int lastLine = document.getLineCount() - 1;
|
||||
if (lastLine < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Filter all lines that are not shown because of collapsed folding region.
|
||||
VisualPosition visStart = new VisualPosition(line, 0);
|
||||
LogicalPosition logStart = editor.visualToLogicalPosition(visStart);
|
||||
int lastLogLine = logStart.line;
|
||||
while (lastLogLine < editor.getDocument().getLineCount() - 1) {
|
||||
while (lastLogLine < document.getLineCount() - 1) {
|
||||
logStart = new LogicalPosition(logStart.line + 1, logStart.column);
|
||||
VisualPosition tryVisible = editor.logicalToVisualPosition(logStart);
|
||||
if (tryVisible.line != visStart.line) break;
|
||||
lastLogLine = logStart.line;
|
||||
}
|
||||
|
||||
int lastLine = editor.getDocument().getLineCount() - 1;
|
||||
if (lastLine < 0) {
|
||||
return 0;
|
||||
int resultLogLine = Math.min(lastLogLine, lastLine);
|
||||
VisualPosition resVisStart = editor.offsetToVisualPosition(document.getLineStartOffset(resultLogLine));
|
||||
VisualPosition resVisEnd = editor.offsetToVisualPosition(document.getLineEndOffset(resultLogLine));
|
||||
|
||||
// Target logical line is not soft wrap affected.
|
||||
if (resVisStart.line == resVisEnd.line) {
|
||||
return resVisEnd.column;
|
||||
}
|
||||
return editor.offsetToVisualPosition(editor.getDocument().getLineEndOffset(Math.min(lastLogLine, lastLine))).column;
|
||||
|
||||
int visualLinesToSkip = line - resVisStart.line;
|
||||
List<TextChange> softWraps = editor.getSoftWrapModel().getSoftWrapsForLine(resultLogLine);
|
||||
for (int i = 0; i < softWraps.size(); i++) {
|
||||
TextChange softWrap = softWraps.get(i);
|
||||
int softWrapLineFeeds = StringUtil.countNewLines(softWrap.getText());
|
||||
if (softWrapLineFeeds < visualLinesToSkip) {
|
||||
visualLinesToSkip -= softWrapLineFeeds;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Target visual column is the one just before line feed introduced by the next line feed.
|
||||
if (softWrapLineFeeds == visualLinesToSkip) {
|
||||
if (i >= softWraps.size() - 1) {
|
||||
return resVisEnd.column;
|
||||
}
|
||||
// We need to find visual column for line feed of the next soft wrap.
|
||||
TextChange nextSoftWrap = softWraps.get(i + 1);
|
||||
int result = editor.offsetToVisualPosition(nextSoftWrap.getStart() - 1).column;
|
||||
|
||||
// We need to add '1' because current column points to the last symbol before the next soft wrap;
|
||||
result++;
|
||||
|
||||
int lineFeedIndex = StringUtil.indexOf(nextSoftWrap.getText(), '\n');
|
||||
result += calcColumnNumber(editor, nextSoftWrap.getText(), 0, lineFeedIndex);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Target visual column is the one before line feed introduced by the current soft wrap.
|
||||
int softWrapStartOffset = 0;
|
||||
int softWrapEndOffset = 0;
|
||||
int softWrapTextLength = softWrap.getText().length();
|
||||
while (visualLinesToSkip-- > 0) {
|
||||
softWrapStartOffset = softWrapEndOffset + 1;
|
||||
if (softWrapStartOffset >= softWrapTextLength) {
|
||||
assert false;
|
||||
return resVisEnd.column;
|
||||
}
|
||||
softWrapEndOffset = StringUtil.indexOf(softWrap.getText(), '\n', softWrapStartOffset, softWrapTextLength);
|
||||
if (softWrapEndOffset < 0) {
|
||||
assert false;
|
||||
return resVisEnd.column;
|
||||
}
|
||||
}
|
||||
int result = editor.offsetToVisualPosition(softWrap.getStart() - 1).column;
|
||||
result += calcColumnNumber(editor, softWrap.getText(), softWrapStartOffset, softWrapEndOffset);
|
||||
return result;
|
||||
}
|
||||
|
||||
assert false;
|
||||
return resVisEnd.column;
|
||||
}
|
||||
|
||||
public static float calcVerticalScrollProportion(Editor editor) {
|
||||
Rectangle viewRect = editor.getScrollingModel().getVisibleAreaOnScrollingFinished();
|
||||
if (viewRect.height == 0) {
|
||||
Rectangle viewArea = editor.getScrollingModel().getVisibleAreaOnScrollingFinished();
|
||||
if (viewArea.height == 0) {
|
||||
return 0;
|
||||
}
|
||||
LogicalPosition pos = editor.getCaretModel().getLogicalPosition();
|
||||
Point location = editor.logicalPositionToXY(pos);
|
||||
return (location.y - viewRect.y) / (float) viewRect.height;
|
||||
return (location.y - viewArea.y) / (float) viewArea.height;
|
||||
}
|
||||
|
||||
public static void setVerticalScrollProportion(Editor editor, float proportion) {
|
||||
Rectangle viewRect = editor.getScrollingModel().getVisibleArea();
|
||||
Rectangle viewArea = editor.getScrollingModel().getVisibleArea();
|
||||
LogicalPosition caretPosition = editor.getCaretModel().getLogicalPosition();
|
||||
Point caretLocation = editor.logicalPositionToXY(caretPosition);
|
||||
int yPos = caretLocation.y;
|
||||
yPos -= viewRect.height * proportion;
|
||||
yPos -= viewArea.height * proportion;
|
||||
editor.getScrollingModel().scrollVertically(yPos);
|
||||
}
|
||||
|
||||
@@ -163,6 +223,10 @@ public class EditorUtil {
|
||||
return tabSize - colNumber % tabSize;
|
||||
}
|
||||
|
||||
public static int calcColumnNumber(Editor editor, CharSequence text, int start, int offset) {
|
||||
return calcColumnNumber(editor, text, start, offset, getTabSize(editor));
|
||||
}
|
||||
|
||||
public static int calcColumnNumber(Editor editor, CharSequence text, int start, int offset, int tabSize) {
|
||||
boolean useOptimization = true;
|
||||
boolean hasNonTabs = false;
|
||||
|
||||
+5
-5
@@ -239,7 +239,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
else {
|
||||
g.setColor(Color.white);
|
||||
int x = getWhitespaceSeparatorOffset() - 1;
|
||||
UIUtil.drawVDottedLine((Graphics2D)g, x, clip.y, clip.y + clip.height, myEditor.getBackroundColor(), getFoldingColor(false));
|
||||
UIUtil.drawVDottedLine((Graphics2D)g, x, clip.y, clip.y + clip.height, myEditor.getBackgroundColor(), getFoldingColor(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,7 +693,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
int lineX = getWhitespaceSeparatorOffset();
|
||||
paintBackground(g, clip, getFoldingAreaOffset(), getFoldingAreaWidth());
|
||||
|
||||
g.setColor(myEditor.getBackroundColor());
|
||||
g.setColor(myEditor.getBackgroundColor());
|
||||
g.fillRect(lineX, clip.y, getFoldingAreaWidth(), clip.height);
|
||||
|
||||
paintCaretRowBackground(g, lineX, getFoldingAnchorWidth());
|
||||
@@ -705,7 +705,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
if (!isFoldingOutlineShown()) return;
|
||||
Rectangle clip = g.getClipBounds();
|
||||
|
||||
UIUtil.drawVDottedLine(g, getWhitespaceSeparatorOffset(), clip.y, clip.y + clip.height, myEditor.getBackroundColor(), getFoldingColor(false));
|
||||
UIUtil.drawVDottedLine(g, getWhitespaceSeparatorOffset(), clip.y, clip.y + clip.height, myEditor.getBackgroundColor(), getFoldingColor(false));
|
||||
|
||||
int anchorX = getFoldingAreaOffset();
|
||||
int width = getFoldingAnchorWidth();
|
||||
@@ -814,7 +814,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
int[] yPoints = {y, y, y + baseHeight, y + height, y + baseHeight};
|
||||
|
||||
if (paintBackground) {
|
||||
g.setColor(myEditor.getBackroundColor());
|
||||
g.setColor(myEditor.getBackgroundColor());
|
||||
|
||||
g.fillPolygon(xPoints, yPoints, 5);
|
||||
}
|
||||
@@ -850,7 +850,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
|
||||
boolean active,
|
||||
boolean paintBackground) {
|
||||
if (paintBackground) {
|
||||
g.setColor(myEditor.getBackroundColor());
|
||||
g.setColor(myEditor.getBackgroundColor());
|
||||
g.fillRect(anchorX, y, width, width);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -959,13 +959,15 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
}
|
||||
|
||||
public LogicalPosition offsetToLogicalPosition(int offset, boolean softWrapAware) {
|
||||
if (softWrapAware) {
|
||||
return mySoftWrapModel.offsetToLogicalPosition(offset);
|
||||
}
|
||||
|
||||
int line = calcLogicalLineNumber(offset, false);
|
||||
int column = calcColumnNumber(offset, line, false);
|
||||
return new LogicalPosition(line, column);
|
||||
LogicalPosition position = new LogicalPosition(line, column);
|
||||
if (softWrapAware) {
|
||||
return mySoftWrapModel.adjustLogicalPosition(position, offset);
|
||||
}
|
||||
else {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -1284,8 +1286,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle viewRect = getScrollingModel().getVisibleArea();
|
||||
if (viewRect == null) {
|
||||
Rectangle visibleArea = getScrollingModel().getVisibleArea();
|
||||
if (visibleArea == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1374,7 +1376,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
return myScheme.getDefaultForeground();
|
||||
}
|
||||
|
||||
public Color getBackroundColor() {
|
||||
public Color getBackgroundColor() {
|
||||
if (myForcedBackground != null) return myForcedBackground;
|
||||
|
||||
return getBackgroundIgnoreForced();
|
||||
@@ -1382,7 +1384,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
|
||||
private Color getBackgroundColor(final TextAttributes attributes) {
|
||||
final Color attrColor = attributes.getBackgroundColor();
|
||||
return attrColor == myScheme.getDefaultBackground() ? getBackroundColor() : attrColor;
|
||||
return attrColor == myScheme.getDefaultBackground() ? getBackgroundColor() : attrColor;
|
||||
}
|
||||
|
||||
private Color getBackgroundIgnoreForced() {
|
||||
@@ -1501,7 +1503,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
|
||||
@SuppressWarnings({"StatementWithEmptyBody"})
|
||||
private void paintBackgrounds(Graphics g, Rectangle clip) {
|
||||
Color defaultBackground = getBackroundColor();
|
||||
Color defaultBackground = getBackgroundColor();
|
||||
g.setColor(defaultBackground);
|
||||
g.fillRect(clip.x, clip.y, clip.width, clip.height);
|
||||
|
||||
@@ -2140,7 +2142,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
g.setColor(savedColor);
|
||||
}
|
||||
else if (effectType == EffectType.BOLD_DOTTED_LINE) {
|
||||
final Color bgColor = getBackroundColor();
|
||||
final Color bgColor = getBackgroundColor();
|
||||
final int dottedAt = SystemInfo.isMac ? y : y + 1;
|
||||
UIUtil.drawBoldDottedLine((Graphics2D)g, xStart, xEnd, dottedAt, bgColor, effectColor, false);
|
||||
}
|
||||
@@ -2598,12 +2600,14 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
throw new IndexOutOfBoundsException("Wrong offset: " + offset + " textLength: " + textLength);
|
||||
}
|
||||
|
||||
int lineIndex = myDocument.getLineNumber(offset);
|
||||
LOG.assertTrue(lineIndex >= 0 && lineIndex < myDocument.getLineCount());
|
||||
|
||||
if (softWrapAware) {
|
||||
return mySoftWrapModel.offsetToLogicalPosition(offset).line;
|
||||
int column = calcColumnNumber(offset, lineIndex, false);
|
||||
return mySoftWrapModel.adjustLogicalPosition(new LogicalPosition(lineIndex, column), offset).line;
|
||||
}
|
||||
else {
|
||||
int lineIndex = myDocument.getLineNumber(offset);
|
||||
LOG.assertTrue(lineIndex >= 0 && lineIndex < myDocument.getLineCount());
|
||||
return lineIndex;
|
||||
}
|
||||
}
|
||||
@@ -2615,14 +2619,17 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
public int calcColumnNumber(int offset, int lineIndex, boolean softWrapAware) {
|
||||
if (myDocument.getTextLength() == 0) return 0;
|
||||
|
||||
CharSequence text = myDocument.getCharsSequence();
|
||||
int start = myDocument.getLineStartOffset(lineIndex);
|
||||
if (start == offset) return 0;
|
||||
int column = EditorUtil.calcColumnNumber(this, text, start, offset, EditorUtil.getTabSize(this));
|
||||
|
||||
if (softWrapAware) {
|
||||
return mySoftWrapModel.offsetToLogicalPosition(offset).column;
|
||||
int line = calcLogicalLineNumber(offset, false);
|
||||
return mySoftWrapModel.adjustLogicalPosition(new LogicalPosition(line, column), offset).column;
|
||||
}
|
||||
else {
|
||||
CharSequence text = myDocument.getCharsSequence();
|
||||
int start = myDocument.getLineStartOffset(lineIndex);
|
||||
if (start == offset) return 0;
|
||||
return EditorUtil.calcColumnNumber(this, text, start, offset, EditorUtil.getTabSize(this));
|
||||
return column;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3148,7 +3155,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
}
|
||||
else {
|
||||
Color background = myScheme.getColor(EditorColors.CARET_ROW_COLOR);
|
||||
if (background == null) background = getBackroundColor();
|
||||
if (background == null) background = getBackgroundColor();
|
||||
g.setXORMode(background);
|
||||
|
||||
g.fillRect(x, y, myWidth, lineHeight - 1);
|
||||
@@ -3668,6 +3675,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
return r[0];
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public AttributedCharacterIterator cancelLatestCommittedText(AttributedCharacterIterator.Attribute[] attributes) {
|
||||
return null;
|
||||
}
|
||||
@@ -3707,6 +3715,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
return r;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TextHitInfo getLocationOffset(int x, int y) {
|
||||
if (composedText != null) {
|
||||
Point p = getContentComponent().getLocationOnScreen();
|
||||
|
||||
+8
-1
@@ -559,11 +559,14 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
public void paint(Graphics g) {
|
||||
((ApplicationImpl)ApplicationManager.getApplication()).editorPaintStart();
|
||||
|
||||
final Rectangle bounds = getBounds();
|
||||
|
||||
g.setColor(myEditor.getBackgroundColor());
|
||||
g.fillRect(0, 0, bounds.width, bounds.height);
|
||||
|
||||
g.setColor(ButtonlessScrollBarUI.TRACK_BACKGROUND);
|
||||
g.fillRect(3, 0, bounds.width, bounds.height);
|
||||
|
||||
@@ -626,6 +629,10 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
|
||||
@Override
|
||||
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
|
||||
Rectangle bounds = new Rectangle(trackBounds);
|
||||
|
||||
g.setColor(myEditor.getBackgroundColor());
|
||||
g.fillRect(0, 0, bounds.width, bounds.height);
|
||||
|
||||
bounds.width /= 1.20;
|
||||
final int shift = trackBounds.width - bounds.width;
|
||||
|
||||
|
||||
@@ -116,6 +116,32 @@ public class SoftWrapModelImpl implements SoftWrapModelEx {
|
||||
return i >= 0 ? myWraps.get(i) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<TextChange> getSoftWrapsForLine(int documentLine) {
|
||||
Document document = myEditor.getDocument();
|
||||
int start = document.getLineStartOffset(documentLine);
|
||||
int end = document.getLineEndOffset(documentLine);
|
||||
|
||||
int i = getSoftWrapIndex(start);
|
||||
if (i < 0) {
|
||||
i = -i - 1;
|
||||
}
|
||||
|
||||
List<TextChange> result = null;
|
||||
for (; i < myWraps.size(); i++) {
|
||||
TextChange softWrap = myWraps.get(i);
|
||||
if (softWrap.getStart() >= end) {
|
||||
break;
|
||||
}
|
||||
if (result == null) {
|
||||
result = new ArrayList<TextChange>();
|
||||
}
|
||||
result.add(softWrap);
|
||||
}
|
||||
return result == null ? Collections.<TextChange>emptyList() : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find index of the target soft wrap stored at {@link #myWraps} collection. <code>'Target'</code> soft wrap is the one
|
||||
* that starts at the given offset.
|
||||
@@ -253,7 +279,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx {
|
||||
|
||||
@NotNull
|
||||
public LogicalPosition adjustLogicalPosition(@NotNull LogicalPosition defaultLogical, @NotNull VisualPosition visual) {
|
||||
if (myActive > 0 || !isSoftWrappingEnabled() || myWraps.isEmpty()) {
|
||||
if (myActive > 0 || !isSoftWrappingEnabled() || myWraps.isEmpty() || myEditor.getDocument().getTextLength() <= 0) {
|
||||
return defaultLogical;
|
||||
}
|
||||
|
||||
@@ -453,21 +479,21 @@ public class SoftWrapModelImpl implements SoftWrapModelEx {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LogicalPosition offsetToLogicalPosition(int offset) {
|
||||
public LogicalPosition adjustLogicalPosition(LogicalPosition defaultLogical, int offset) {
|
||||
if (myActive > 0 || !isSoftWrappingEnabled()) {
|
||||
return myEditor.offsetToLogicalPosition(offset, false);
|
||||
return defaultLogical;
|
||||
}
|
||||
|
||||
myActive++;
|
||||
try {
|
||||
return doOffsetToLogicalPosition(offset);
|
||||
return offsetToLogicalPosition(offset);
|
||||
} finally {
|
||||
myActive--;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"AssignmentToForLoopParameter"})
|
||||
private LogicalPosition doOffsetToLogicalPosition(int offset) {
|
||||
private LogicalPosition offsetToLogicalPosition(int offset) {
|
||||
DocumentImpl document = (DocumentImpl)myEditor.getDocument();
|
||||
CharSequence chars = document.getCharsNoThreadCheck();
|
||||
|
||||
@@ -660,11 +686,11 @@ public class SoftWrapModelImpl implements SoftWrapModelEx {
|
||||
softWrapIndex = -softWrapIndex - 1;
|
||||
}
|
||||
|
||||
if (softWrapIndex >= myWraps.size()) {
|
||||
Document document = myEditor.getDocument();
|
||||
|
||||
if (softWrapIndex >= myWraps.size() || document.getTextLength() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Document document = myEditor.getDocument();
|
||||
int firstChangedLine = document.getLineNumber(change.getStart());
|
||||
int lastChangedLine = Math.max(document.getLineNumber(change.getEnd()), firstChangedLine + StringUtil.countNewLines(change.getText()));
|
||||
for (int i = firstChangedLine; i <= lastChangedLine; i++) {
|
||||
@@ -759,7 +785,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx {
|
||||
}
|
||||
|
||||
private int toVisualColumnSymbolsNumber(CharSequence text, int start, int end) {
|
||||
return EditorUtil.calcColumnNumber(myEditor, text, start, end, EditorUtil.getTabSize(myEditor));
|
||||
return EditorUtil.calcColumnNumber(myEditor, text, start, end);
|
||||
}
|
||||
|
||||
private class Context {
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class TextComponentCaretModel implements CaretModel {
|
||||
}
|
||||
|
||||
public void moveToVisualPosition(final VisualPosition pos) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
moveToLogicalPosition(myEditor.visualToLogicalPosition(pos));
|
||||
}
|
||||
|
||||
public void moveToOffset(final int offset) {
|
||||
|
||||
+14
@@ -19,6 +19,10 @@ import com.intellij.openapi.editor.SoftWrapModel;
|
||||
import com.intellij.openapi.editor.TextChange;
|
||||
import com.intellij.openapi.editor.VisualPosition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
@@ -26,14 +30,24 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class TextComponentSoftWrapModel implements SoftWrapModel {
|
||||
|
||||
@Override
|
||||
public boolean isSoftWrappingEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TextChange getSoftWrap(int offset) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TextChange> getSoftWrapsForLine(int documentLine) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeDocumentChange(@NotNull VisualPosition position) {
|
||||
}
|
||||
}
|
||||
|
||||
+13
-25
@@ -147,6 +147,18 @@ final class EditorTabbedContainer implements Disposable, CloseAction.CloseTarget
|
||||
|
||||
UISettings uiSettings = UISettings.getInstance();
|
||||
|
||||
List<String> topIds = mgr.getIdsOn(ToolWindowAnchor.TOP);
|
||||
List<String> bottom = mgr.getIdsOn(ToolWindowAnchor.BOTTOM);
|
||||
List<String> rightIds = mgr.getIdsOn(ToolWindowAnchor.RIGHT);
|
||||
List<String> leftIds = mgr.getIdsOn(ToolWindowAnchor.LEFT);
|
||||
|
||||
if (!uiSettings.HIDE_TOOL_STRIPES) {
|
||||
border.top = topIds.size() > 0 ? 1: 0;
|
||||
border.bottom = bottom.size() > 0 ? 1: 0;
|
||||
border.left = leftIds.size() > 0 ? 1: 0;
|
||||
border.right = rightIds.size() > 0 ? 1: 0;
|
||||
}
|
||||
|
||||
for (String each : ids) {
|
||||
ToolWindow eachWnd = mgr.getToolWindow(each);
|
||||
if (!eachWnd.isAvailable()) continue;
|
||||
@@ -160,35 +172,11 @@ final class EditorTabbedContainer implements Disposable, CloseAction.CloseTarget
|
||||
} else if (eachAnchor == ToolWindowAnchor.LEFT) {
|
||||
border.left = 1;
|
||||
} else if (eachAnchor == ToolWindowAnchor.RIGHT) {
|
||||
border.right = 1;
|
||||
border.right = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!uiSettings.HIDE_TOOL_STRIPES) {
|
||||
if (mgr.getIdsOn(ToolWindowAnchor.TOP).size() > 0) {
|
||||
border.top = 1;
|
||||
}
|
||||
|
||||
if (mgr.getIdsOn(ToolWindowAnchor.BOTTOM).size() > 0) {
|
||||
border.bottom = 1;
|
||||
}
|
||||
|
||||
if (mgr.getIdsOn(ToolWindowAnchor.LEFT).size() > 0) {
|
||||
border.left = 1;
|
||||
}
|
||||
|
||||
if (mgr.getIdsOn(ToolWindowAnchor.RIGHT).size() > 0) {
|
||||
border.right = 1;
|
||||
}
|
||||
|
||||
if (!uiSettings.SHOW_STATUS_BAR && !uiSettings.HIDE_TOOL_STRIPES) {
|
||||
border.bottom = 1;
|
||||
}
|
||||
}
|
||||
|
||||
myTabs.getComponent().setBorder(new EmptyBorder(1, 0, 0, 0));
|
||||
|
||||
myTabs.getPresentation().setPaintBorder(border.top, border.left, border.right, border.bottom).setTabSidePaintBorder(5);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,12 +46,14 @@ import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.EventListenerList;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Belyaev
|
||||
@@ -429,6 +431,7 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa
|
||||
|
||||
contentPane.add(inner, BorderLayout.CENTER);
|
||||
add(contentPane, BorderLayout.CENTER);
|
||||
setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
|
||||
// Add listeners
|
||||
registerKeyboardAction(new ActionListener() {
|
||||
@@ -448,21 +451,83 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa
|
||||
|
||||
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
|
||||
g.setColor(UIUtil.getBorderInactiveColor());
|
||||
UIUtil.drawLine(g, x, y, x, y + height - 2);
|
||||
UIUtil.drawLine(g, x + width - 1, y, x + width - 1, y + height - 2);
|
||||
|
||||
if (hasBottomLine()) {
|
||||
UIUtil.drawLine(g, x + 1, y + height - 1, x + width - 2, y + height - 1);
|
||||
Insets insets = getBorderInsets(c);
|
||||
|
||||
if (insets.left > 0) {
|
||||
UIUtil.drawLine(g, x, y, x, y + height - 2);
|
||||
}
|
||||
|
||||
if (insets.right > 0) {
|
||||
UIUtil.drawLine(g, x + width - 1, y, x + width - 1, y + height - 2);
|
||||
}
|
||||
|
||||
if (insets.bottom > 0) {
|
||||
UIUtil.drawLine(g, x + 1, y + height - 1, x + width - 2, y + height - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasBottomLine() {
|
||||
return (myWindow.getAnchor() == ToolWindowAnchor.BOTTOM || myWindow.getAnchor() == ToolWindowAnchor.LEFT || myWindow.getAnchor() == ToolWindowAnchor.RIGHT)
|
||||
&& !UISettings.getInstance().HIDE_TOOL_STRIPES && UISettings.getInstance().SHOW_STATUS_BAR;
|
||||
&& !UISettings.getInstance().HIDE_TOOL_STRIPES && UISettings.getInstance().SHOW_STATUS_BAR || (myWindow.getAnchor() == ToolWindowAnchor.TOP);
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(final Component c) {
|
||||
return new Insets(0, 1, hasBottomLine() ? 1 : 0, 1);
|
||||
UISettings settings = UISettings.getInstance();
|
||||
|
||||
ToolWindowManagerImpl mgr = ((ToolWindowImpl)myWindow).getToolWindowManager();
|
||||
|
||||
List<String> topIds = mgr.getIdsOn(ToolWindowAnchor.TOP);
|
||||
boolean topButtons = !settings.HIDE_TOOL_STRIPES && topIds.size() > 0;
|
||||
boolean windowAtTop = hasDockedVisible(mgr, topIds);
|
||||
|
||||
List<String> bottomIds = mgr.getIdsOn(ToolWindowAnchor.BOTTOM);
|
||||
boolean bottomButtons = !settings.HIDE_TOOL_STRIPES && bottomIds.size() > 0;
|
||||
boolean windowAtBottom = hasDockedVisible(mgr, bottomIds);
|
||||
|
||||
List<String> leftIds = mgr.getIdsOn(ToolWindowAnchor.LEFT);
|
||||
boolean leftButtons = !settings.HIDE_TOOL_STRIPES && leftIds.size() > 0;
|
||||
boolean windowAtLeft = hasDockedVisible(mgr, leftIds);
|
||||
|
||||
List<String> rightIds = mgr.getIdsOn(ToolWindowAnchor.RIGHT);
|
||||
boolean rightBottoms = !settings.HIDE_TOOL_STRIPES && rightIds.size() > 0;
|
||||
boolean windowAtRight = hasDockedVisible(mgr, rightIds);
|
||||
|
||||
Insets insets = new Insets(0, 0, 0, 0);
|
||||
if (myWindow.getAnchor() == ToolWindowAnchor.TOP) {
|
||||
insets.top = topButtons ? 1 : 0;
|
||||
insets.left = leftButtons ? 1: 0;
|
||||
insets.right = rightBottoms ? 1: 0;
|
||||
insets.bottom = 1;
|
||||
} else if (myWindow.getAnchor() == ToolWindowAnchor.BOTTOM) {
|
||||
insets.top = 0;
|
||||
insets.left = leftButtons ? 1 : 0;
|
||||
insets.right = rightBottoms ? 1: 0;
|
||||
insets.bottom = bottomButtons ? 1 : 0;
|
||||
} else if (myWindow.getAnchor() == ToolWindowAnchor.LEFT) {
|
||||
insets.top = topButtons && !windowAtTop ? 1 : 0;
|
||||
insets.left = leftButtons ? 1: 0;
|
||||
insets.right = 0;
|
||||
insets.bottom = bottomButtons && !windowAtBottom ? 1 : 0;
|
||||
} else if (myWindow.getAnchor() == ToolWindowAnchor.RIGHT) {
|
||||
insets.top = topButtons && !windowAtTop ? 1: 0;
|
||||
insets.left = 1;
|
||||
insets.right = rightBottoms ? 1: 0;
|
||||
insets.bottom = bottomButtons && !windowAtBottom ? 1: 0;
|
||||
}
|
||||
|
||||
return insets;
|
||||
}
|
||||
|
||||
private boolean hasDockedVisible(ToolWindowManager mgr, List<String> ids) {
|
||||
for (String each : ids) {
|
||||
ToolWindow eachWnd = mgr.getToolWindow(each);
|
||||
if (eachWnd.isVisible()) {
|
||||
if (eachWnd.getType() == ToolWindowType.DOCKED) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBorderOpaque() {
|
||||
|
||||
@@ -60,7 +60,7 @@ public final class TitlePanel extends JPanel {
|
||||
|
||||
public final static Color ACTIVE_SIDE_BUTTON_BG = new Color(179, 197, 231);
|
||||
public final static Color INACTIVE_SIDE_BUTTON_BG = new Color(200, 200, 200);
|
||||
public static final int STRUT = 1;
|
||||
public static final int STRUT = 0;
|
||||
|
||||
TitlePanel() {
|
||||
super(new BorderLayout());
|
||||
|
||||
@@ -92,8 +92,12 @@ final class ToolWindowsPane extends JLayeredPane {
|
||||
// Splitters
|
||||
|
||||
myVerticalSplitter = new ThreeComponentsSplitter(true);
|
||||
myVerticalSplitter.setDividerWidth(0);
|
||||
myVerticalSplitter.setDividerMouseZoneSize(5);
|
||||
myVerticalSplitter.setBackground(Color.gray);
|
||||
myHorizontalSplitter = new ThreeComponentsSplitter(false);
|
||||
myHorizontalSplitter.setDividerWidth(0);
|
||||
myHorizontalSplitter.setDividerMouseZoneSize(5);
|
||||
myHorizontalSplitter.setBackground(Color.gray);
|
||||
|
||||
myVerticalSplitter.setInnerComponent(myHorizontalSplitter);
|
||||
|
||||
@@ -145,7 +145,7 @@ public class PatternCompilerImpl<T> implements PatternCompiler<T> {
|
||||
curFrame.state = ch == '('? State.param_start : State.name_end;
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("'"+curString+ch+"' method name start is invalid");
|
||||
throw new IllegalStateException("'"+curString+ch+"' method name start is invalid, '(' expected");
|
||||
}
|
||||
break;
|
||||
case name_end:
|
||||
|
||||
@@ -21,8 +21,6 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ui.AbstractTableCellEditor;
|
||||
import com.intellij.util.ui.CellEditorComponentWithBrowseButton;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -45,12 +43,7 @@ public class LocalPathCellEditor extends AbstractTableCellEditor {
|
||||
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, int column) {
|
||||
ActionListener listener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FileChooserDescriptor d = new FileChooserDescriptor(false, true, false, true, false, false);
|
||||
if (myTitle != null) {
|
||||
d.setTitle(myTitle);
|
||||
}
|
||||
d.setShowFileSystemRoots(true);
|
||||
|
||||
final FileChooserDescriptor d = getFileChooserDescriptor();
|
||||
VirtualFile initialFile = LocalFileSystem.getInstance().findFileByPath((String)getCellEditorValue());
|
||||
VirtualFile[] files = FileChooser.chooseFiles(table, d, initialFile);
|
||||
if (files.length == 1 && files[0] != null) {
|
||||
@@ -66,4 +59,13 @@ public class LocalPathCellEditor extends AbstractTableCellEditor {
|
||||
myComponent.getChildComponent().setText((String)value);
|
||||
return myComponent;
|
||||
}
|
||||
|
||||
public FileChooserDescriptor getFileChooserDescriptor() {
|
||||
FileChooserDescriptor d = new FileChooserDescriptor(false, true, false, true, false, false);
|
||||
if (myTitle != null) {
|
||||
d.setTitle(myTitle);
|
||||
}
|
||||
d.setShowFileSystemRoots(true);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,7 @@ intention.add.single.member.static.import.text=Add static import for ''{0}''
|
||||
intention.replace.concatenation.with.formatted.output.family=Replace Concatenation with Formatted Output
|
||||
intention.replace.concatenation.with.formatted.output.text=Replace + with java.text.MessageFormat call
|
||||
intention.color.chooser.dialog=Choose Color
|
||||
intention.convert.to.basic.latin=Convert to Basic Latin
|
||||
dialog.create.field.from.parameter.title=Create Field
|
||||
dialog.create.field.from.parameter.already.exists.text=Use existing field {0}?
|
||||
dialog.create.field.from.parameter.already.exists.title=Field Already Exists
|
||||
|
||||
@@ -435,8 +435,6 @@
|
||||
<className>com.intellij.codeInsight.intention.impl.EditFoldingOptionsAction</className>
|
||||
</intentionAction>
|
||||
|
||||
<resolveScopeEnlarger implementation="com.intellij.psi.NonClasspathResolveScopeEnlarger"/>
|
||||
|
||||
<!-- CodeInsightSettings -->
|
||||
<editorActionHandler action="EditorEnter" implementationClass="com.intellij.codeInsight.editorActions.EnterHandler"/>
|
||||
<editorActionHandler action="EditorLineEnd" implementationClass="com.intellij.codeInsight.editorActions.EndHandler"/>
|
||||
|
||||
@@ -417,7 +417,7 @@ public class PersistentEnumerator<Data> implements Forceable {
|
||||
Bits.putInt(buf, KEY_REF_OFFSET, dataOffset);
|
||||
}
|
||||
|
||||
public boolean iterateData(final Processor<Data> processor) throws IOException {
|
||||
protected boolean iterateData(final Processor<Data> processor) throws IOException {
|
||||
if (myKeyStorage == null) {
|
||||
throw new UnsupportedOperationException("Iteration over InlineIntegerKeyDescriptors is not supported");
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.command.CommandAdapter;
|
||||
import com.intellij.openapi.command.CommandEvent;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vcs.actions.VcsContextFactory;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManager;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
@@ -276,10 +276,16 @@ public abstract class VcsVFSListener implements Disposable {
|
||||
|
||||
public void beforePropertyChange(final VirtualFilePropertyEvent event) {
|
||||
if (!isEventIgnored(event) && event.getPropertyName().equalsIgnoreCase(VirtualFile.PROP_NAME)) {
|
||||
final VirtualFile file = event.getFile();
|
||||
final VirtualFile parent = file.getParent();
|
||||
if (parent != null) {
|
||||
addFileToMove(file, parent.getPath(), (String)event.getNewValue());
|
||||
String oldName = (String) event.getOldValue();
|
||||
String newName = (String) event.getNewValue();
|
||||
// in order to force a reparse of a file, the rename event can be fired with old name equal to new name -
|
||||
// such events needn't be handled by the VCS
|
||||
if (!Comparing.equal(oldName, newName)) {
|
||||
final VirtualFile file = event.getFile();
|
||||
final VirtualFile parent = file.getParent();
|
||||
if (parent != null) {
|
||||
addFileToMove(file, parent.getPath(), newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -30,7 +30,7 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsBundle;
|
||||
import com.intellij.openapi.vcs.changes.patch.RelativePathCalculator;
|
||||
import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager;
|
||||
import com.intellij.openapi.vcs.impl.ExcludedFileIndex;
|
||||
import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -53,6 +53,7 @@ public class PathsVerifier<BinaryType extends FilePatch> {
|
||||
private final List<Pair<VirtualFile, ApplyFilePatchBase<BinaryType>>> myBinaryPatches;
|
||||
private final List<VirtualFile> myWritableFiles;
|
||||
private final BaseMapper myBaseMapper;
|
||||
private ProjectLevelVcsManager myVcsManager;
|
||||
|
||||
public PathsVerifier(final Project project, final VirtualFile baseDirectory, final List<FilePatch> patches, BaseMapper baseMapper) {
|
||||
myProject = project;
|
||||
@@ -66,6 +67,7 @@ public class PathsVerifier<BinaryType extends FilePatch> {
|
||||
myTextPatches = new ArrayList<Pair<VirtualFile, ApplyTextFilePatch>>();
|
||||
myBinaryPatches = new ArrayList<Pair<VirtualFile, ApplyFilePatchBase<BinaryType>>>();
|
||||
myWritableFiles = new ArrayList<VirtualFile>();
|
||||
myVcsManager = ProjectLevelVcsManager.getInstance(myProject);
|
||||
}
|
||||
|
||||
// those to be moved to CL: target + created dirs
|
||||
@@ -279,13 +281,16 @@ public class PathsVerifier<BinaryType extends FilePatch> {
|
||||
|
||||
protected boolean checkModificationValid(final VirtualFile file, final String name) {
|
||||
// security check to avoid overwriting system files with a patch
|
||||
if ((file == null) || (! ExcludedFileIndex.getInstance(myProject).isInContent(file)) ||
|
||||
(ProjectLevelVcsManager.getInstance(myProject).getVcsRootFor(file) == null)) {
|
||||
if ((file == null) || (!inContent(file)) || (myVcsManager.getVcsRootFor(file) == null)) {
|
||||
setErrorMessage("File to patch found outside content root: " + name);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean inContent(VirtualFile file) {
|
||||
return ((ProjectLevelVcsManagerImpl) myVcsManager).isFileInContent(file);
|
||||
}
|
||||
}
|
||||
|
||||
private void addPatch(final FilePatch patch, final VirtualFile file) {
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ public class ShelveChangesCommitExecutor implements CommitExecutor {
|
||||
ChangeList changeList = ChangesUtil.getChangeListIfOnlyOne(myProject, changesArray);
|
||||
if (changeList instanceof LocalChangeList) {
|
||||
LocalChangeList localChangeList = (LocalChangeList) changeList;
|
||||
if (localChangeList.getChanges().size() == changes.size() && !localChangeList.isDefault()) {
|
||||
if (localChangeList.getChanges().size() == changes.size() && !localChangeList.isReadOnly()) {
|
||||
ChangeListManager.getInstance(myProject).removeChangeList(localChangeList.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -784,7 +784,7 @@ public class LineStatusTracker {
|
||||
|
||||
JComponent toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, group, true).getComponent();
|
||||
|
||||
final Color background = ((EditorEx)editor).getBackroundColor();
|
||||
final Color background = ((EditorEx)editor).getBackgroundColor();
|
||||
final Color foreground = editor.getColorsScheme().getColor(EditorColors.CARET_COLOR);
|
||||
toolbar.setBackground(background);
|
||||
|
||||
|
||||
@@ -703,7 +703,9 @@ public void addMessageToConsoleWindow(final String message, final TextAttributes
|
||||
if (file == null) return false;
|
||||
final StorageScheme storageScheme = ((ProjectEx) myProject).getStateStore().getStorageScheme();
|
||||
if (StorageScheme.DIRECTORY_BASED.equals(storageScheme)) {
|
||||
final VirtualFile ideaDir = myProject.getBaseDir().findChild(Project.DIRECTORY_STORE_FOLDER);
|
||||
final VirtualFile baseDir = myProject.getBaseDir();
|
||||
if (baseDir == null) return false;
|
||||
final VirtualFile ideaDir = baseDir.findChild(Project.DIRECTORY_STORE_FOLDER);
|
||||
return (ideaDir != null && ideaDir.isValid() && ideaDir.isDirectory() && VfsUtil.isAncestor(ideaDir, file, false));
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -111,21 +111,6 @@ public class IdeaSpecificSettings {
|
||||
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, JavadocOrderRootType.getInstance(), RELATIVE_MODULE_JAVADOC);
|
||||
modifiableModel.commit();
|
||||
}
|
||||
else {
|
||||
libraryByName = EclipseClasspathReader.findLibraryByName(model.getProject(), libName);
|
||||
if (libraryByName != null) {
|
||||
appendLibraryScope(model, libElement, libraryByName);
|
||||
}
|
||||
final Library[] libraries = model.getModuleLibraryTable().getLibraries();
|
||||
for (Library library : libraries) {
|
||||
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
|
||||
replaceCollapsedByEclipseSourceRoots(libElement, modifiableModel);
|
||||
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.SOURCES, RELATIVE_MODULE_SRC);
|
||||
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, OrderRootType.CLASSES, RELATIVE_MODULE_CLS);
|
||||
replaceModuleRelatedRoots(model.getProject(), modifiableModel, libElement, JavadocOrderRootType.getInstance(), RELATIVE_MODULE_JAVADOC);
|
||||
modifiableModel.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user