Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Trofimov
2012-04-13 16:16:30 +02:00
65 changed files with 1050 additions and 409 deletions
@@ -496,12 +496,12 @@ public class DebuggerManagerImpl extends DebuggerManagerEx {
}
private static boolean shouldAddXdebugKey(Sdk jdk) {
if (jdk == null) {
return true; // conservative choice
}
if (DebuggerSettings.getInstance().DISABLE_JIT) {
return true;
}
if (jdk == null) {
return false; // assume newer jdk by default
}
//if (ApplicationManager.getApplication().isUnitTestMode()) {
// need this in unit tests to avoid false alarms when comparing actual output with expected output
@@ -520,7 +520,7 @@ public class DebuggerManagerImpl extends DebuggerManagerEx {
private static boolean isJVMTIAvailable(Sdk jdk) {
if (jdk == null) {
return true; // assume newer jdk by default
return false; // conservative choice
}
final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
@@ -65,11 +65,16 @@ public abstract class HeaderHidingTabbedModuleEditor extends TabbedModuleEditor
}
@Override
@Nullable
public ModuleConfigurationEditor getEditor(@NotNull String displayName) {
ModuleConfigurationEditor singleEditor = getSingleEditor();
if (singleEditor != null) {
assert singleEditor.getDisplayName().equals(displayName);
return singleEditor;
if (displayName.equals(singleEditor.getDisplayName())) {
return singleEditor;
}
else {
return null;
}
}
else {
return super.getEditor(displayName);
@@ -20,25 +20,26 @@ import com.intellij.codeInsight.completion.simple.ParenthesesTailType;
import com.intellij.codeInsight.completion.simple.RParenthTailType;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
public class TailTypes {
public static final TailType CALL_RPARENTH = new RParenthTailType(){
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && editor.getDocument().getCharsSequence().charAt(tailOffset - 1) != '(';
}
};
public static final TailType IF_RPARENTH = new RParenthTailType(){
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_IF_PARENTHESES;
}
};
public static final TailType WHILE_RPARENTH = new RParenthTailType(){
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_WHILE_PARENTHESES;
}
};
public static final TailType CALL_RPARENTH_SEMICOLON = new RParenthTailType(){
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES;
}
@@ -48,56 +49,56 @@ public class TailTypes {
};
public static final TailType SYNCHRONIZED_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_SYNCHRONIZED_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_SYNCHRONIZED_PARENTHESES;
}
};
public static final TailType CATCH_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_CATCH_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_CATCH_PARENTHESES;
}
};
public static final TailType SWITCH_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_SWITCH_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_SWITCH_PARENTHESES;
}
};
public static final TailType WHILE_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_WHILE_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_WHILE_PARENTHESES;
}
};
public static final TailType FOR_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_FOR_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_FOR_PARENTHESES;
}
};
public static final TailType IF_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_IF_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_IF_PARENTHESES;
}
};
@@ -20,8 +20,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiType;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.jetbrains.annotations.Nullable;
/**
@@ -64,7 +63,7 @@ public class CastingLookupElementDecorator extends LookupElementDecorator<Lookup
@Override
public void handleInsert(InsertionContext context) {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(context.getProject());
final CommonCodeStyleSettings settings = context.getCodeStyleSettings();
String spaceWithin = settings.SPACE_WITHIN_CAST_PARENTHESES ? " " : "";
String spaceAfter = settings.SPACE_AFTER_TYPE_CAST ? " " : "";
final Editor editor = context.getEditor();
@@ -27,8 +27,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
public class DefaultInsertHandler extends TemplateInsertHandler implements Cloneable {
@@ -94,7 +93,7 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
}
}
else{
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
final CommonCodeStyleSettings styleSettings = context.getCodeStyleSettings();
myState.tailOffset = context.getSelectionEndOffset();
myState.caretOffset = context.getSelectionEndOffset();
@@ -30,7 +30,10 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.NullableLazyKey;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.patterns.PsiJavaPatterns;
@@ -66,7 +69,10 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.intellij.patterns.PlatformPatterns.psiElement;
@@ -272,7 +278,7 @@ public class JavaCompletionUtil {
if (element instanceof PsiWhiteSpace &&
( !element.textContains('\n') ||
CodeStyleSettingsManager.getInstance(project).getCurrentSettings().METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
CodeStyleSettingsManager.getSettings(project).getCommonSettings(JavaLanguage.INSTANCE).METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
)
){
element = file.findElementAt(element.getTextRange().getEndOffset());
@@ -541,7 +547,7 @@ public class JavaCompletionUtil {
if (ref != null) {
final PsiElement qualifier = ref.getQualifier();
if (qualifier != null) {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(qualifier.getProject());
final CommonCodeStyleSettings settings = context.getCodeStyleSettings();
final String parenSpace = settings.SPACE_WITHIN_PARENTHESES ? " " : "";
document.insertString(qualifier.getTextRange().getEndOffset(), parenSpace + ")");
@@ -821,7 +827,7 @@ public class JavaCompletionUtil {
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getDocument());
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
final CommonCodeStyleSettings styleSettings = context.getCodeStyleSettings();
ParenthesesInsertHandler.getInstance(hasParams,
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES,
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && hasParams,
@@ -14,8 +14,7 @@ import com.intellij.openapi.editor.ScrollType;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.impl.source.tree.java.PsiEmptyExpressionImpl;
import com.intellij.psi.util.PsiTreeUtil;
@@ -100,7 +99,7 @@ class SmartCastProvider extends CompletionProvider<CompletionParameters> {
context.getOffsetMap().getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET));
}
final CodeStyleSettings csSettings = CodeStyleSettingsManager.getSettings(context.getProject());
final CommonCodeStyleSettings csSettings = context.getCodeStyleSettings();
final int oldTail = context.getTailOffset();
context.setTailOffset(RParenthTailType.addRParenth(editor, oldTail, csSettings.SPACE_WITHIN_CAST_PARENTHESES));
@@ -18,20 +18,19 @@ package com.intellij.codeInsight.completion.simple;
import com.intellij.codeInsight.TailType;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
/**
* @author peter
*/
public abstract class ParenthesesTailType extends TailType {
protected abstract boolean isSpaceBeforeParentheses(CodeStyleSettings styleSettings, Editor editor, final int tailOffset);
protected abstract boolean isSpaceBeforeParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset);
protected abstract boolean isSpaceWithinParentheses(CodeStyleSettings styleSettings, Editor editor, final int tailOffset);
protected abstract boolean isSpaceWithinParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset);
public int processTail(final Editor editor, int tailOffset) {
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject());
CommonCodeStyleSettings styleSettings = getLocalCodeStyleSettings(editor, tailOffset);
if (isSpaceBeforeParentheses(styleSettings, editor, tailOffset)) {
tailOffset = insertChar(editor, tailOffset, ' ');
}
@@ -24,8 +24,7 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.java.IJavaElementType;
@@ -50,10 +49,10 @@ public abstract class RParenthTailType extends TailType {
return element == null ? new TextRange(0, document.getTextLength()) : element.getTextRange();
}
protected abstract boolean isSpaceWithinParentheses(CodeStyleSettings styleSettings, Editor editor, final int tailOffset);
protected abstract boolean isSpaceWithinParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset);
public int processTail(final Editor editor, int tailOffset) {
return addRParenth(editor, tailOffset, isSpaceWithinParentheses(CodeStyleSettingsManager.getSettings(editor.getProject()), editor, tailOffset));
return addRParenth(editor, tailOffset, isSpaceWithinParentheses(getLocalCodeStyleSettings(editor, tailOffset), editor, tailOffset));
}
public static int addRParenth(Editor editor, int offset, boolean spaceWithinParens) {
@@ -353,41 +353,18 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
}
return;
}
refElement.accept(new RefJavaVisitor() {
@Override public void visitElement(final RefEntity elem) {
if (elem instanceof RefElement) {
final RefElement element = (RefElement)elem;
if (isEntryPoint(element)) {
getEntryPointsManager().addEntryPoint(element, false);
}
}
}
refElement.accept(new RefJavaVisitor() {
@Override public void visitMethod(RefMethod method) {
if (isAddMainsEnabled() && method.isAppMain()) {
getEntryPointsManager().addEntryPoint(method, false);
} else {
super.visitMethod(method);
}
}
@Override public void visitClass(RefClass aClass) {
final PsiClass psiClass = aClass.getElement();
if (psiClass == null) return;
if (
isAddAppletEnabled() && aClass.isApplet() ||
isAddServletEnabled() && aClass.isServlet()) {
if (isAddAppletEnabled() && aClass.isApplet() ||
isAddServletEnabled() && aClass.isServlet()) {
getEntryPointsManager().addEntryPoint(aClass, false);
} else if (psiClass.isAnnotationType()){
getEntryPointsManager().addEntryPoint(aClass, false);
final PsiMethod[] psiMethods = psiClass.getMethods();
for (PsiMethod psiMethod : psiMethods) {
getEntryPointsManager().addEntryPoint(getRefManager().getReference(psiMethod), false);
}
} else if (psiClass.isEnum()) {
getEntryPointsManager().addEntryPoint(aClass, false);
} else {
super.visitClass(aClass);
}
}
});
@@ -437,7 +414,7 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
myPhase = 1;
}
private boolean isEntryPoint(final RefElement owner) {
public boolean isEntryPoint(final RefElement owner) {
final PsiElement element = owner.getElement();
if (RefUtil.isImplicitUsage(element)) return true;
if (element instanceof PsiModifierListOwner) {
@@ -907,8 +884,6 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
@Override public void visitElement(RefEntity refEntity) {
if (refEntity instanceof RefJavaElement) {
final RefJavaElementImpl refElement = (RefJavaElementImpl)refEntity;
final PsiElement element = refElement.getElement();
if (element == null) return;
if (!getContext().isToCheckMember(refElement, UnusedDeclarationInspection.this)) return;
refElement.setReachable(false);
}
@@ -15,14 +15,20 @@
*/
package com.intellij.codeInspection.reference;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.SuppressionUtil;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.ex.EntryPointsManager;
import com.intellij.codeInspection.ex.EntryPointsManagerImpl;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.Tools;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.UserDataCache;
import com.intellij.psi.*;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.javadoc.PsiDocTag;
@@ -89,6 +95,41 @@ public class RefJavaManagerImpl extends RefJavaManager {
return refPackage;
}
public boolean isEntryPoint(final RefElement element) {
UnusedDeclarationInspection tool = getDeadCodeTool(element);
return tool != null && tool.isEntryPoint(element);
}
@Nullable
private UnusedDeclarationInspection getDeadCodeTool(RefElement element) {
PsiFile file = ((RefElementImpl)element).getContainingFile();
if (file == null) return null;
return getDeadCodeTool(file);
}
private static final UserDataCache<Ref<UnusedDeclarationInspection>, PsiFile, RefManagerImpl> DEAD_CODE_TOOL = new UserDataCache<Ref<UnusedDeclarationInspection>, PsiFile, RefManagerImpl>("DEAD_CODE_TOOL") {
@Override
protected Ref<UnusedDeclarationInspection> compute(PsiFile file, RefManagerImpl refManager) {
Tools tools = refManager.getContext().getTools().get(UnusedDeclarationInspection.SHORT_NAME);
InspectionProfileEntry tool = tools != null ? tools.getEnabledTool(file) : null;
if (tool instanceof InspectionToolWrapper) tool = ((InspectionToolWrapper)tool).getTool();
return Ref.create(tool instanceof UnusedDeclarationInspection ? (UnusedDeclarationInspection)tool : null);
}
};
@Nullable
private UnusedDeclarationInspection getDeadCodeTool(PsiElement element) {
PsiFile file = element.getContainingFile();
return file != null ? DEAD_CODE_TOOL.get(file, myRefManager).get() : null;
}
public boolean isEntryPoint(PsiElement element) {
UnusedDeclarationInspection tool = getDeadCodeTool(element);
return tool != null && tool.isEntryPoint(element);
}
public RefPackage getDefaultPackage() {
if (myDefaultPackage == null) {
myDefaultPackage = getPackage(InspectionsBundle.message("inspection.reference.default.package"));
@@ -269,6 +310,28 @@ public class RefJavaManagerImpl extends RefJavaManager {
}
}
@Override
public void onEntityInitialized(RefElement refElement, PsiElement psiElement) {
if (isEntryPoint(refElement)) {
getEntryPointsManager().addEntryPoint(refElement, false);
}
if (psiElement instanceof PsiClass) {
PsiClass psiClass = (PsiClass)psiElement;
EntryPointsManager entryPointsManager = getEntryPointsManager();
if (psiClass.isAnnotationType()){
entryPointsManager.addEntryPoint(refElement, false);
for (PsiMethod psiMethod : psiClass.getMethods()) {
entryPointsManager.addEntryPoint(myRefManager.getReference(psiMethod), false);
}
}
else if (psiClass.isEnum()) {
entryPointsManager.addEntryPoint(refElement, false);
}
}
}
private static void appendPackageElement(final Element element, final String packageName) {
final Element packageElement = new Element("package");
packageElement.addContent(packageName.length() > 0 ? packageName : InspectionsBundle.message("inspection.export.results.default"));
@@ -0,0 +1,9 @@
public static class G {
public static void foo(String s1, String s2) {
}
public static void main(String[] args) {
String sss1 = "text";
foo(sss1,<caret>);
}
}
@@ -0,0 +1,9 @@
public static class G {
public static void foo(String s1, String s2) {
}
public static void main(String[] args) {
String sss1 = "text";
foo(ss<caret>);
}
}
@@ -5,10 +5,11 @@ import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInsight.lookup.impl.LookupManagerImpl;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
import com.intellij.testFramework.LightCodeInsightTestCase;
@@ -208,8 +209,9 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{
}
public void testParensInSynchronized() throws Exception{
CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_SYNCHRONIZED_PARENTHESES = false;
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_SYNCHRONIZED_PARENTHESES = true;
CommonCodeStyleSettings styleSettings = getCodeStyleSettings();
styleSettings.SPACE_BEFORE_SYNCHRONIZED_PARENTHESES = false;
styleSettings.SPACE_WITHIN_SYNCHRONIZED_PARENTHESES = true;
final String path = BASE_PATH;
configureByFile(path + "/before22.java");
@@ -254,22 +256,17 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{
public void testCastParensStyle1() throws Exception{
final String path = BASE_PATH;
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
final boolean space_within_cast_parentheses = styleSettings.SPACE_WITHIN_CAST_PARENTHESES;
final boolean space_after_type_cast = styleSettings.SPACE_AFTER_TYPE_CAST;
styleSettings.SPACE_WITHIN_CAST_PARENTHESES = true;
styleSettings.SPACE_AFTER_TYPE_CAST = false;
getCodeStyleSettings().SPACE_WITHIN_CAST_PARENTHESES = true;
getCodeStyleSettings().SPACE_AFTER_TYPE_CAST = false;
configureByFile(path + "/before31.java");
performSmartCompletion();
checkResultByFile(path + "/after31.java");
styleSettings.SPACE_WITHIN_CAST_PARENTHESES = space_within_cast_parentheses;
styleSettings.SPACE_AFTER_TYPE_CAST = space_after_type_cast;
}
public void testMethodParensStyle2() throws Exception{
final String path = BASE_PATH;
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
CommonCodeStyleSettings styleSettings = getCodeStyleSettings();
final boolean space_before_method_call_parentheses = styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES;
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true;
configureByFile(path + "/before32.java");
@@ -278,9 +275,14 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = space_before_method_call_parentheses;
}
private static CommonCodeStyleSettings getCodeStyleSettings() {
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
}
public void testMethodParensStyle3() throws Exception{
final String path = BASE_PATH;
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
CommonCodeStyleSettings styleSettings = getCodeStyleSettings();
final boolean space_before_method_call_parentheses = styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES;
final boolean space_within_method_call_parentheses = styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES;
@@ -22,11 +22,12 @@ import com.intellij.codeInsight.lookup.Lookup
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.codeInsight.lookup.LookupManager
import com.intellij.lang.java.JavaLanguage
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.fileTypes.StdFileTypes
import com.intellij.psi.codeStyle.CodeStyleSettings
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.psi.codeStyle.CommonCodeStyleSettings
import com.intellij.psi.*
public class NormalCompletionTest extends LightFixtureCompletionTestCase {
@@ -287,12 +288,9 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
}
public void testMethodCallBeforeAnotherStatementWithParen2() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
boolean oldvalue = settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE;
settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
codeStyleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
configureByFile("MethodLookup2.java");
checkResultByFile("MethodLookup2_After2.java");
settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = oldvalue;
}
public void testSwitchEnumLabel() throws Exception {
@@ -494,16 +492,14 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testPrivateInAnonymous() throws Throwable { doTest() }
public void testMethodParenthesesSpaces() throws Throwable {
final settings = CodeStyleSettingsManager.getSettings(getProject())
settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
doTest();
}
public void testMethodParenthesesSpacesArgs() throws Throwable {
final settings = CodeStyleSettingsManager.getSettings(getProject())
settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
doTest();
}
@@ -601,23 +597,18 @@ public class ListUtils {
}
public void testNoSpaceInParensWithoutParams() throws Throwable {
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
try {
doTest();
}
finally {
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
}
}
public void testTwoSpacesInParensWithParams() throws Throwable {
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
try {
doTest();
}
finally {
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
}
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
doTest();
}
public void testFillCommonPrefixOnSecondCompletion() throws Throwable {
@@ -1330,6 +1321,10 @@ public class ListUtils {
public void testInterfaceImplementationNoCast() { doTest() }
public void testStaticallyImportedMethodsBeforeExpression() { doTest() }
private CommonCodeStyleSettings getCodeStyleSettings() {
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
}
public void testCompatibleInterfacesCast() {
configure()
assert myFixture.lookupElementStrings.containsAll(['foo', 'bar'])
@@ -12,10 +12,12 @@ import com.intellij.codeInsight.template.TemplateContextType;
import com.intellij.codeInsight.template.TemplateManager;
import com.intellij.codeInsight.template.impl.TemplateImpl;
import com.intellij.codeInsight.template.impl.TemplateSettings;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.util.containers.ContainerUtil;
public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
@@ -92,15 +94,9 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testParenAfterCall1_SpaceWithinMethodCallParens() throws Exception {
String path = "/parenAfterCall";
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
myFixture.configureByFile(path + "/before1.java");
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
try{
complete();
}
finally{
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
}
getCodeStyleSettings().SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
complete();
checkResultByFile(path + "/after1_space.java");
}
@@ -659,14 +655,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testUseIntConstantsInOr() throws Throwable { doTest(); }
public void testExtraSemicolonAfterMethodParam() throws Throwable {
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
try{
doTest();
}
finally{
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
}
getCodeStyleSettings().SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
doTest();
}
public void testAssignFromTheSameFieldOfAnotherObject() throws Throwable {
@@ -1132,7 +1122,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doTest(Lookup.NORMAL_SELECT_CHAR);
}
private void doTest(final char c) throws Exception {
private void doTest(final char c) {
boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION;
if (c != Lookup.NORMAL_SELECT_CHAR) {
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = false;
@@ -1173,4 +1163,12 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
}
public void testSpaceAfterCommaInMethodCall() {
getCodeStyleSettings().SPACE_AFTER_COMMA = false;
doTest(',');
}
private CommonCodeStyleSettings getCodeStyleSettings() {
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
}
}
@@ -20,12 +20,16 @@ import com.intellij.ide.Bootstrap;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.StreamUtil;
import com.intellij.util.Restarter;
import org.jetbrains.annotations.NonNls;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -46,39 +50,30 @@ public class Main {
System.setProperty("jna.nounpack", "false");
}
// pre-load class before installing the patch to prevent class loader problems
Restarter.isSupported();
final int[] restartCode = {Restarter.getRestartCode()};
if (installPatch()) {
boolean restarted = false;
int restartCode = 0;
try {
restarted = Restarter.restart();
restartCode = Restarter.getRestartCode();
Runnable restart = new Runnable() {
@Override
public void run() {
if (restartCode[0] == 0) {
try {
if (Restarter.restart()) restartCode[0] = 1;
}
catch (Throwable ignore) {
}
}
}
catch (Throwable e) {
// can be either CannotRestartException
// or something like class/method not found if they has been changed during update
};
//noinspection CallToPrintStackTrace
e.printStackTrace();
}
if (installPatch(restart)) {
if (restartCode[0] == 0) {
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Throwable ignore) { }
if (!restarted && restartCode == 0) {
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ignore) { }
String msg = "The application cannot start right away since some critical files have been changed.\nPlease restart it manually.";
String msg = "Patch has been applied successfully, please restart application.";
JOptionPane.showMessageDialog(null, msg, "Update", JOptionPane.INFORMATION_MESSAGE);
}
final int finalRestartCode = restartCode;
//noinspection SSBasedInspection
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
System.exit(finalRestartCode);
}
});
System.exit(restartCode[0]);
return;
}
@@ -124,7 +119,7 @@ public class Main {
return isHeadless;
}
private static boolean installPatch() {
private static boolean installPatch(Runnable restart) {
try {
File ideaHomeDir = getIdeaHomeDir();
if (ideaHomeDir == null) return false;
@@ -141,10 +136,12 @@ public class Main {
File launcherFile = new File(ideaHomeDir, "bin/vistalauncher.exe");
File launcherCopy = FileUtil.createTempFile("vistalauncher", ".exe");
launcherCopy.deleteOnExit();
copyFile(launcherFile, launcherCopy);
FileUtil.copy(launcherFile, launcherCopy);
args.add(launcherCopy.getPath());
}
restart.run();
Collections.addAll(args,
System.getProperty("java.home") + "/bin/java",
"-classpath",
@@ -160,13 +157,14 @@ public class Main {
errThread.start();
try {
boolean requiresRestart = process.waitFor() == 42;
return requiresRestart;
process.waitFor();
}
finally {
outThread.join();
errThread.join();
}
return true;
}
finally {
patchFile.delete();
@@ -189,7 +187,7 @@ public class Main {
public void run() {
try {
copyStream(myIn, myOut);
StreamUtil.copyStreamContent(myIn, myOut);
}
catch (IOException e) {
e.printStackTrace();
@@ -217,44 +215,4 @@ public class Main {
return null;
}
}
public static void copyFile(File from, File to) throws IOException {
to.getParentFile().mkdirs();
FileInputStream is = null;
FileOutputStream os = null;
try {
is = new FileInputStream(from);
os = new FileOutputStream(to);
copyStream(is, os);
}
finally {
if (is != null) {
try {
is.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
if (os != null) {
try {
os.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void copyStream(InputStream from, OutputStream to) throws IOException {
byte[] buffer = new byte[65536];
while (true) {
int read = from.read(buffer);
if (read < 0) break;
to.write(buffer, 0, read);
}
}
}
@@ -16,11 +16,16 @@
package com.intellij.codeInsight;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.lang.Language;
import com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.util.PsiUtilBase;
import org.jetbrains.annotations.NotNull;
/**
@@ -72,11 +77,11 @@ public abstract class TailType {
};
public static final TailType SEMICOLON = new CharTailType(';');
public static final TailType EXCLAMATION = new CharTailType('!');
@Deprecated public static final TailType EXCLAMATION = new CharTailType('!');
public static final TailType COMMA = new TailType(){
public int processTail(final Editor editor, int tailOffset) {
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject());
CommonCodeStyleSettings styleSettings = getLocalCodeStyleSettings(editor, tailOffset);
if (styleSettings.SPACE_BEFORE_COMMA) tailOffset = insertChar(editor, tailOffset, ' ');
tailOffset = insertChar(editor, tailOffset, ',');
if (styleSettings.SPACE_AFTER_COMMA) tailOffset = insertChar(editor, tailOffset, ' ');
@@ -87,6 +92,17 @@ public abstract class TailType {
return "COMMA";
}
};
protected static CommonCodeStyleSettings getLocalCodeStyleSettings(Editor editor, int tailOffset) {
Project project = editor.getProject();
assert project != null;
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
assert psiFile != null;
Language language = PsiUtilBase.getLanguageAtOffset(psiFile, tailOffset);
return CodeStyleSettingsManager.getSettings(project).getCommonSettings(language);
}
/**
* insert a space, overtype if already present
*/
@@ -16,11 +16,15 @@
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.lang.Language;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.util.PsiUtilBase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -132,4 +136,9 @@ public class InsertionContext {
public boolean shouldAddCompletionChar() {
return myAddCompletionChar;
}
public CommonCodeStyleSettings getCodeStyleSettings() {
Language lang = PsiUtilBase.getLanguageAtOffset(getFile(), getTailOffset());
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(lang);
}
}
@@ -18,13 +18,13 @@ package com.intellij.codeInspection;
import org.jetbrains.annotations.NotNull;
/**
* This class is for the inspections that are gathered by another inspection,
* This interface is for the inspections that are gathered by another inspection,
* but should be shown under this inspection in the inspections result view.
* This inspection is identified by the problem group, which is stored in the Annotation, HighlightInfo and ProblemDescriptor classes.
*/
public abstract class LocalDummyInspectionTool extends LocalInspectionTool {
public interface DummyInspectionTool {
@NotNull
public abstract String getProblemGroup();
String getProblemGroup();
public abstract boolean shouldBeShownInInspectionProfile();
boolean shouldBeShownInInspectionProfile();
}
@@ -59,4 +59,6 @@ public interface RefManagerExtension<T> {
boolean belongsToScope(final PsiElement psiElement);
void export(final RefEntity refEntity, final Element element);
}
void onEntityInitialized(RefElement refEntity, PsiElement psiElement);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -78,7 +78,7 @@ public class EmacsStyleIndentAction extends BaseCodeInsightAction implements Dum
final int newPos = codeStyleManager.adjustLineIndent(file, lineStart);
final int newCol = newPos - lineStart;
final int lineInc = document.getLineEndOffset(line) - initLineEnd;
if (newCol >= col + lineInc) {
if (newCol >= col + lineInc && newCol >= 0) {
final LogicalPosition pos = new LogicalPosition(line, newCol);
editor.getCaretModel().moveToLogicalPosition(pos);
editor.getSelectionModel().removeSelection();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -36,7 +36,7 @@ public abstract class AbstractElementSignatureProvider implements ElementSignatu
@Nullable
public PsiElement restoreBySignature(@NotNull PsiFile file, @NotNull String signature, @Nullable StringBuilder processingInfoStorage) {
int semicolonIndex = signature.indexOf(';');
int semicolonIndex = signature.indexOf(ELEMENTS_SEPARATOR);
PsiElement parent;
if (semicolonIndex >= 0) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -42,6 +42,9 @@ public class CollapseSelectionHandler implements CodeInsightActionHandler {
if (editor.getSelectionModel().hasSelection()) {
int start = editor.getSelectionModel().getSelectionStart();
int end = editor.getSelectionModel().getSelectionEnd();
if (start + 1 >= end) {
return;
}
Document doc = editor.getDocument();
if (start < end && doc.getCharsSequence().charAt(end-1) == '\n') end--;
FoldRegion region;
@@ -52,7 +55,7 @@ public class CollapseSelectionHandler implements CodeInsightActionHandler {
}
} else if (!foldingModel.intersectsRegion(start, end)) {
region = foldingModel.addFoldRegion(start, end, ourPlaceHolderText);
LOG.assertTrue(region != null);
LOG.assertTrue(region != null, "Fold region is not created. Folding model: " + foldingModel);
region.setExpanded(false);
int offset = Math.min(start + ourPlaceHolderText.length(), doc.getTextLength());
editor.getCaretModel().moveToOffset(offset);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -79,10 +79,21 @@ public class OffsetsElementSignatureProvider extends AbstractElementSignaturePro
PsiElement element = file.findElementAt(start);
if (element != null) {
result = findElement(start, end, index, element, processingInfoStorage);
if (result == null && processingInfoStorage != null) {
processingInfoStorage.append(String.format(
"Failed to find an element by the given offsets. Started by the element '%s' (%s)", element, element.getText()
));
}
}
if (result == null) {
final PsiElement injectedStartElement = InjectedLanguageUtil.findElementAtNoCommit(file, start);
if (processingInfoStorage != null) {
processingInfoStorage.append(String.format(
"Trying to find injected element starting from the '%s'%s%n",
injectedStartElement, injectedStartElement == null ? "" : String.format("(%s)", injectedStartElement.getText())
));
}
if (injectedStartElement != null && injectedStartElement != element) {
result = findElement(start, end, index, injectedStartElement, processingInfoStorage);
}
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.folding.impl;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -67,7 +68,7 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr
else {
if (processingInfoStorage != null) {
processingInfoStorage.append(String.format(
"Stopping '%s' provider because it has top level marker but more than one non white-space child: %s",
"Stopping '%s' provider because it has top level marker but more than one non white-space child: %s%n",
getClass().getName(), Arrays.toString(file.getChildren())
));
}
@@ -77,7 +78,7 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr
}
if (processingInfoStorage != null) {
processingInfoStorage.append(String.format(
"Finished processing of '%s' provider because all of its top-level children have been processed: %s",
"Finished processing of '%s' provider because all of its top-level children have been processed: %s%n",
getClass().getName(), Arrays.toString(file.getChildren())
));
}
@@ -99,10 +100,17 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr
}
if (!tokenizer.hasMoreTokens()) {
if (processingInfoStorage != null) {
processingInfoStorage.append(String.format("Stopping '%s' provider because it has no more data to process%n", getClass().getName()));
}
return null;
}
try {
int index = Integer.parseInt(tokenizer.nextToken());
if (processingInfoStorage != null) {
processingInfoStorage.append(String.format("Looking for the child with a name '%s' # %d at the element '%s'%n",
elementMarker, index, parent));
}
return restoreElementInternal(parent, elementMarker, index, PsiNamedElement.class);
}
catch (NumberFormatException e) {
@@ -172,7 +180,7 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr
if (element instanceof PsiNamedElement) {
PsiNamedElement named = (PsiNamedElement)element;
final String name = named.getName();
if (name == null) {
if (StringUtil.isEmpty(name)) {
return null;
}
int index = getChildIndex(named, element.getParent(), name, (Class<PsiNamedElement>)named.getClass());
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.folding.impl;
import com.intellij.lang.folding.FoldingDescriptor;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.FoldingGroup;
@@ -41,6 +42,9 @@ import static com.intellij.util.containers.CollectionFactory.newTroveMap;
* @author cdr
*/
class UpdateFoldRegionsOperation implements Runnable {
private static final Logger LOG = Logger.getInstance("#" + UpdateFoldRegionsOperation.class.getName());
private final Project myProject;
private final Editor myEditor;
private final PsiFile myFile;
@@ -104,6 +108,11 @@ class UpdateFoldRegionsOperation implements Runnable {
FoldingGroup group = descriptor.getGroup();
TextRange range = descriptor.getRange();
String placeholder = descriptor.getPlaceholderText();
if (range.getEndOffset() > myEditor.getDocument().getTextLength()) {
LOG.error(String.format("Invalid folding descriptor detected (%s). It ends beyond the document range (%d)",
descriptor, myEditor.getDocument().getTextLength()));
continue;
}
FoldRegion region = foldingModel.createFoldRegion(range.getStartOffset(), range.getEndOffset(),
placeholder == null ? "..." : placeholder,
group,
@@ -0,0 +1,83 @@
/*
* Copyright 2000-2012 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.lookup.impl;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.ui.HeavyweightHint;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
/**
* @author Konstantin Bulenkov
*/
public class CompletionExtender extends HeavyweightHint {
private LookupElement myElement;
private LookupImpl myLookup;
private int myIndex;
public CompletionExtender(@NotNull LookupElement element, @NotNull LookupImpl lookup) {
super(createComponent(element, lookup), false);
myElement = element;
myLookup = lookup;
myIndex = myLookup.getList().getSelectedIndex();
}
public LookupElement getLookupElement() {
return myElement;
}
public boolean sameAsFor(LookupElement item) {
return getLookupElement().equals(item)
&& myIndex == myLookup.getList().getSelectedIndex();
}
private static JComponent createComponent(LookupElement element, LookupImpl lookup) {
final LookupCellRenderer renderer = new LookupCellRenderer(lookup);
renderer.setFullSize(true);
final JComponent component = (JComponent)renderer.getListCellRendererComponent(lookup.getList(), element,
lookup.getList().getSelectedIndex(),
true, false);
component.setSize(component.getPreferredSize());
return component;
}
public boolean show() {
final JList list = myLookup.getList();
if (getComponent().getWidth() > list.getWidth()) {
final JComponent rootPane = UIUtil.getRootPane(myLookup.getEditor().getContentComponent());
final Point p = list.getLocationOnScreen();
p.y += list.indexToLocation(list.getSelectedIndex()).y;
SwingUtilities.convertPointFromScreen(p, rootPane);
if (rootPane != null) {
show(rootPane, p);
return true;
}
}
return false;
}
@Override
public void hide() {
super.hide();
myLookup = null;
myElement = null;
}
}
@@ -95,7 +95,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
private final Project myProject;
private final Editor myEditor;
private Hint tip;
private CompletionExtender extender;
private String myInitialPrefix;
private boolean myStableStart;
@@ -1029,10 +1029,6 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
public void valueChanged(ListSelectionEvent e){
myHintAlarm.cancelAllRequests();
if (tip != null && tip.isVisible()) {
tip.hide();
}
final LookupElement item = getCurrentItem();
if (oldItem != item) {
mySelectionInvariant = item == null ? null : myPresentableModel.getItemPresentationInvariant(item);
@@ -1043,26 +1039,18 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
}
if (item != null) {
updateHint(item);
if (myList.getModel().getSize() > 1 && isVisible()) {
final LookupCellRenderer renderer = new LookupCellRenderer(LookupImpl.this);
renderer.setFullSize(true);
final JComponent component = (JComponent)renderer.getListCellRendererComponent(myList, item,
myList
.getSelectedIndex(),
true, false);
component.setSize(component.getPreferredSize());
if (component.getWidth() > myList.getWidth()) {
tip = new HeavyweightHint(component, false);
final Point p = myList.getLocationOnScreen();
p.y += myList.indexToLocation(myList.getSelectedIndex()).y;
}
oldItem = item;
final JComponent editor = UIUtil.getRootPane(myEditor.getContentComponent());
SwingUtilities.convertPointFromScreen(p, editor);
tip.show(editor, p.x, p.y, null, new HintHint(editor, p));
if (item != null && LookupImpl.this.isVisible()) {
if (extender == null || !extender.isVisible() || !extender.sameAsFor(item)) {
if (extender != null) extender.hide();
extender = new CompletionExtender(item, LookupImpl.this);
if (!extender.show()) {
extender.hide();
}
}
}
oldItem = item;
}
});
@@ -1390,8 +1378,8 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
}
Disposer.dispose(myProcessIcon);
Disposer.dispose(myHintAlarm);
if (tip != null) {
tip.hide();
if (extender != null) {
extender.hide();
}
myDisposed = true;
disposeTrace = DebugUtil.currentStackTrace() + "\n============";
@@ -18,8 +18,8 @@ package com.intellij.codeInspection.ex;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.DummyInspectionTool;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.LocalDummyInspectionTool;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.search.scope.packageSet.NamedScope;
@@ -62,8 +62,8 @@ public class Descriptor {
if (tool instanceof InspectionToolWrapper) {
InspectionProfileEntry inspection = ((InspectionToolWrapper)tool).getTool();
if (inspection instanceof LocalDummyInspectionTool) {
myShouldBeShown = ((LocalDummyInspectionTool)inspection).shouldBeShownInInspectionProfile();
if (inspection instanceof DummyInspectionTool) {
myShouldBeShown = ((DummyInspectionTool)inspection).shouldBeShownInInspectionProfile();
}
}
}
@@ -354,7 +354,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
public boolean isToCheckFile(PsiFile file, final InspectionProfileEntry tool) {
final Tools tools = myTools.get(tool.getShortName());
if (tools != null) {
if (tools != null && file != null) {
for (ScopeToolState state : tools.getTools()) {
final NamedScope namedScope = state.getScope(file.getProject());
if (namedScope == null || namedScope.getValue().contains(file, getCurrentProfile().getProfileManager().getScopesManager())) {
@@ -636,12 +636,12 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profileEntry;
InspectionProfileEntry inspectionTool = toolWrapper.getTool();
if (inspectionTool instanceof LocalDummyInspectionTool) {
if (inspectionTool instanceof DummyInspectionTool) {
if (toolWrappers == null) {
toolWrappers = new HashMap<String, DescriptorProviderInspection>();
}
toolWrappers.put(((LocalDummyInspectionTool)inspectionTool).getProblemGroup(), toolWrapper);
toolWrappers.put(((DummyInspectionTool)inspectionTool).getProblemGroup(), toolWrapper);
}
}
}
@@ -99,6 +99,10 @@ public class RefManagerImpl extends RefManager {
}
}
public GlobalInspectionContextImpl getContext() {
return myContext;
}
public void iterate(RefVisitor visitor) {
myLock.readLock().lock();
try {
@@ -440,6 +444,9 @@ public class RefManagerImpl extends RefManager {
ApplicationManager.getApplication().runReadAction(new Runnable() {
public void run() {
refElement.initialize();
for (RefManagerExtension extension : myExtensions.values()) {
extension.onEntityInitialized(refElement, elem);
}
}
});
@@ -84,7 +84,10 @@ public class FormattingDocumentModelImpl implements FormattingDocumentModel {
@Override
public int getLineNumber(int offset) {
LOG.assertTrue (offset <= myDocument.getTextLength());
if (offset > myDocument.getTextLength()) {
LOG.error(String.format("Invalid offset detected (%d). Document length: %d. Target file: %s",
offset, myDocument.getTextLength(), myFile));
}
return myDocument.getLineNumber(offset);
}
@@ -20,6 +20,8 @@ import com.intellij.openapi.project.Project;
/**
* @author Dmitry Avdeev
*
* This may implement {@link com.intellij.openapi.project.DumbAware}.
*/
public interface StartupActivity {
@@ -275,8 +275,8 @@ public class Switcher extends AnAction implements DumbAware {
toolWindows.addMouseMotionListener(this);
toolWindows.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!toolWindows.getSelectionModel().isSelectionEmpty()) {
files.getSelectionModel().clearSelection();
if (!toolWindows.isSelectionEmpty() && !files.isSelectionEmpty()) {
files.clearSelection();
}
}
});
@@ -411,7 +411,7 @@ public class Switcher extends AnAction implements DumbAware {
files.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
files.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!files.getSelectionModel().isSelectionEmpty()) {
if (!files.isSelectionEmpty() && !toolWindows.isSelectionEmpty()) {
toolWindows.getSelectionModel().clearSelection();
}
}
@@ -693,12 +693,20 @@ public class Switcher extends AnAction implements DumbAware {
}
public JList getSelectedList() {
return getSelectedList(files);
}
JList getSelectedList(JList preferable) {
if (toolWindows.isSelectionEmpty() && files.isSelectionEmpty()) {
if (files.getModel().getSize() > 1) {
if (preferable != null && preferable.getModel().getSize() > 0) {
preferable.setSelectedIndex(0);
return preferable;
} else
if (files.getModel().getSize() > 0) {
files.setSelectedIndex(0);
return files;
}
else {
} else {
toolWindows.setSelectedIndex(0);
return toolWindows;
}
@@ -709,8 +717,8 @@ public class Switcher extends AnAction implements DumbAware {
}
void navigate() {
myPopup.closeOk(null);
final Object value = getSelectedList().getSelectedValue();
myPopup.closeOk(null);
if (value instanceof ToolWindow) {
((ToolWindow)value).activate(null, true, true);
}
@@ -847,21 +855,23 @@ public class Switcher extends AnAction implements DumbAware {
@Override
protected void selectElement(Object element, String selectedText) {
if (element instanceof FileInfo) {
toolWindows.getSelectionModel().clearSelection();
if (!toolWindows.isSelectionEmpty()) toolWindows.clearSelection();
files.setSelectedValue(element, false);
} else {
files.clearSelection();
if (!files.isSelectionEmpty()) files.clearSelection();
toolWindows.setSelectedValue(element, false);
}
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
final JList list = getSelectedList();
final Object value = list.getSelectedValue();
((NameFilteringListModel)files.getModel()).refilter();
((NameFilteringListModel)toolWindows.getModel()).refilter();
files.repaint();
toolWindows.repaint();
getSelectedList();
getSelectedList(list).setSelectedValue(value, true);
}
}
@@ -141,12 +141,14 @@ public class EditorUtil {
editorInfo = ((EditorImpl)editor).dumpState();
}
else {
editorInfo = "all soft wraps: " + editor.getSoftWrapModel().getSoftWrapsForRange(0, document.getTextLength())
+ ", fold regions: " + Arrays.toString(editor.getFoldingModel().getAllFoldRegions());
editorInfo = "editor's class: " + editor.getClass()
+ ", all soft wraps: " + editor.getSoftWrapModel().getSoftWrapsForRange(0, document.getTextLength())
+ ", fold regions: " + Arrays.toString(editor.getFoldingModel().getAllFoldRegions());
}
LOG.error(String.format(
LogMessageEx.error(LOG, "Can't calculate last visual column", String.format(
"Target visual line: %d, mapped logical line: %d, visual lines range for the mapped logical line: [%s]-[%s], soft wraps for "
+ "the target logical line: %s. Editor info: %s", line, resultLogLine, resVisStart, resVisEnd, softWraps, editorInfo
+ "the target logical line: %s. Editor info: %s",
line, resultLogLine, resVisStart, resVisEnd, softWraps, editorInfo
));
return resVisEnd.column;
@@ -117,7 +117,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
public void updateFinished(@NotNull Document doc) {
if (doc != myEditor.getDocument() || myIsInUpdate) return;
if (savedBeforeBulkCaretMarker != null && savedBeforeBulkCaretMarker.isValid()
&& savedBeforeBulkCaretMarker.getStartOffset() != myOffset)
&& savedBeforeBulkCaretMarker.getStartOffset() != myOffset && !myReportCaretMoves)
{
moveToOffset(savedBeforeBulkCaretMarker.getStartOffset());
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.wm.ex.WindowManagerEx;
import com.intellij.ui.awt.RelativePoint;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.EventListenerList;
@@ -45,7 +46,11 @@ public class HeavyweightHint implements Hint {
/**
* Shows the hint as the window
*/
public void show(@NotNull JComponent parentComponent, int x, int y, JComponent focusBackComponent, @NotNull HintHint hintInfo) {
public void show(@NotNull JComponent parentComponent, int x, int y, @Nullable JComponent focusBackComponent, @Nullable HintHint hintInfo) {
show(parentComponent, new Point(x, y));
}
public void show(@NotNull JComponent parentComponent, Point p) {
myParentComponent = parentComponent;
LOG.assertTrue(parentComponent.isShowing());
@@ -59,10 +64,12 @@ public class HeavyweightHint implements Hint {
myWindow.getContentPane().setLayout(new BorderLayout());
myWindow.getContentPane().add(myComponent, BorderLayout.CENTER);
updateBounds(x, y);
updateBounds(p.x, p.y);
myWindow.setVisible(true);
}
protected void fireHintHidden() {
final EventListener[] listeners = myListenerList.getListeners(HintListener.class);
for (EventListener listener1 : listeners) {
@@ -368,9 +368,10 @@ public class FileWatcherTest extends PlatformLangTestCase {
}
}
finally {
VirtualDirectoryImpl.disallowRootAccess(substRoot);
delete(targetDir);
new GeneralCommandLine("subst", subst + ":", "/d").createProcess().waitFor();
myFileSystem.refresh(false);
VirtualDirectoryImpl.disallowRootAccess(substRoot);
}
}
@@ -17,6 +17,7 @@ package com.intellij.util;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.sun.jna.Native;
import com.sun.jna.WString;
import com.sun.jna.win32.StdCallLibrary;
@@ -68,7 +69,13 @@ public class Restarter {
int pid = kernel32.GetCurrentProcessId();
try {
String command = "restarter " + Integer.toString(pid) + " " + cline;
// to prevent blocking exe file during update we should copy it
File restarterFile = new File(PathManager.getBinPath(), "restarter.exe");
File restarterCopy = FileUtil.createTempFile("restarter", ".exe");
FileUtil.copy(restarterFile, restarterCopy);
String command = "\"" + restarterCopy + "\" " + Integer.toString(pid) + " " + cline;
Runtime.getRuntime().exec(command, null, new File(PathManager.getBinPath()));
}
catch (IOException ex) {
@@ -36,11 +36,16 @@ public abstract class VcsBackgroundTask<T> extends Task.ConditionalModal {
private final List<VcsException> myExceptions = new ArrayList<VcsException>();
public VcsBackgroundTask(final Project project, @NotNull final String title, @NotNull final PerformInBackgroundOption backgroundOption,
final Collection<T> itemsToProcess) {
super(project, title, false, backgroundOption);
final Collection<T> itemsToProcess, final boolean canBeCanceled) {
super(project, title, canBeCanceled, backgroundOption);
myItems = itemsToProcess;
}
public VcsBackgroundTask(final Project project, @NotNull final String title, @NotNull final PerformInBackgroundOption backgroundOption,
final Collection<T> itemsToProcess) {
this(project, title, backgroundOption, itemsToProcess, false);
}
public void run(@NotNull ProgressIndicator indicator) {
for(T item: myItems) {
try {
@@ -0,0 +1,67 @@
/*
* Copyright 2000-2012 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.util.ui;
import com.intellij.history.LocalHistory;
import com.intellij.history.LocalHistoryAction;
import com.intellij.openapi.progress.PerformInBackgroundOption;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.VcsException;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 4/13/12
* Time: 1:59 PM
*/
public abstract class VcsBackgroundTaskWithLocalHistory<T> extends VcsBackgroundTask<T> {
private final String myActionName;
protected VcsBackgroundTaskWithLocalHistory(Project project,
@NotNull String title,
@NotNull PerformInBackgroundOption backgroundOption,
Collection<T> itemsToProcess,
String actionName) {
super(project, title, backgroundOption, itemsToProcess);
myActionName = actionName;
}
protected VcsBackgroundTaskWithLocalHistory(Project project,
@NotNull String title,
@NotNull PerformInBackgroundOption backgroundOption,
Collection<T> itemsToProcess,
boolean canBeCanceled, String actionName) {
super(project, title, backgroundOption, itemsToProcess, canBeCanceled);
myActionName = actionName;
}
@Override
public void run(@NotNull ProgressIndicator indicator) {
LocalHistoryAction action = LocalHistoryAction.NULL;
if (myActionName != null) {
action = LocalHistory.getInstance().startAction(myActionName);
}
try {
super.run(indicator);
} finally {
action.finish();
}
}
}
@@ -17,6 +17,7 @@ package com.intellij.android.designer.model;
import com.android.ide.common.rendering.api.ViewInfo;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.model.RadVisualComponent;
import com.intellij.designer.propertyTable.Property;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.xml.XmlAttribute;
@@ -24,20 +25,15 @@ import com.intellij.psi.xml.XmlTag;
import com.intellij.util.containers.hash.HashMap;
import org.jdom.Element;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Alexander Lobas
*/
public class RadViewComponent extends RadComponent {
private final List<RadComponent> myChildren = new ArrayList<RadComponent>();
public class RadViewComponent extends RadVisualComponent {
protected ViewInfo myViewInfo;
private Component myNativeComponent;
private final Rectangle myBounds = new Rectangle();
private Rectangle myMargins;
private XmlTag myTag;
private List<Property> myProperties;
@@ -50,11 +46,6 @@ public class RadViewComponent extends RadComponent {
myTag = tag;
}
@Override
public List<RadComponent> getChildren() {
return myChildren;
}
public ViewInfo getViewInfo() {
return myViewInfo;
}
@@ -83,33 +74,6 @@ public class RadViewComponent extends RadComponent {
return myMargins;
}
@Override
public Rectangle getBounds() {
return myBounds;
}
@Override
public Rectangle getBounds(Component relativeTo) {
return SwingUtilities.convertRectangle(myNativeComponent, myBounds, relativeTo);
}
public void setBounds(int x, int y, int width, int height) {
myBounds.setBounds(x, y, width, height);
}
public Component getNativeComponent() {
return myNativeComponent;
}
public void setNativeComponent(Component nativeComponent) {
myNativeComponent = nativeComponent;
}
@Override
public Point convertPoint(Component component, int x, int y) {
return SwingUtilities.convertPoint(component, x, y, myNativeComponent);
}
@Override
public void delete() throws Exception {
getParent().getChildren().remove(this);
@@ -40,6 +40,7 @@ import java.util.List;
*/
public class InspectionDescriptionNotFoundInspection extends DevKitInspectionBase{
@NonNls static final String INSPECTION_PROFILE_ENTRY = InspectionProfileEntry.class.getName();
@NonNls static final String DUMMY_INSPECTION_TOOL = DummyInspectionTool.class.getName();
@NonNls private static final String INSPECTION_DESCRIPTIONS = "inspectionDescriptions";
@Override
@@ -51,8 +52,10 @@ public class InspectionDescriptionNotFoundInspection extends DevKitInspectionBas
if (nameIdentifier == null || module == null || !PsiUtil.isInstantiatable(aClass)) return null;
final PsiClass base = JavaPsiFacade.getInstance(project).findClass(INSPECTION_PROFILE_ENTRY, GlobalSearchScope.allScope(project));
final PsiClass dummy = JavaPsiFacade.getInstance(project).findClass(DUMMY_INSPECTION_TOOL, GlobalSearchScope.allScope(project));
if (base == null || ! aClass.isInheritor(base, true) || isPathMethodsAreOverridden(aClass)) return null;
if (dummy == null || aClass.isInheritor(dummy, true)) return null;
PsiMethod method = findNearestMethod("getShortName", aClass);
if (method != null && method.getContainingClass().getQualifiedName().equals(INSPECTION_PROFILE_ENTRY)) {
@@ -37,7 +37,7 @@ import java.awt.event.ActionListener;
*/
public class GitVcsPanel {
private static final String IDEA_SSH = ApplicationNamesInfo.getInstance().getProductName() + " " + GitBundle.getString("git.vcs.config.ssh.mode.idea"); // IDEA ssh value
private static final String IDEA_SSH = GitBundle.getString("git.vcs.config.ssh.mode.idea"); // IDEA ssh value
private static final String NATIVE_SSH = GitBundle.getString("git.vcs.config.ssh.mode.native"); // Native SSH value
private static final String CRLF_CONVERT_TO_PROJECT = GitBundle.getString("git.vcs.config.convert.project");
private static final String CRLF_DO_NOT_CONVERT = GitBundle.getString("git.vcs.config.convert.do.not.convert");
@@ -144,7 +144,7 @@ git.vcs.config.convert.tooltip=<html>Specify what to do if line separators in a
Note that this setting has nothing common with Git autocrlf and other Git settings.\
</html>
git.vcs.config.path.label=Path to &Git Executable:
git.vcs.config.ssh.mode.idea=ssh
git.vcs.config.ssh.mode.idea=Built-in
git.vcs.config.ssh.mode.native=Native
git.vcs.config.ssh.mode.tooltip=<html>Specify which version of SSH to be used with Git.<ul><li><b>Native</b> means that the native SSH will be used.</li><li><b>{0} SSH</b> means that the implementation provided by the {0} will be used.</li></ul>The native implementation might cause hangups on some platforms. In native case, you also might need to configure <em>ssh-askpass</em> for your platform to receive GUI prompts for passwords.</html>
git.vcs.config.ssh.mode=&SSH Executable:
@@ -19,12 +19,16 @@ package org.jetbrains.idea.svn.actions;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.BackgroundFromStartOption;
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.ui.VcsBackgroundTaskWithLocalHistory;
import org.jetbrains.idea.svn.SvnBundle;
import org.jetbrains.idea.svn.SvnStatusUtil;
import org.jetbrains.idea.svn.SvnVcs;
@@ -40,6 +44,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public class AddAction extends BasicAction {
static final Logger log = Logger.getInstance("org.jetbrains.idea.svn.action.AddAction");
@@ -57,22 +62,47 @@ public class AddAction extends BasicAction {
return true;
}
protected void batchPerform(final Project project, SvnVcs activeVcs, VirtualFile[] files, DataContext context)
protected void batchPerform(final Project project, final SvnVcs activeVcs, final VirtualFile[] files, DataContext context)
throws VcsException {
log.debug("enter: batchPerform");
SvnVcs vcs = SvnVcs.getInstance(project);
SVNWCClient wcClient = vcs.createWCClient();
wcClient.setEventHandler(new AddEventListener(project));
addFiles(project, activeVcs, files);
}
Collection<SVNException> exceptions = SvnCheckinEnvironment.scheduleUnversionedFilesForAddition(wcClient, Arrays.asList(files), true);
if (! exceptions.isEmpty()) {
final Collection<String> messages = new ArrayList<String>(exceptions.size());
for (SVNException exception : exceptions) {
messages.add(exception.getMessage());
}
throw new VcsException(messages);
}
private void addFiles(final Project project, final SvnVcs activeVcs, final VirtualFile[] files) {
// passed parameter serves only for ""
VcsBackgroundTaskWithLocalHistory taskWithLocalHistory =
new VcsBackgroundTaskWithLocalHistory<VirtualFile[]>(project, getActionName(activeVcs), BackgroundFromStartOption.getInstance(),
Collections.singleton(files), true, SvnBundle.message("action.Subversion.Add.text")) {
@Override
protected void process(VirtualFile[] items) throws VcsException {
ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project);
manager.startBackgroundVcsOperation();
try {
SVNWCClient wcClient = activeVcs.createWCClient();
wcClient.setEventHandler(new AddEventListener(project));
Collection<SVNException> exceptions =
SvnCheckinEnvironment.scheduleUnversionedFilesForAddition(wcClient, Arrays.asList(items), true);
if (!exceptions.isEmpty()) {
final Collection<String> messages = new ArrayList<String>(exceptions.size());
for (SVNException exception : exceptions) {
messages.add(exception.getMessage());
}
throw new VcsException(messages);
}
} finally {
manager.stopBackgroundVcsOperation();
}
}
};
ProgressManager.getInstance().run(taskWithLocalHistory);
}
@Override
protected boolean witeLocalHistory() {
return false;
}
protected boolean isBatchAction() {
@@ -82,16 +112,7 @@ public class AddAction extends BasicAction {
protected void perform(Project project, SvnVcs activeVcs, VirtualFile file, DataContext context)
throws VcsException {
try {
SVNWCClient wcClient = activeVcs.createWCClient();
wcClient.setEventHandler(new AddEventListener(project));
wcClient.doAdd(new File(file.getPath()), false, false, true, true);
}
catch (SVNException e) {
VcsException ve = new VcsException(e);
ve.setVirtualFile(file);
throw ve;
}
addFiles(project, activeVcs, new VirtualFile[] {file});
}
private static class AddEventListener implements ISVNEventHandler {
@@ -61,7 +61,7 @@ public abstract class BasicAction extends AnAction implements DumbAware {
final AbstractVcsHelper helper = AbstractVcsHelper.getInstance(project);
LocalHistoryAction action = LocalHistoryAction.NULL;
if (actionName != null) {
if (witeLocalHistory() && actionName != null) {
action = LocalHistory.getInstance().startAction(actionName);
}
@@ -95,6 +95,10 @@ public abstract class BasicAction extends AnAction implements DumbAware {
}
}
protected boolean witeLocalHistory() {
return true;
}
public void update(AnActionEvent e) {
//LOG.debug("enter: update class:"+getClass().getName());
super.update(e);
@@ -392,6 +392,26 @@ public class SvnCheckinEnvironment implements CheckinEnvironment {
Collections.sort(files, FilePathComparator.getInstance());
wcClient.setEventHandler(new ISVNEventHandler() {
@Override
public void handleEvent(SVNEvent event, double progress) throws SVNException {
final ProgressManager pm = ProgressManager.getInstance();
final ProgressIndicator pi = pm.getProgressIndicator();
if (pi != null && event.getFile() != null) {
File file = event.getFile();
pi.setText(SvnBundle.message("progress.text2.adding", file.getName() + " (" + file.getParent() + ")"));
}
}
@Override
public void checkCancelled() throws SVNCancelException {
final ProgressManager pm = ProgressManager.getInstance();
final ProgressIndicator pi = pm.getProgressIndicator();
if (pi != null) {
if (pi.isCanceled()) throw new SVNCancelException();
}
}
});
for (VirtualFile file : files) {
try {
wcClient.doAdd(new File(FileUtil.toSystemDependentName(file.getPath())), true, false, true, recursive);
@@ -15,6 +15,7 @@
*/
package org.jetbrains.idea.svn.history;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import org.tmatesoft.svn.core.SVNException;
@@ -88,6 +89,7 @@ public class BunchFactory {
if (defender == 0) {
return;
}
ProgressManager.checkCanceled();
final Fragment fragment = myCurrentProvider.getEarliestBunchInInterval(myYoungest, 0,
(myYoungest == -1) ? myBunchSize : (myBunchSize + 1), (myYoungest == -1), true);
if ((fragment == null) || (fragment.getList().isEmpty())) {
@@ -95,6 +97,7 @@ public class BunchFactory {
break;
}
ProgressManager.checkCanceled();
final List<CommittedChangeList> bunchLists = fragment.getList();
if (! fragment.isConsistentWithYounger()) {
final long endRevision = bunchLists.get(0).getNumber();
@@ -51,6 +51,11 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider,
public CommonEditActionsProvider(DesignerEditorPanel designer) {
myDesigner = designer;
}
protected EditableArea getArea() {
return myDesigner.getActionsArea();
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// Delete
@@ -60,7 +65,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider,
@Override
public boolean canDeleteElement(@NotNull DataContext dataContext) {
// TODO: InplaceEditing
List<RadComponent> selection = myDesigner.getActionsArea().getSelection();
List<RadComponent> selection = getArea().getSelection();
if (selection.isEmpty()) {
return false;
}
@@ -77,7 +82,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider,
myDesigner.getToolProvider().execute(new ThrowableRunnable<Exception>() {
@Override
public void run() throws Exception {
EditableArea area = myDesigner.getActionsArea();
EditableArea area = getArea();
List<RadComponent> selection = area.getSelection();
List<RadComponent> components = RadComponent.getPureSelection(selection);
RadComponent newSelection = getNewSelection(components.get(0), selection);
@@ -128,7 +133,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider,
@Override
public boolean isCopyEnabled(@NotNull DataContext dataContext) {
// TODO: InplaceEditing
return !myDesigner.getActionsArea().getSelection().isEmpty();
return !getArea().getSelection().isEmpty();
}
@Override
@@ -141,7 +146,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider,
Element root = new Element("designer");
root.setAttribute("target", myDesigner.getPlatformTarget());
List<RadComponent> components = RadComponent.getPureSelection(myDesigner.getActionsArea().getSelection());
List<RadComponent> components = RadComponent.getPureSelection(getArea().getSelection());
for (RadComponent component : components) {
component.copyTo(root);
}
@@ -15,22 +15,130 @@
*/
package com.intellij.designer.designSurface;
import com.intellij.designer.actions.CommonEditActionsProvider;
import com.intellij.designer.designSurface.tools.InputTool;
import com.intellij.designer.model.FindComponentVisitor;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.model.RadVisualComponent;
import com.intellij.ide.DeleteProvider;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.SideBorder;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.util.List;
/**
* @author Alexander Lobas
*/
public class CaptionPanel extends JComponent implements DataProvider {
public class CaptionPanel extends JLayeredPane implements DataProvider, DeleteProvider, ComponentSelectionListener {
private final boolean myHorizontal;
private final EditableArea myArea;
private final DecorationLayer myDecorationLayer;
private final FeedbackLayer myFeedbackLayer;
private final CommonEditActionsProvider myActionsProvider;
private final RadVisualComponent myRootComponent;
public CaptionPanel(DesignerEditorPanel designer, boolean horizontal) {
setBorder(IdeBorderFactory.createBorder(horizontal ? SideBorder.BOTTOM : SideBorder.RIGHT));
setFocusable(true);
myHorizontal = horizontal;
myRootComponent = new RadVisualComponent() {
@Override
public boolean canDelete() {
return false;
}
};
myRootComponent.setNativeComponent(this);
myRootComponent.setBounds(0, 0, 100000, 100000);
myArea = new ComponentEditableArea(this) {
@Override
protected void fireSelectionChanged() {
super.fireSelectionChanged();
revalidate();
repaint();
}
@Override
public RadComponent findTarget(int x, int y, @Nullable ComponentTargetFilter filter) {
FindComponentVisitor visitor = new FindComponentVisitor(CaptionPanel.this, filter, x, y);
myRootComponent.accept(visitor, false);
return visitor.getResult();
}
@Override
public InputTool findTargetTool(int x, int y) {
return myDecorationLayer.findTargetTool(x, y);
}
@Override
public void showSelection(boolean value) {
myDecorationLayer.showSelection(value);
}
@Override
public ComponentDecorator getRootSelectionDecorator() {
return EmptyComponentDecorator.INSTANCE;
}
@Override
public EditOperation processRootOperation(OperationContext context) {
return null;
}
@Override
public FeedbackLayer getFeedbackLayer() {
return myFeedbackLayer;
}
@Override
public RadComponent getRootComponent() {
return myRootComponent;
}
};
add(new GlassLayer(designer.getToolProvider(), myArea), DesignerEditorPanel.LAYER_GLASS);
myDecorationLayer = new DecorationLayer(myArea);
add(myDecorationLayer, DesignerEditorPanel.LAYER_DECORATION);
myFeedbackLayer = new FeedbackLayer();
add(myFeedbackLayer, DesignerEditorPanel.LAYER_FEEDBACK);
myActionsProvider = new CommonEditActionsProvider(designer) {
@Override
protected EditableArea getArea() {
return myArea;
}
};
designer.getSurfaceArea().addSelectionListener(this);
}
public void attachToScrollPane(JScrollPane scrollPane) {
scrollPane.getViewport().addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
repaint();
}
});
}
public void doLayout() {
for (int i = getComponentCount() - 1; i >= 0; i--) {
Component component = getComponent(i);
component.setBounds(0, 0, getWidth(), getHeight());
}
}
@Override
@@ -45,6 +153,56 @@ public class CaptionPanel extends JComponent implements DataProvider {
@Override
public Object getData(@NonNls String dataId) {
return null; // TODO: Auto-generated method stub
if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
return this;
}
return null;
}
@Override
public boolean canDeleteElement(@NotNull DataContext dataContext) {
return myActionsProvider.canDeleteElement(dataContext);
}
@Override
public void deleteElement(@NotNull DataContext dataContext) {
myActionsProvider.deleteElement(dataContext);
}
@Override
public void selectionChanged(EditableArea area) {
List<RadComponent> selection = area.getSelection();
if (selection.size() != 1) {
return;
}
List<RadComponent> children = myRootComponent.getChildren();
boolean update = !children.isEmpty();
children.clear();
myRootComponent.setLayout(null);
ICaption caption = null;
RadComponent component = selection.get(0);
RadComponent parent = component.getParent();
if (parent != null && parent.getLayout() instanceof ICaption) {
caption = (ICaption)parent.getLayout();
}
if (caption == null && component instanceof ICaption) {
caption = (ICaption)component;
}
if (caption != null) {
myRootComponent.setLayout(caption.getCaptionLayout(area, myHorizontal));
caption.addCaptionChildren(area, myHorizontal, children);
update = true;
}
if (update) {
revalidate();
repaint();
}
}
}
@@ -21,8 +21,8 @@ import com.intellij.designer.actions.DesignerActionPanel;
import com.intellij.designer.componentTree.TreeComponentDecorator;
import com.intellij.designer.componentTree.TreeEditableArea;
import com.intellij.designer.designSurface.tools.*;
import com.intellij.designer.model.FindComponentVisitor;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.model.RadComponentVisitor;
import com.intellij.designer.palette.Item;
import com.intellij.designer.propertyTable.Property;
import com.intellij.diagnostic.LogMessageEx;
@@ -70,12 +70,10 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
private static final Logger LOG = Logger.getInstance("#com.intellij.designer.designSurface.DesignerEditorPanel");
protected static final Integer LAYER_COMPONENT = JLayeredPane.DEFAULT_LAYER;
protected static final Integer LAYER_STATIC_DECORATION = JLayeredPane.POPUP_LAYER;
protected static final Integer LAYER_DECORATION = JLayeredPane.DRAG_LAYER;
protected static final Integer LAYER_FEEDBACK = LAYER_DECORATION + 100;
protected static final Integer LAYER_DECORATION = JLayeredPane.POPUP_LAYER;
protected static final Integer LAYER_FEEDBACK = JLayeredPane.DRAG_LAYER;
protected static final Integer LAYER_GLASS = LAYER_FEEDBACK + 100;
protected static final Integer LAYER_BUTTONS = LAYER_GLASS + 100;
protected static final Integer LAYER_INPLACE_EDITING = LAYER_BUTTONS + 100;
protected static final Integer LAYER_INPLACE_EDITING = LAYER_GLASS + 100;
private static final Integer LAYER_PROGRESS = LAYER_INPLACE_EDITING + 100;
private final static String DESIGNER_CARD = "designer";
@@ -134,24 +132,6 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
}
private void createDesignerCard() {
JPanel content = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.fill = GridBagConstraints.VERTICAL;
myVerticalCaption = new CaptionPanel(this, false);
content.add(myVerticalCaption, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
myHorizontalCaption = new CaptionPanel(this, true);
content.add(myHorizontalCaption, gbc);
myLayeredPane = new MyLayeredPane();
mySurfaceArea = new ComponentEditableArea(myLayeredPane) {
@@ -165,7 +145,7 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
@Override
public RadComponent findTarget(int x, int y, @Nullable ComponentTargetFilter filter) {
if (myRootComponent != null) {
FindComponentVisitor visitor = new FindComponentVisitor(filter, x, y);
FindComponentVisitor visitor = new FindComponentVisitor(myLayeredPane, filter, x, y);
myRootComponent.accept(visitor, false);
return visitor.getResult();
}
@@ -267,6 +247,24 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
myFeedbackLayer = new FeedbackLayer();
myLayeredPane.add(myFeedbackLayer, LAYER_FEEDBACK);
JPanel content = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.fill = GridBagConstraints.VERTICAL;
myVerticalCaption = new CaptionPanel(this, false);
content.add(myVerticalCaption, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
myHorizontalCaption = new CaptionPanel(this, true);
content.add(myHorizontalCaption, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.weightx = 1;
@@ -277,6 +275,9 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
myScrollPane.setBackground(Color.WHITE);
content.add(myScrollPane, gbc);
myHorizontalCaption.attachToScrollPane(myScrollPane);
myVerticalCaption.attachToScrollPane(myScrollPane);
myActionPanel = new DesignerActionPanel(this, myGlassLayer);
myDesignerCard = new JPanel(new FillLayout());
@@ -768,37 +769,6 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
}
}
private class FindComponentVisitor extends RadComponentVisitor {
@Nullable private final ComponentTargetFilter myFilter;
private RadComponent myResult;
private final int myX;
private final int myY;
public FindComponentVisitor(@Nullable ComponentTargetFilter filter, int x, int y) {
myFilter = filter;
myX = x;
myY = y;
}
public RadComponent getResult() {
return myResult;
}
@Override
public boolean visit(RadComponent component) {
return myResult == null &&
component.getBounds(myLayeredPane).contains(myX, myY) &&
(myFilter == null || myFilter.preFilter(component));
}
@Override
public void endVisit(RadComponent component) {
if (myResult == null && (myFilter == null || myFilter.resultFilter(component))) {
myResult = component;
}
}
}
public static final class ErrorInfo {
public String myMessage;
public String myDisplayMessage;
@@ -0,0 +1,44 @@
/*
* Copyright 2000-2012 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.designer.designSurface;
import com.intellij.designer.designSurface.tools.InputTool;
import com.intellij.designer.model.RadComponent;
import java.awt.*;
/**
* @author Alexander Lobas
*/
public final class EmptyComponentDecorator extends ComponentDecorator {
public static final ComponentDecorator INSTANCE = new EmptyComponentDecorator();
private EmptyComponentDecorator() {
}
@Override
public InputTool findTargetTool(DecorationLayer layer, RadComponent component, int x, int y) {
return null;
}
@Override
public void decorate(DecorationLayer layer, Graphics2D host, RadComponent component) {
}
@Override
protected void paint(DecorationLayer layer, Graphics2D g, RadComponent component) {
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2012 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.designer.designSurface;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.model.RadLayout;
import java.util.List;
/**
* @author Alexander Lobas
*/
public interface ICaption {
RadLayout getCaptionLayout(EditableArea mainArea, boolean horizontal);
void addCaptionChildren(EditableArea mainArea, boolean horizontal, List<RadComponent> children);
}
@@ -0,0 +1,58 @@
/*
* Copyright 2000-2012 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.designer.model;
import com.intellij.designer.designSurface.ComponentTargetFilter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author Alexander Lobas
*/
public class FindComponentVisitor extends RadComponentVisitor {
private final JComponent myComponent;
private final ComponentTargetFilter myFilter;
private RadComponent myResult;
private final int myX;
private final int myY;
public FindComponentVisitor(@NotNull JComponent component, @Nullable ComponentTargetFilter filter, int x, int y) {
myComponent = component;
myFilter = filter;
myX = x;
myY = y;
}
public RadComponent getResult() {
return myResult;
}
@Override
public boolean visit(RadComponent component) {
return myResult == null &&
component.getBounds(myComponent).contains(myX, myY) &&
(myFilter == null || myFilter.preFilter(component));
}
@Override
public void endVisit(RadComponent component) {
if (myResult == null && (myFilter == null || myFilter.resultFilter(component))) {
myResult = component;
}
}
}
@@ -115,7 +115,7 @@ public abstract class RadComponent {
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// layout
// Layout
//
//////////////////////////////////////////////////////////////////////////////////////////
@@ -123,9 +123,11 @@ public abstract class RadComponent {
return myLayout;
}
public void setLayout(RadLayout layout) {
public void setLayout(@Nullable RadLayout layout) {
myLayout = layout;
myLayout.setContainer(this);
if (myLayout != null) {
myLayout.setContainer(this);
}
}
@Nullable
@@ -0,0 +1,67 @@
/*
* Copyright 2000-2012 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.designer.model;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author Alexander Lobas
*/
public abstract class RadVisualComponent extends RadComponent {
protected final List<RadComponent> myChildren = new ArrayList<RadComponent>();
private Component myNativeComponent;
private final Rectangle myBounds = new Rectangle();
@Override
public List<RadComponent> getChildren() {
return myChildren;
}
@Override
public Rectangle getBounds() {
return myBounds;
}
@Override
public Rectangle getBounds(Component relativeTo) {
return myNativeComponent == relativeTo
? new Rectangle(myBounds) :
SwingUtilities.convertRectangle(myNativeComponent, myBounds, relativeTo);
}
public void setBounds(int x, int y, int width, int height) {
myBounds.setBounds(x, y, width, height);
}
@Override
public Point convertPoint(Component relativeFrom, int x, int y) {
return myNativeComponent == relativeFrom
? myBounds.getLocation() :
SwingUtilities.convertPoint(relativeFrom, x, y, myNativeComponent);
}
public Component getNativeComponent() {
return myNativeComponent;
}
public void setNativeComponent(Component nativeComponent) {
myNativeComponent = nativeComponent;
}
}
@@ -35,6 +35,7 @@ import com.intellij.psi.xml.XmlFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.CollectionFactory;
import com.intellij.util.containers.HashMap;
import com.intellij.xml.Html5SchemaProvider;
import com.intellij.xml.XmlSchemaProvider;
import com.intellij.xml.util.XmlUtil;
import org.jdom.Element;
@@ -75,7 +76,7 @@ public class ExternalResourceManagerImpl extends ExternalResourceManagerEx imple
}
};
private String myDefaultHtmlDoctype = XmlUtil.XHTML_URI;
private String myDefaultHtmlDoctype = Html5SchemaProvider.HTML5_SCHEMA_LOCATION;
protected Map<String, Map<String, Resource>> computeStdResources() {
ResourceRegistrarImpl registrar = new ResourceRegistrarImpl();
@@ -27,7 +27,6 @@ import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlToken;
import com.intellij.xml.XmlNSDescriptor;
import com.intellij.xml.util.HtmlUtil;
import com.intellij.xml.util.XmlTagUtil;
/**
@@ -42,7 +41,7 @@ public class XMLExternalAnnotator extends ExternalAnnotator {
XmlTag rootTag = document.getRootTag();
XmlNSDescriptor nsDescriptor = rootTag == null ? null : rootTag.getNSDescriptor(rootTag.getNamespace(), false);
if (nsDescriptor instanceof Validator && !HtmlUtil.isHtml5Document(document)) {
if (nsDescriptor instanceof Validator) {
//noinspection unchecked
((Validator<XmlDocument>)nsDescriptor).validate(document, new MyHost(holder));
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -88,7 +88,9 @@ public class HtmlConditionalCommentInjector implements MultiHostInjector {
ASTNode conditionalStart = pair.first;
ASTNode conditionalEnd = pair.second;
TextRange range = new TextRange(conditionalStart.getTextRange().getEndOffset() - startOffset, conditionalEnd.getStartOffset() - startOffset);
registrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost)host, range).doneInjecting();
if (range.getStartOffset() < range.getEndOffset()) {
registrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost)host, range).doneInjecting();
}
}
@NotNull
@@ -39,7 +39,7 @@ public class XmlElementsGroupImpl implements XmlElementsGroup {
return ContainerUtil.map(myParticle.getSubParticles(), new Function<XmlContentParticle, XmlElementsGroup>() {
@Override
public XmlElementsGroup fun(XmlContentParticle xmlContentParticle) {
return new XmlElementsGroupImpl(xmlContentParticle, XmlElementsGroupImpl.this);
return new XmlElementsGroupImpl(xmlContentParticle, XmlElementsGroupImpl.this);
}
});
}
@@ -37,6 +37,7 @@ import com.intellij.util.ArrayUtil;
import com.intellij.xml.XmlAttributeDescriptor;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.XmlNSDescriptor;
import com.intellij.xml.XmlNSDescriptorEx;
import com.intellij.xml.impl.ExternalDocumentValidator;
import com.intellij.xml.util.XmlUtil;
import gnu.trove.THashSet;
@@ -50,7 +51,7 @@ import java.util.*;
* @author Mike
*/
@SuppressWarnings({"HardCodedStringLiteral"})
public class XmlNSDescriptorImpl implements XmlNSDescriptor,Validator<XmlDocument>, DumbAware, XmlNSTypeDescriptorProvider {
public class XmlNSDescriptorImpl implements XmlNSDescriptorEx,Validator<XmlDocument>, DumbAware, XmlNSTypeDescriptorProvider {
private static final Logger LOG = Logger.getInstance("#com.intellij.xml.impl.schema.XmlNSDescriptorImpl");
@NonNls private static final Set<String> STD_TYPES = new HashSet<String>();
private static final Set<String> UNDECLARED_STD_TYPES = new HashSet<String>();
@@ -0,0 +1,8 @@
package com.intellij.xml;
/**
* @author Eugene.Kudelevsky
*/
public interface XmlNSDescriptorEx extends XmlNSDescriptor {
XmlElementDescriptor getElementDescriptor(String localName, String namespace);
}
@@ -35,7 +35,8 @@ import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.XmlNSDescriptor;
import com.intellij.xml.XmlNSDescriptorEx;
import com.intellij.xml.impl.schema.AnyXmlElementDescriptor;
import org.intellij.plugins.relaxNG.ApplicationLoader;
import org.intellij.plugins.relaxNG.model.resolve.RelaxIncludeIndex;
import org.intellij.plugins.relaxNG.validation.RngParser;
@@ -48,17 +49,17 @@ import org.kohsuke.rngom.digested.DPattern;
import org.kohsuke.rngom.nc.NameClass;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Created by IntelliJ IDEA.
* User: sweinreuter
* Date: 18.07.2007
*/
public class RngNsDescriptor implements XmlNSDescriptor, Validator {
public class RngNsDescriptor implements XmlNSDescriptorEx, Validator {
private final Map<QName, CachedValue<XmlElementDescriptor>> myDescriptorsMap =
Collections.synchronizedMap(new HashMap<QName, CachedValue<XmlElementDescriptor>>());
private static final Key<ParameterizedCachedValue<XmlElementDescriptor, RngNsDescriptor>> ROOT_KEY = Key.create("ROOT_DESCRIPTOR");
private XmlFile myFile;
@@ -95,7 +96,7 @@ public class RngNsDescriptor implements XmlNSDescriptor, Validator {
}
}
if (desc == null) {
if (desc == null || desc instanceof AnyXmlElementDescriptor) {
return findRootDescriptor(tag);
}
@@ -124,6 +125,11 @@ public class RngNsDescriptor implements XmlNSDescriptor, Validator {
return descriptor != null ? descriptor : findDescriptor(tag, ChildElementFinder.find(myPattern));
}
private XmlElementDescriptor findRootDescriptorInner(QName qName) {
return findDescriptor(qName, ContainerUtil.findAll(
ChildElementFinder.find(-1, myPattern), NamedPatternFilter.INSTANCE));
}
public XmlElementDescriptor findDescriptor(XmlTag tag, List<DElementPattern> list) {
final QName qName = new QName(tag.getNamespace(), tag.getLocalName());
@@ -279,4 +285,23 @@ public class RngNsDescriptor implements XmlNSDescriptor, Validator {
XmlInstanceValidator.doValidation(doc, host, getDescriptorFile());
}
}
//@Override
public XmlElementDescriptor getElementDescriptor(String localName, String namespace) {
final QName qName = new QName(namespace, localName);
CachedValue<XmlElementDescriptor> cachedValue = myDescriptorsMap.get(qName);
if (cachedValue == null) {
cachedValue =
CachedValuesManager.getManager(myElement.getProject()).createCachedValue(new CachedValueProvider<XmlElementDescriptor>() {
public Result<XmlElementDescriptor> compute() {
final XmlElementDescriptor descriptor = findRootDescriptorInner(qName);
return descriptor != null
? new Result<XmlElementDescriptor>(descriptor, descriptor.getDependences())
: new Result<XmlElementDescriptor>(null, getDependences());
}
}, false);
myDescriptorsMap.put(qName, cachedValue);
}
return cachedValue.getValue();
}
}