From 519ccb6024db1fb1049bb344ef083acc733b2c4a Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 22 Feb 2012 20:11:46 +0100 Subject: [PATCH 01/13] check valueOf signature before use synthetic javadoc (IDEA-81701) --- .../codeInsight/javadoc/JavaDocInfoGenerator.java | 10 +++++++--- .../testData/codeInsight/javadocIG/enumValueOf.html | 3 +++ .../testData/codeInsight/javadocIG/enumValueOf.java | 12 ++++++++++++ .../javadoc/JavaDocInfoGeneratorTest.java | 4 ++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/javadocIG/enumValueOf.html create mode 100644 java/java-tests/testData/codeInsight/javadocIG/enumValueOf.java diff --git a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java index 58d85d6d0492..2f18c00301b0 100644 --- a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java +++ b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java @@ -759,11 +759,15 @@ public class JavaDocInfoGenerator { private PsiDocComment getMethodDocComment(final PsiMethod method) { final PsiClass parentClass = method.getContainingClass(); if (parentClass != null && parentClass.isEnum()) { - if (method.getName().equals("values") && method.getParameterList().getParametersCount() == 0) { + final PsiParameterList parameterList = method.getParameterList(); + if (method.getName().equals("values") && parameterList.getParametersCount() == 0) { return loadSyntheticDocComment(method, "/javadoc/EnumValues.java.template"); } - if (method.getName().equals("valueOf") && method.getParameterList().getParametersCount() == 1) { - return loadSyntheticDocComment(method, "/javadoc/EnumValueOf.java.template"); + if (method.getName().equals("valueOf") && parameterList.getParametersCount() == 1) { + final PsiType psiType = parameterList.getParameters()[0].getType(); + if (psiType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { + return loadSyntheticDocComment(method, "/javadoc/EnumValueOf.java.template"); + } } } return getDocComment(method); diff --git a/java/java-tests/testData/codeInsight/javadocIG/enumValueOf.html b/java/java-tests/testData/codeInsight/javadocIG/enumValueOf.html new file mode 100644 index 000000000000..e2161cbf8986 --- /dev/null +++ b/java/java-tests/testData/codeInsight/javadocIG/enumValueOf.html @@ -0,0 +1,3 @@ + En
static int valueOf(int i)
+ myjavadoc +
Parameters:
i -
Returns:
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/javadocIG/enumValueOf.java b/java/java-tests/testData/codeInsight/javadocIG/enumValueOf.java new file mode 100644 index 000000000000..0d54e7b72647 --- /dev/null +++ b/java/java-tests/testData/codeInsight/javadocIG/enumValueOf.java @@ -0,0 +1,12 @@ +enum En { + ; + + /** + * myjavadoc + * @param i + * @return + */ + static int valueOf(int i) { + return i; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java index cc05711af681..71b6fc1c69eb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java @@ -50,6 +50,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase { public void testClassTypeParameter() throws Exception { verifyJavaDoc(getTestClass()); } + + public void testEnumValueOf() throws Exception { + doTestMethod(); + } private void doTestField() throws Exception { PsiClass psiClass = getTestClass(); From 9c91d9374f06748c2476b6a234d70eb630c953d0 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 23 Feb 2012 10:29:04 +0100 Subject: [PATCH 02/13] add convert switch to if for invalid switch types (IDEA-81580) --- .../daemon/impl/analysis/HighlightUtil.java | 3 +- .../quickfix/ConvertSwitchToIfIntention.java | 363 ++++++++++++++++++ .../impl/quickfix/SwitchStatementBranch.java | 88 +++++ .../quickFix/convertSwitchToIf/after1.java | 8 + .../quickFix/convertSwitchToIf/before1.java | 9 + .../quickFix/convertSwitchToIf/before2.java | 7 + .../quickFix/convertSwitchToIf/before3.java | 8 + .../quickFix/ConvertSwitchToIfTest.java | 26 ++ .../ReplaceSwitchWithIfIntention.java | 295 +------------- .../replaceSwitchToIf/ReplaceInt.java | 8 + .../replaceSwitchToIf/ReplaceInt_after.java | 7 + .../ReplaceSwitchWithIflIntentionTest.java | 35 ++ ...idNonConstantResIdsInSwitchInspection.java | 3 +- 13 files changed, 565 insertions(+), 295 deletions(-) create mode 100644 java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java create mode 100644 java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SwitchStatementBranch.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/after1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before1.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before2.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before3.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ConvertSwitchToIfTest.java create mode 100644 plugins/IntentionPowerPak/test/com/siyeh/ipp/switchtoif/replaceSwitchToIf/ReplaceInt.java create mode 100644 plugins/IntentionPowerPak/test/com/siyeh/ipp/switchtoif/replaceSwitchToIf/ReplaceInt_after.java create mode 100644 plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/switchtoif/ReplaceSwitchWithIflIntentionTest.java diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 12eeaf0a5a7e..140b8f92e90e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1226,7 +1226,7 @@ public class HighlightUtil { @Nullable public static HighlightInfo checkSwitchSelectorType(PsiSwitchStatement statement) { - PsiExpression expression = statement.getExpression(); + final PsiExpression expression = statement.getExpression(); HighlightInfo errorResult = null; if (expression != null && expression.getType() != null) { PsiType type = expression.getType(); @@ -1234,6 +1234,7 @@ public class HighlightUtil { String message = JavaErrorMessages.message("incompatible.types", JavaErrorMessages.message("valid.switch.selector.types"), formatType(type)); errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expression, message); + QuickFixAction.registerQuickFixAction(errorResult, new ConvertSwitchToIfIntention(statement)); if (PsiType.LONG.equals(type) || PsiType.FLOAT.equals(type) || PsiType.DOUBLE.equals(type)) { QuickFixAction.registerQuickFixAction(errorResult, new AddTypeCastFix(PsiType.INT, expression)); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java new file mode 100644 index 000000000000..3bf3f10a89d5 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java @@ -0,0 +1,363 @@ +/* + * 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.daemon.impl.quickfix; + +import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.*; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; +import com.intellij.psi.controlFlow.*; +import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** +* User: anna +* Date: 2/22/12 +*/ +public class ConvertSwitchToIfIntention implements IntentionAction { + private final PsiSwitchStatement mySwitchExpression; + + public ConvertSwitchToIfIntention(PsiSwitchStatement switchStatement) { + mySwitchExpression = switchStatement; + } + + @NotNull + @Override + public String getText() { + return "Replace 'switch' with 'if'"; + } + + @NotNull + @Override + public String getFamilyName() { + return getText(); + } + + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + final PsiCodeBlock body = mySwitchExpression.getBody(); + return body != null && body.getStatements().length > 0; + } + + @Override + public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { + doProcessIntention(mySwitchExpression); + } + + @Override + public boolean startInWriteAction() { + return true; + } + + public static void doProcessIntention(@NotNull PsiSwitchStatement switchStatement) { + final PsiExpression switchExpression = switchStatement.getExpression(); + if (switchExpression == null) { + return; + } + final PsiType switchExpressionType = switchExpression.getType(); + if (switchExpressionType == null) { + return; + } + final boolean isSwitchOnString = + switchExpressionType.equalsToText("java.lang.String"); + final String declarationString; + final boolean hadSideEffects; + final String expressionText; + final Project project = switchStatement.getProject(); + if (RemoveUnusedVariableFix.checkSideEffects(switchExpression, null, new ArrayList())) { + hadSideEffects = true; + + final JavaCodeStyleManager javaCodeStyleManager = + JavaCodeStyleManager.getInstance(project); + final String variableName; + if (isSwitchOnString) { + variableName = javaCodeStyleManager.suggestUniqueVariableName( + "s", switchExpression, true); + } + else { + variableName = javaCodeStyleManager.suggestUniqueVariableName( + "i", switchExpression, true); + } + expressionText = variableName; + declarationString = + switchExpressionType.getPresentableText() + ' ' + + variableName + " = " + + switchExpression.getText() + ';'; + } + else { + hadSideEffects = false; + declarationString = null; + expressionText = switchExpression.getText(); + } + final PsiCodeBlock body = switchStatement.getBody(); + if (body == null) { + return; + } + final List openBranches = + new ArrayList(); + final Set declaredVariables = + new HashSet(); + final List allBranches = + new ArrayList(); + SwitchStatementBranch currentBranch = null; + final PsiElement[] children = body.getChildren(); + for (int i = 1; i < children.length - 1; i++) { + final PsiElement statement = children[i]; + if (statement instanceof PsiSwitchLabelStatement) { + final PsiSwitchLabelStatement label = + (PsiSwitchLabelStatement)statement; + if (currentBranch == null) { + openBranches.clear(); + currentBranch = new SwitchStatementBranch(); + currentBranch.addPendingVariableDeclarations(declaredVariables); + allBranches.add(currentBranch); + openBranches.add(currentBranch); + } + else if (currentBranch.hasStatements()) { + currentBranch = new SwitchStatementBranch(); + allBranches.add(currentBranch); + openBranches.add(currentBranch); + } + if (label.isDefaultCase()) { + currentBranch.setDefault(); + } + else { + final PsiExpression value = label.getCaseValue(); + final String valueText = getCaseValueText(value); + currentBranch.addCaseValue(valueText); + } + } + else { + if (statement instanceof PsiStatement) { + if (statement instanceof PsiDeclarationStatement) { + final PsiDeclarationStatement declarationStatement = + (PsiDeclarationStatement)statement; + final PsiElement[] elements = + declarationStatement.getDeclaredElements(); + for (PsiElement varElement : elements) { + final PsiLocalVariable variable = + (PsiLocalVariable)varElement; + declaredVariables.add(variable); + } + } + for (SwitchStatementBranch branch : openBranches) { + branch.addStatement(statement); + } + try { + ControlFlow controlFlow = ControlFlowFactory + .getInstance(project).getControlFlow(statement, LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance()); + int startOffset = controlFlow.getStartOffset(statement); + int endOffset = controlFlow.getEndOffset(statement); + if (startOffset != -1 && endOffset != -1 && !ControlFlowUtil.canCompleteNormally(controlFlow, startOffset, endOffset)) { + currentBranch = null; + } + } + catch (AnalysisCanceledException e) { + currentBranch = null; + } + } + else { + for (SwitchStatementBranch branch : openBranches) { + if (statement instanceof PsiWhiteSpace) { + branch.addWhiteSpace(statement); + } + else { + branch.addComment(statement); + } + } + } + } + } + final StringBuilder ifStatementText = new StringBuilder(); + boolean firstBranch = true; + SwitchStatementBranch defaultBranch = null; + for (SwitchStatementBranch branch : allBranches) { + if (branch.isDefault()) { + defaultBranch = branch; + } + else { + final List caseValues = branch.getCaseValues(); + final List bodyElements = branch.getBodyElements(); + final Set pendingVariableDeclarations = + branch.getPendingVariableDeclarations(); + dumpBranch(expressionText, caseValues, bodyElements, + pendingVariableDeclarations, firstBranch, + isSwitchOnString, ifStatementText); + firstBranch = false; + } + } + if (defaultBranch != null) { + final List bodyElements = + defaultBranch.getBodyElements(); + final Set pendingVariableDeclarations = + defaultBranch.getPendingVariableDeclarations(); + dumpDefaultBranch(bodyElements, pendingVariableDeclarations, + firstBranch, ifStatementText); + } + if (ifStatementText.length() == 0) return; + final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); + final PsiElementFactory factory = psiFacade.getElementFactory(); + if (hadSideEffects) { + final PsiStatement declarationStatement = + factory.createStatementFromText(declarationString, + switchStatement); + final PsiStatement ifStatement = + factory.createStatementFromText(ifStatementText.toString(), + switchStatement); + final PsiElement parent = switchStatement.getParent(); + parent.addBefore(declarationStatement, switchStatement); + switchStatement.replace(ifStatement); + } + else { + final PsiStatement newStatement = + factory.createStatementFromText(ifStatementText.toString(), + switchStatement); + switchStatement.replace(newStatement); + } + } + + private static String getCaseValueText(PsiExpression value) { + if (value == null) { + return ""; + } + if (value instanceof PsiParenthesizedExpression) { + final PsiParenthesizedExpression parenthesizedExpression = + (PsiParenthesizedExpression)value; + final PsiExpression expression = + parenthesizedExpression.getExpression(); + return getCaseValueText(expression); + } + if (!(value instanceof PsiReferenceExpression)) { + return value.getText(); + } + final PsiReferenceExpression referenceExpression = + (PsiReferenceExpression)value; + final PsiElement target = referenceExpression.resolve(); + final String text = referenceExpression.getText(); + if (!(target instanceof PsiEnumConstant)) { + return value.getText(); + } + final PsiEnumConstant enumConstant = (PsiEnumConstant)target; + final PsiClass aClass = enumConstant.getContainingClass(); + if (aClass == null) { + return value.getText(); + } + final String name = aClass.getQualifiedName(); + return name + '.' + text; + } + + private static void dumpBranch( + String expressionText, List caseValues, + List bodyStatements, + Set variables, boolean firstBranch, + boolean useEquals, + @NonNls StringBuilder ifStatementString) { + if (!firstBranch) { + ifStatementString.append("else "); + } + dumpCaseValues(expressionText, caseValues, useEquals, + ifStatementString); + dumpBody(bodyStatements, variables, ifStatementString); + } + + private static void dumpDefaultBranch( + List bodyStatements, + Set variables, boolean firstBranch, + @NonNls StringBuilder ifStatementString) { + if (!firstBranch) { + ifStatementString.append("else "); + } + dumpBody(bodyStatements, variables, ifStatementString); + } + + private static void dumpCaseValues( + String expressionText, List caseValues, boolean useEquals, + @NonNls StringBuilder ifStatementString) { + ifStatementString.append("if("); + boolean firstCaseValue = true; + for (String caseValue : caseValues) { + if (!firstCaseValue) { + ifStatementString.append("||"); + } + firstCaseValue = false; + ifStatementString.append(expressionText); + if (useEquals) { + ifStatementString.append(".equals("); + ifStatementString.append(caseValue); + ifStatementString.append(')'); + } + else { + ifStatementString.append("=="); + ifStatementString.append(caseValue); + } + } + ifStatementString.append(')'); + } + + private static void dumpBody(List bodyStatements, + Set variables, + @NonNls StringBuilder ifStatementString) { + ifStatementString.append('{'); + for (PsiLocalVariable variable : variables) { + if (ReferencesSearch.search(variable, new LocalSearchScope(bodyStatements.toArray(new PsiElement[bodyStatements.size()]))).findFirst() != null) { + final PsiType varType = variable.getType(); + ifStatementString.append(varType.getPresentableText()); + ifStatementString.append(' '); + ifStatementString.append(variable.getName()); + ifStatementString.append(';'); + } + } + for (PsiElement bodyStatement : bodyStatements) { + if (bodyStatement instanceof PsiBlockStatement) { + final PsiBlockStatement blockStatement = + (PsiBlockStatement)bodyStatement; + final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); + final PsiStatement[] statements = codeBlock.getStatements(); + for (PsiStatement statement : statements) { + appendElement(statement, ifStatementString); + } + } + else { + appendElement(bodyStatement, ifStatementString); + } + } + ifStatementString.append("\n}"); + } + + private static void appendElement( + PsiElement element, @NonNls StringBuilder ifStatementString) { + if (element instanceof PsiBreakStatement) { + final PsiBreakStatement breakStatement = + (PsiBreakStatement)element; + final PsiIdentifier identifier = + breakStatement.getLabelIdentifier(); + if (identifier == null) { + return; + } + } + final String text = element.getText(); + ifStatementString.append(text); + } +} diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SwitchStatementBranch.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SwitchStatementBranch.java new file mode 100644 index 000000000000..f361a95e1cf7 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SwitchStatementBranch.java @@ -0,0 +1,88 @@ +/* + * Copyright 2003-2009 Dave Griffith, Bas Leijdekkers + * + * 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.daemon.impl.quickfix; + +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiLocalVariable; + +import java.util.*; + +class SwitchStatementBranch { + + private final Set m_pendingVariableDeclarations = + new HashSet(5); + private final List m_caseValues = + new ArrayList(2); + private final List m_bodyElements = + new ArrayList(5); + private final List m_pendingWhiteSpace = + new ArrayList(2); + private boolean m_default = false; + private boolean m_hasStatements = false; + + public void addCaseValue(String labelString) { + m_caseValues.add(labelString); + } + + public void addStatement(PsiElement statement) { + m_hasStatements = true; + addElement(statement); + } + + public void addComment(PsiElement comment) { + addElement(comment); + } + + private void addElement(PsiElement element) { + m_bodyElements.addAll(m_pendingWhiteSpace); + m_pendingWhiteSpace.clear(); + m_bodyElements.add(element); + } + + public void addWhiteSpace(PsiElement statement) { + if (!m_bodyElements.isEmpty()) { + m_pendingWhiteSpace.add(statement); + } + } + + public List getCaseValues() { + return Collections.unmodifiableList(m_caseValues); + } + + public List getBodyElements() { + return Collections.unmodifiableList(m_bodyElements); + } + + public boolean isDefault() { + return m_default; + } + + public void setDefault() { + m_default = true; + } + + public boolean hasStatements() { + return m_hasStatements; + } + + public void addPendingVariableDeclarations(Set vars) { + m_pendingVariableDeclarations.addAll(vars); + } + + public Set getPendingVariableDeclarations() { + return Collections.unmodifiableSet(m_pendingVariableDeclarations); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/after1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/after1.java new file mode 100644 index 000000000000..132822279ce4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/after1.java @@ -0,0 +1,8 @@ +// "Replace 'switch' with 'if'" "true" +class Test { + void foo(float f) { + if (f == 0) { + System.out.println(f); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before1.java new file mode 100644 index 000000000000..56d0be102861 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before1.java @@ -0,0 +1,9 @@ +// "Replace 'switch' with 'if'" "true" +class Test { + void foo(float f) { + switch (f) { + case 0: + System.out.println(f); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before2.java new file mode 100644 index 000000000000..e94e3fd5546a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before2.java @@ -0,0 +1,7 @@ +// "Replace 'switch' with 'if'" "false" +class Test { + void foo(float f) { + switch (f) { + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before3.java new file mode 100644 index 000000000000..bb70140dd635 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf/before3.java @@ -0,0 +1,8 @@ +// "Replace 'switch' with 'if'" "false" +class Test { + void foo(float f) { + switch (f) { + case + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ConvertSwitchToIfTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ConvertSwitchToIfTest.java new file mode 100644 index 000000000000..1d7123e4a132 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ConvertSwitchToIfTest.java @@ -0,0 +1,26 @@ +/* + * 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.daemon.quickFix; + +public class ConvertSwitchToIfTest extends LightQuickFixTestCase { + public void test() throws Exception { doAllTests(); } + + @Override + protected String getBasePath() { + return "/codeInsight/daemonCodeAnalyzer/quickFix/convertSwitchToIf"; + } +} + diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceSwitchWithIfIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceSwitchWithIfIntention.java index 38723ade34e4..fba3bb404db5 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceSwitchWithIfIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceSwitchWithIfIntention.java @@ -15,24 +15,14 @@ */ package com.siyeh.ipp.switchtoif; -import com.intellij.openapi.project.Project; +import com.intellij.codeInsight.daemon.impl.quickfix.ConvertSwitchToIfIntention; import com.intellij.psi.*; -import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.util.IncorrectOperationException; import com.siyeh.ipp.base.Intention; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.ControlFlowUtils; -import com.siyeh.ipp.psiutils.SideEffectChecker; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - public class ReplaceSwitchWithIfIntention extends Intention { - @Override @NotNull public PsiElementPredicate getElementPredicate() { @@ -48,291 +38,10 @@ public class ReplaceSwitchWithIfIntention extends Intention { if (switchStatement == null) { return; } - doProcessIntention(switchStatement); + ConvertSwitchToIfIntention.doProcessIntention(switchStatement); } public static boolean canProcess(@NotNull PsiSwitchStatement switchLabelStatement) { return SwitchPredicate.checkSwitchStatement(switchLabelStatement); } - - public static void doProcessIntention(@NotNull PsiSwitchStatement switchStatement) { - final PsiExpression switchExpression = switchStatement.getExpression(); - if (switchExpression == null) { - return; - } - final PsiType switchExpressionType = switchExpression.getType(); - if (switchExpressionType == null) { - return; - } - final boolean isSwitchOnString = - switchExpressionType.equalsToText("java.lang.String"); - final String declarationString; - final boolean hadSideEffects; - final String expressionText; - final Project project = switchStatement.getProject(); - if (SideEffectChecker.mayHaveSideEffects(switchExpression)) { - hadSideEffects = true; - - final JavaCodeStyleManager javaCodeStyleManager = - JavaCodeStyleManager.getInstance(project); - final String variableName; - if (isSwitchOnString) { - variableName = javaCodeStyleManager.suggestUniqueVariableName( - "s", switchExpression, true); - } - else { - variableName = javaCodeStyleManager.suggestUniqueVariableName( - "i", switchExpression, true); - } - expressionText = variableName; - declarationString = - switchExpressionType.getPresentableText() + ' ' + - variableName + " = " + - switchExpression.getText() + ';'; - } - else { - hadSideEffects = false; - declarationString = null; - expressionText = switchExpression.getText(); - } - final PsiCodeBlock body = switchStatement.getBody(); - if (body == null) { - return; - } - final List openBranches = - new ArrayList(); - final Set declaredVariables = - new HashSet(); - final List allBranches = - new ArrayList(); - SwitchStatementBranch currentBranch = null; - final PsiElement[] children = body.getChildren(); - for (int i = 1; i < children.length - 1; i++) { - final PsiElement statement = children[i]; - if (statement instanceof PsiSwitchLabelStatement) { - final PsiSwitchLabelStatement label = - (PsiSwitchLabelStatement)statement; - if (currentBranch == null) { - openBranches.clear(); - currentBranch = new SwitchStatementBranch(); - currentBranch.addPendingVariableDeclarations(declaredVariables); - allBranches.add(currentBranch); - openBranches.add(currentBranch); - } - else if (currentBranch.hasStatements()) { - currentBranch = new SwitchStatementBranch(); - allBranches.add(currentBranch); - openBranches.add(currentBranch); - } - if (label.isDefaultCase()) { - currentBranch.setDefault(); - } - else { - final PsiExpression value = label.getCaseValue(); - final String valueText = getCaseValueText(value); - currentBranch.addCaseValue(valueText); - } - } - else { - if (statement instanceof PsiStatement) { - if (statement instanceof PsiDeclarationStatement) { - final PsiDeclarationStatement declarationStatement = - (PsiDeclarationStatement)statement; - final PsiElement[] elements = - declarationStatement.getDeclaredElements(); - for (PsiElement varElement : elements) { - final PsiLocalVariable variable = - (PsiLocalVariable)varElement; - declaredVariables.add(variable); - } - } - for (SwitchStatementBranch branch : openBranches) { - branch.addStatement(statement); - } - if (!ControlFlowUtils.statementMayCompleteNormally( - (PsiStatement)statement)) { - currentBranch = null; - } - } - else { - for (SwitchStatementBranch branch : openBranches) { - if (statement instanceof PsiWhiteSpace) { - branch.addWhiteSpace(statement); - } - else { - branch.addComment(statement); - } - } - } - } - } - final StringBuilder ifStatementText = new StringBuilder(); - boolean firstBranch = true; - SwitchStatementBranch defaultBranch = null; - for (SwitchStatementBranch branch : allBranches) { - if (branch.isDefault()) { - defaultBranch = branch; - } - else { - final List caseValues = branch.getCaseValues(); - final List bodyElements = branch.getBodyElements(); - final Set pendingVariableDeclarations = - branch.getPendingVariableDeclarations(); - dumpBranch(expressionText, caseValues, bodyElements, - pendingVariableDeclarations, firstBranch, - isSwitchOnString, ifStatementText); - firstBranch = false; - } - } - if (defaultBranch != null) { - final List bodyElements = - defaultBranch.getBodyElements(); - final Set pendingVariableDeclarations = - defaultBranch.getPendingVariableDeclarations(); - dumpDefaultBranch(bodyElements, pendingVariableDeclarations, - firstBranch, ifStatementText); - } - final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); - final PsiElementFactory factory = psiFacade.getElementFactory(); - if (hadSideEffects) { - final PsiStatement declarationStatement = - factory.createStatementFromText(declarationString, - switchStatement); - final PsiStatement ifStatement = - factory.createStatementFromText(ifStatementText.toString(), - switchStatement); - final PsiElement parent = switchStatement.getParent(); - parent.addBefore(declarationStatement, switchStatement); - switchStatement.replace(ifStatement); - } - else { - final PsiStatement newStatement = - factory.createStatementFromText(ifStatementText.toString(), - switchStatement); - switchStatement.replace(newStatement); - } - } - - private static String getCaseValueText(PsiExpression value) { - if (value == null) { - return ""; - } - if (value instanceof PsiParenthesizedExpression) { - final PsiParenthesizedExpression parenthesizedExpression = - (PsiParenthesizedExpression)value; - final PsiExpression expression = - parenthesizedExpression.getExpression(); - return getCaseValueText(expression); - } - if (!(value instanceof PsiReferenceExpression)) { - return value.getText(); - } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)value; - final PsiElement target = referenceExpression.resolve(); - final String text = referenceExpression.getText(); - if (!(target instanceof PsiEnumConstant)) { - return value.getText(); - } - final PsiEnumConstant enumConstant = (PsiEnumConstant)target; - final PsiClass aClass = enumConstant.getContainingClass(); - if (aClass == null) { - return value.getText(); - } - final String name = aClass.getQualifiedName(); - return name + '.' + text; - } - - private static void dumpBranch( - String expressionText, List caseValues, - List bodyStatements, - Set variables, boolean firstBranch, - boolean useEquals, - @NonNls StringBuilder ifStatementString) { - if (!firstBranch) { - ifStatementString.append("else "); - } - dumpCaseValues(expressionText, caseValues, useEquals, - ifStatementString); - dumpBody(bodyStatements, variables, ifStatementString); - } - - private static void dumpDefaultBranch( - List bodyStatements, - Set variables, boolean firstBranch, - @NonNls StringBuilder ifStatementString) { - if (!firstBranch) { - ifStatementString.append("else "); - } - dumpBody(bodyStatements, variables, ifStatementString); - } - - private static void dumpCaseValues( - String expressionText, List caseValues, boolean useEquals, - @NonNls StringBuilder ifStatementString) { - ifStatementString.append("if("); - boolean firstCaseValue = true; - for (String caseValue : caseValues) { - if (!firstCaseValue) { - ifStatementString.append("||"); - } - firstCaseValue = false; - ifStatementString.append(expressionText); - if (useEquals) { - ifStatementString.append(".equals("); - ifStatementString.append(caseValue); - ifStatementString.append(')'); - } - else { - ifStatementString.append("=="); - ifStatementString.append(caseValue); - } - } - ifStatementString.append(')'); - } - - private static void dumpBody(List bodyStatements, - Set variables, - @NonNls StringBuilder ifStatementString) { - ifStatementString.append('{'); - for (PsiLocalVariable variable : variables) { - if (SwitchUtils.isUsedByStatementList(variable, bodyStatements)) { - final PsiType varType = variable.getType(); - ifStatementString.append(varType.getPresentableText()); - ifStatementString.append(' '); - ifStatementString.append(variable.getName()); - ifStatementString.append(';'); - } - } - for (PsiElement bodyStatement : bodyStatements) { - if (bodyStatement instanceof PsiBlockStatement) { - final PsiBlockStatement blockStatement = - (PsiBlockStatement)bodyStatement; - final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); - final PsiStatement[] statements = codeBlock.getStatements(); - for (PsiStatement statement : statements) { - appendElement(statement, ifStatementString); - } - } - else { - appendElement(bodyStatement, ifStatementString); - } - } - ifStatementString.append("\n}"); - } - - private static void appendElement( - PsiElement element, @NonNls StringBuilder ifStatementString) { - if (element instanceof PsiBreakStatement) { - final PsiBreakStatement breakStatement = - (PsiBreakStatement)element; - final PsiIdentifier identifier = - breakStatement.getLabelIdentifier(); - if (identifier == null) { - return; - } - } - final String text = element.getText(); - ifStatementString.append(text); - } } \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/switchtoif/replaceSwitchToIf/ReplaceInt.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/switchtoif/replaceSwitchToIf/ReplaceInt.java new file mode 100644 index 000000000000..95f58a5682ca --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/switchtoif/replaceSwitchToIf/ReplaceInt.java @@ -0,0 +1,8 @@ +class T { + void foo(int i) { + switch (i) { + case 0: + System.out.println(i); + } + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/switchtoif/replaceSwitchToIf/ReplaceInt_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/switchtoif/replaceSwitchToIf/ReplaceInt_after.java new file mode 100644 index 000000000000..2273e0f6c99b --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/switchtoif/replaceSwitchToIf/ReplaceInt_after.java @@ -0,0 +1,7 @@ +class T { + void foo(int i) { + if (i == 0) { + System.out.println(i); + } + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/switchtoif/ReplaceSwitchWithIflIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/switchtoif/ReplaceSwitchWithIflIntentionTest.java new file mode 100644 index 000000000000..05c4f36ef19d --- /dev/null +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/switchtoif/ReplaceSwitchWithIflIntentionTest.java @@ -0,0 +1,35 @@ +/* + * 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.siyeh.ipp.switchtoif; + +import com.siyeh.ipp.IPPTestCase; + +public class ReplaceSwitchWithIflIntentionTest extends IPPTestCase { + + public void testReplaceInt() { + doTest(); + } + + @Override + protected String getIntentionName() { + return "Replace 'switch' with 'if'"; + } + + @Override + protected String getRelativePath() { + return "switchtoif/replaceSwitchToIf"; + } +} diff --git a/plugins/android/src/org/jetbrains/android/inspections/AndroidNonConstantResIdsInSwitchInspection.java b/plugins/android/src/org/jetbrains/android/inspections/AndroidNonConstantResIdsInSwitchInspection.java index 75a7e8d4f450..8513e4c9d2eb 100644 --- a/plugins/android/src/org/jetbrains/android/inspections/AndroidNonConstantResIdsInSwitchInspection.java +++ b/plugins/android/src/org/jetbrains/android/inspections/AndroidNonConstantResIdsInSwitchInspection.java @@ -1,5 +1,6 @@ package org.jetbrains.android.inspections; +import com.intellij.codeInsight.daemon.impl.quickfix.ConvertSwitchToIfIntention; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.LocalQuickFix; import com.intellij.codeInspection.ProblemDescriptor; @@ -111,7 +112,7 @@ public class AndroidNonConstantResIdsInSwitchInspection extends LocalInspectionT return; } - ReplaceSwitchWithIfIntention.doProcessIntention(switchStatement); + ConvertSwitchToIfIntention.doProcessIntention(switchStatement); } } } From 8ff182bce0423061d327b1a141ed2239ac95f715 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 23 Feb 2012 11:43:28 +0100 Subject: [PATCH 03/13] wording (IDEA-81544) --- .../refactoring/changeSignature/DefaultValueChooser.form | 2 +- .../refactoring/changeSignature/DefaultValueChooser.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.form b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.form index f12544a32d5f..a697eb70f797 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.form +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.form @@ -35,7 +35,7 @@ - + diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java index 62a2d2bc1cc2..5b4719b9c6b7 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java @@ -59,7 +59,7 @@ public class DefaultValueChooser extends DialogWrapper{ myValueEditor.setEnabled(false); myFeelLuckyDescription.setText("In method call place variable of the same type would be searched.\n" + "When exactly one is found - it would be used.\n" + - "Blank place would be used otherwise"); + "Parameter place would be leaved blank otherwise"); myFeelLuckyDescription.setUI(new MultiLineLabelUI()); myBlankDescription.setUI(new MultiLineLabelUI()); myValueEditor.setText(defaultValue); From 09a9f593fcbf7ff5979dbb76af65fb1525719f53 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 22 Feb 2012 20:37:52 +0100 Subject: [PATCH 04/13] finish list popups on mouse release. It's more natural, doesn't lead to stuck mouse cursor, and should fix IDEA-48927 (Mouse click in a pop up moves cursor and makes selection in underlying editor) --- .../com/intellij/openapi/ui/popup/PopupChooserBuilder.java | 4 ++-- .../src/com/intellij/ui/popup/list/ListPopupImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java index bfb962865369..f82e36b483c3 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java @@ -203,8 +203,8 @@ public class PopupChooserBuilder { (list != null ? list : myChooserComponent).addMouseListener(new MouseAdapter() { @Override - public void mousePressed(MouseEvent e) { - if (UIUtil.isActionClick(e) && !UIUtil.isSelectionButtonDown(e) && !e.isConsumed()) { + public void mouseReleased(MouseEvent e) { + if (UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED) && !UIUtil.isSelectionButtonDown(e) && !e.isConsumed()) { closePopup(true, e, true); } } diff --git a/platform/platform-impl/src/com/intellij/ui/popup/list/ListPopupImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/list/ListPopupImpl.java index dcbe7f23d7c6..64213cc37d00 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/list/ListPopupImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/list/ListPopupImpl.java @@ -379,7 +379,7 @@ public class ListPopupImpl extends WizardPopup implements ListPopup { } protected boolean isActionClick(MouseEvent e) { - return UIUtil.isActionClick(e, MouseEvent.MOUSE_PRESSED, true); + return UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED, true); } public Object getSelectedValue() { @@ -389,7 +389,7 @@ public class ListPopupImpl extends WizardPopup implements ListPopup { private class MyMouseListener extends MouseAdapter { @Override - public void mousePressed(MouseEvent e) { + public void mouseReleased(MouseEvent e) { if (!isActionClick(e)) return; IdeEventQueue.getInstance().blockNextEvents(e); // sometimes, after popup close, MOUSE_RELEASE event delivers to other components final Object selectedValue = myList.getSelectedValue(); From b9373dafcdb77dbe0f6dda9161684ddb978b5b7e Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 23 Feb 2012 14:13:19 +0100 Subject: [PATCH 05/13] don't hide switcher if specific UI option is set --- .../editor/EditorTabsConfigurable.form | 38 +++++++++++++++-- .../editor/EditorTabsConfigurable.java | 6 +++ .../src/com/intellij/ide/ui/UISettings.java | 1 + .../com/intellij/ide/actions/Switcher.java | 41 +++++++++++-------- 4 files changed, 65 insertions(+), 21 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.form b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.form index fc88e11f7982..6b1ede8c1ed8 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.form +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.form @@ -1,9 +1,9 @@
- + - + @@ -95,7 +95,7 @@ - + @@ -220,6 +220,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.java b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.java index 68a5ad08b39e..520abd9e2833 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.java @@ -44,6 +44,7 @@ public class EditorTabsConfigurable implements EditorOptionsProvider { private JCheckBox myShowCloseButtonOnCheckBox; private JCheckBox myShowDirectoryInTabCheckBox; private JRadioButton myActivateRightNeighbouringTabRadioButton; + private JCheckBox mySwitcherPolicy; public EditorTabsConfigurable() { myEditorTabPlacement.setModel(new DefaultComboBoxModel(new Object[]{ @@ -100,6 +101,7 @@ public class EditorTabsConfigurable implements EditorOptionsProvider { myShowDirectoryInTabCheckBox.setSelected(uiSettings.SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES); myEditorTabLimitField.setText(Integer.toString(uiSettings.EDITOR_TAB_LIMIT)); myShowCloseButtonOnCheckBox.setSelected(uiSettings.SHOW_CLOSE_BUTTON); + mySwitcherPolicy.setSelected(uiSettings.HIDE_SWITCHER_ON_CONTROL_RELEASE); if (uiSettings.CLOSE_NON_MODIFIED_FILES_FIRST) { myCloseNonModifiedFilesFirstRadio.setSelected(true); @@ -130,6 +132,9 @@ public class EditorTabsConfigurable implements EditorOptionsProvider { if (isModified(myShowCloseButtonOnCheckBox, uiSettings.SHOW_CLOSE_BUTTON)) uiSettingsChanged = true; uiSettings.SHOW_CLOSE_BUTTON = myShowCloseButtonOnCheckBox.isSelected(); + if (isModified(mySwitcherPolicy, uiSettings.HIDE_SWITCHER_ON_CONTROL_RELEASE)) uiSettingsChanged = true; + uiSettings.HIDE_SWITCHER_ON_CONTROL_RELEASE = mySwitcherPolicy.isSelected(); + final int tabPlacement = ((Integer)myEditorTabPlacement.getSelectedItem()).intValue(); if (uiSettings.EDITOR_TAB_PLACEMENT != tabPlacement) uiSettingsChanged = true; uiSettings.EDITOR_TAB_PLACEMENT = tabPlacement; @@ -172,6 +177,7 @@ public class EditorTabsConfigurable implements EditorOptionsProvider { isModified |= myScrollTabLayoutInEditorCheckBox.isSelected() != uiSettings.SCROLL_TAB_LAYOUT_IN_EDITOR; isModified |= myShowCloseButtonOnCheckBox.isSelected() != uiSettings.SHOW_CLOSE_BUTTON; + isModified |= mySwitcherPolicy.isSelected() != uiSettings.HIDE_SWITCHER_ON_CONTROL_RELEASE; isModified |= isModified(myCloseNonModifiedFilesFirstRadio, uiSettings.CLOSE_NON_MODIFIED_FILES_FIRST); isModified |= isModified(myActivateMRUEditorOnCloseRadio, uiSettings.ACTIVATE_MRU_EDITOR_ON_CLOSE); diff --git a/platform/platform-api/src/com/intellij/ide/ui/UISettings.java b/platform/platform-api/src/com/intellij/ide/ui/UISettings.java index c8b8309a0652..01797fe0d95e 100644 --- a/platform/platform-api/src/com/intellij/ide/ui/UISettings.java +++ b/platform/platform-api/src/com/intellij/ide/ui/UISettings.java @@ -92,6 +92,7 @@ public class UISettings implements PersistentStateComponent, Exporta public int MAX_LOOKUP_WIDTH = 500; public int MAX_LOOKUP_LIST_HEIGHT = 11; public boolean HIDE_NAVIGATION_ON_FOCUS_LOSS = true; + public boolean HIDE_SWITCHER_ON_CONTROL_RELEASE = true; /** * Defines whether asterisk is shown on modified editor tab or not diff --git a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java index 647c650201a0..63b0ae1525a1 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java @@ -17,6 +17,7 @@ package com.intellij.ide.actions; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.IdeEventQueue; +import com.intellij.ide.ui.UISettings; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.markup.EffectType; @@ -113,23 +114,25 @@ public class Switcher extends AnAction implements DumbAware { } TW_SHORTCUT = new CustomShortcutSet(shortcuts.toArray(new Shortcut[shortcuts.size()])); - IdeEventQueue.getInstance().addPostprocessor(new IdeEventQueue.EventDispatcher() { - @Override - public boolean dispatch(AWTEvent event) { - ToolWindow tw; - if (SWITCHER != null && event instanceof KeyEvent) { - final KeyEvent keyEvent = (KeyEvent)event; - if (event.getID() == KEY_RELEASED && keyEvent.getKeyCode() == CTRL_KEY) { - SwingUtilities.invokeLater(CHECKER); - } - else if (event.getID() == KEY_PRESSED && (tw = SWITCHER.twShortcuts.get(String.valueOf((char)keyEvent.getKeyCode()))) != null) { - SWITCHER.myPopup.closeOk(null); - tw.activate(null, true, true); + + IdeEventQueue.getInstance().addPostprocessor(new IdeEventQueue.EventDispatcher() { + @Override + public boolean dispatch(AWTEvent event) { + ToolWindow tw; + if (SWITCHER != null && event instanceof KeyEvent) { + final KeyEvent keyEvent = (KeyEvent)event; + if (event.getID() == KEY_RELEASED && keyEvent.getKeyCode() == CTRL_KEY && UISettings.getInstance().HIDE_SWITCHER_ON_CONTROL_RELEASE) { + SwingUtilities.invokeLater(CHECKER); + } + else if (event.getID() == KEY_PRESSED && (tw = SWITCHER.twShortcuts.get(String.valueOf((char)keyEvent.getKeyCode()))) != null) { + SWITCHER.myPopup.closeOk(null); + tw.activate(null, true, true); + } } + return false; } - return false; - } - }, null); + }, null); + } @NonNls private static final String SWITCHER_TITLE = "Switcher"; @@ -148,6 +151,7 @@ public class Switcher extends AnAction implements DumbAware { } } + assert SWITCHER != null; if (e.getInputEvent().isShiftDown()) { SWITCHER.goBack(); } else { @@ -437,7 +441,8 @@ public class Switcher extends AnAction implements DumbAware { } public void keyReleased(KeyEvent e) { - if (e.getKeyCode() == CTRL_KEY || e.getKeyCode() == VK_ENTER) { + if ((e.getKeyCode() == CTRL_KEY && UISettings.getInstance().HIDE_SWITCHER_ON_CONTROL_RELEASE) + || e.getKeyCode() == VK_ENTER) { navigate(); } else if (e.getKeyCode() == VK_LEFT) { @@ -541,7 +546,7 @@ public class Switcher extends AnAction implements DumbAware { } private void goRight() { - if (isFilesSelected() || !isFilesVisible()) { + if ((isFilesSelected() || !isFilesVisible()) && UISettings.getInstance().HIDE_SWITCHER_ON_CONTROL_RELEASE) { cancel(); } else { @@ -557,7 +562,7 @@ public class Switcher extends AnAction implements DumbAware { } private void goLeft() { - if (isToolWindowsSelected()) { + if (isToolWindowsSelected() && UISettings.getInstance().HIDE_SWITCHER_ON_CONTROL_RELEASE) { cancel(); } else { From 41d65288a225fc8332f88cafb49b402f307cf504 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 23 Feb 2012 14:38:17 +0100 Subject: [PATCH 06/13] DRY --- .../impl/quickfix/ChangeToAppendFix.java | 28 +++--- ...ionInsideStringBufferAppendInspection.java | 85 +------------------ 2 files changed, 20 insertions(+), 93 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeToAppendFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeToAppendFix.java index d8bb0d29aab4..bb0c72cf8c10 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeToAppendFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeToAppendFix.java @@ -77,18 +77,22 @@ public class ChangeToAppendFix implements IntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { if (!CodeInsightUtilBase.prepareFileForWrite(file)) return; - final PsiExpression rhs = myAssignmentExpression.getRExpression(); - if (rhs == null) { - return; - } - final StringBuilder appendCallText = buildAppendExpression(rhs, myLhsType.equalsToText("java.lang.Appendable"), - new StringBuilder(myAssignmentExpression.getLExpression().getText())); - if (appendCallText == null) { - return; - } - final PsiElementFactory factory = JavaPsiFacade.getElementFactory(myAssignmentExpression.getProject()); - final PsiExpression appendCall = factory.createExpressionFromText(appendCallText.toString(), myAssignmentExpression); - myAssignmentExpression.replace(appendCall); + final PsiExpression appendExpression = + buildAppendExpression(myAssignmentExpression.getLExpression(), myAssignmentExpression.getRExpression()); + if (appendExpression == null) return; + myAssignmentExpression.replace(appendExpression); + } + + @Nullable + public static PsiExpression buildAppendExpression(PsiExpression appendable, PsiExpression concatenation) { + if (concatenation == null) return null; + final PsiType type = appendable.getType(); + if (type == null) return null; + final StringBuilder result = + buildAppendExpression(concatenation, type.equalsToText("java.lang.Appendable"), new StringBuilder(appendable.getText())); + if (result == null) return null; + final PsiElementFactory factory = JavaPsiFacade.getElementFactory(appendable.getProject()); + return factory.createExpressionFromText(result.toString(), appendable); } @Nullable diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringConcatenationInsideStringBufferAppendInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringConcatenationInsideStringBufferAppendInspection.java index ce7c82388a84..5ff455099758 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringConcatenationInsideStringBufferAppendInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringConcatenationInsideStringBufferAppendInspection.java @@ -15,6 +15,7 @@ */ package com.siyeh.ig.performance; +import com.intellij.codeInsight.daemon.impl.quickfix.ChangeToAppendFix; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; @@ -28,7 +29,6 @@ import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class StringConcatenationInsideStringBufferAppendInspection extends BaseInspection { @@ -80,18 +80,6 @@ public class StringConcatenationInsideStringBufferAppendInspection extends BaseI if (methodCallExpression == null) { return; } - final PsiMethod method = methodCallExpression.resolveMethod(); - if (method == null) { - return; - } - final PsiClass containingClass = method.getContainingClass(); - if (containingClass == null) { - return; - } - final String qualifiedName = containingClass.getQualifiedName(); - if (qualifiedName == null) { - return; - } final PsiExpression qualifier = methodExpression.getQualifierExpression(); if (qualifier == null) { return; @@ -99,76 +87,11 @@ public class StringConcatenationInsideStringBufferAppendInspection extends BaseI final PsiExpressionList argumentList = methodCallExpression.getArgumentList(); final PsiExpression[] arguments = argumentList.getExpressions(); final PsiExpression argument = arguments[0]; - final boolean useStringValueOf; - useStringValueOf = !qualifiedName.equals(CommonClassNames.JAVA_LANG_STRING_BUFFER) && - !qualifiedName.equals(CommonClassNames.JAVA_LANG_STRING_BUILDER); - @NonNls final StringBuilder newExpressionBuffer = - buildAppendExpression(argument, useStringValueOf, new StringBuilder(qualifier.getText())); - if (newExpressionBuffer == null) { + final PsiExpression appendExpression = ChangeToAppendFix.buildAppendExpression(qualifier, argument); + if (appendExpression == null) { return; } - replaceExpression(methodCallExpression, newExpressionBuffer.toString()); - } - - @Nullable - private static StringBuilder buildAppendExpression(PsiExpression concatenation, boolean useStringValueOf, @NonNls StringBuilder out) - throws IncorrectOperationException { - final PsiType type = concatenation.getType(); - if (type == null) { - return null; - } - if (concatenation instanceof PsiPolyadicExpression && type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { - PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)concatenation; - final PsiExpression[] operands = polyadicExpression.getOperands(); - boolean isConstant = true; - boolean isString = false; - final StringBuilder builder = new StringBuilder(); - for (PsiExpression operand : operands) { - if (isConstant && PsiUtil.isConstantExpression(operand)) { - if (builder.length() != 0) { - builder.append('+'); - } - final PsiType operandType = operand.getType(); - if (operandType != null && operandType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { - isString = true; - } - builder.append(operand.getText()); - } - else { - isConstant = false; - if (builder.length() != 0) { - append(builder, useStringValueOf && !isString, out); - builder.setLength(0); - } - buildAppendExpression(operand, useStringValueOf, out); - } - } - if (builder.length() != 0) { - append(builder, false, out); - } - } - else if (concatenation instanceof PsiParenthesizedExpression) { - final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)concatenation; - final PsiExpression expression = parenthesizedExpression.getExpression(); - if (expression != null) { - return buildAppendExpression(expression, useStringValueOf, out); - } - } - else { - append(concatenation.getText(), useStringValueOf && !type.equalsToText(CommonClassNames.JAVA_LANG_STRING), out); - } - return out; - } - - private static void append(CharSequence text, boolean useStringValueOf, StringBuilder out) { - out.append(".append("); - if (useStringValueOf) { - out.append("String.valueOf(").append(text).append(')'); - } - else { - out.append(text); - } - out.append(')'); + methodCallExpression.replace(appendExpression); } } From 2900451217f02dee8834b45a37fdbf192677251f Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 23 Feb 2012 15:36:45 +0100 Subject: [PATCH 07/13] Use the right name for "Call to 'Runtime.exec()' with non-constant string" inspection --- ...meExecWithNonConstantStringInspection.java | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/security/RuntimeExecWithNonConstantStringInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/security/RuntimeExecWithNonConstantStringInspection.java index fb35bb9b03c4..bd31af868aed 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/security/RuntimeExecWithNonConstantStringInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/security/RuntimeExecWithNonConstantStringInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,14 @@ package com.siyeh.ig.security; import com.intellij.psi.*; -import com.intellij.psi.util.ConstantExpressionUtil; +import com.intellij.psi.util.PsiUtil; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -public class RuntimeExecWithNonConstantStringInspection - extends BaseInspection { +public class RuntimeExecWithNonConstantStringInspection extends BaseInspection { @Override @NotNull @@ -35,15 +34,13 @@ public class RuntimeExecWithNonConstantStringInspection @Override @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "runtime.exec.call.display.name"); + return InspectionGadgetsBundle.message("runtime.exec.with.non.constant.string.display.name"); } @Override @NotNull protected String buildErrorString(Object... infos) { - return InspectionGadgetsBundle.message( - "runtime.exec.with.non.constant.string.problem.descriptor"); + return InspectionGadgetsBundle.message("runtime.exec.with.non.constant.string.problem.descriptor"); } @Override @@ -54,13 +51,10 @@ public class RuntimeExecWithNonConstantStringInspection private static class RuntimeExecVisitor extends BaseInspectionVisitor { @Override - public void visitMethodCallExpression( - @NotNull PsiMethodCallExpression expression) { + public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) { super.visitMethodCallExpression(expression); - final PsiReferenceExpression methodExpression = - expression.getMethodExpression(); - @NonNls final String methodName = - methodExpression.getReferenceName(); + final PsiReferenceExpression methodExpression = expression.getMethodExpression(); + @NonNls final String methodName = methodExpression.getReferenceName(); if (!"exec".equals(methodName)) { return; } @@ -77,22 +71,16 @@ public class RuntimeExecWithNonConstantStringInspection return; } final PsiExpressionList argumentList = expression.getArgumentList(); - final PsiExpression[] args = argumentList.getExpressions(); - if (args.length == 0) { + final PsiExpression[] arguments = argumentList.getExpressions(); + if (arguments.length == 0) { return; } - final PsiExpression arg = args[0]; - final PsiType type = arg.getType(); - if (type == null) { + final PsiExpression argument = arguments[0]; + final PsiType type = argument.getType(); + if (type == null || !type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { return; } - final String typeText = type.getCanonicalText(); - if (!CommonClassNames.JAVA_LANG_STRING.equals(typeText)) { - return; - } - final String stringValue = - (String)ConstantExpressionUtil.computeCastTo(arg, type); - if (stringValue != null) { + if (PsiUtil.isConstantExpression(argument)) { return; } registerMethodCallError(expression); From f041c0d1ac2c96a766681dd4af16e816f936bfbe Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 23 Feb 2012 15:37:34 +0100 Subject: [PATCH 08/13] improve "Lock acquired but not safely unlocked" inspection description --- .../src/inspectionDescriptions/SafeLock.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/SafeLock.html b/plugins/InspectionGadgets/src/inspectionDescriptions/SafeLock.html index d03514462acd..1bb1208abd0f 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/SafeLock.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/SafeLock.html @@ -1,9 +1,7 @@ - -This inspection reports any Lock resource which is not acquired in front of a -try block and unlocked in the corresponding -finally block. Such resources may +This inspection reports any java.util.concurrent.locks.Lock resource which is not acquired in front of a +try block and unlocked in the corresponding finally block. Such resources may be inadvertently leaked if an exception is thrown before the resource is closed.

Powered by InspectionGadgets From b8c16163bd342e9c74fdc6d1babb5b52df930bdc Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 23 Feb 2012 15:41:59 +0100 Subject: [PATCH 09/13] EA-31159 --- .../dateOrRevision/SimpleRevision.java | 14 ++------------ .../cvsSupport2/cvsstatuses/CvsChangeProvider.java | 7 ++++--- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/dateOrRevision/SimpleRevision.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/dateOrRevision/SimpleRevision.java index d8254a22ce68..9100952c8e0c 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/dateOrRevision/SimpleRevision.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/dateOrRevision/SimpleRevision.java @@ -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. @@ -15,12 +15,8 @@ */ package com.intellij.cvsSupport2.cvsoperations.dateOrRevision; -import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.cvsSupport2.history.CvsRevisionNumber; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; -import org.netbeans.lib.cvsclient.admin.Entry; import org.netbeans.lib.cvsclient.command.Command; @@ -30,17 +26,11 @@ import org.netbeans.lib.cvsclient.command.Command; public class SimpleRevision implements RevisionOrDate { private final String myRevision; - public static SimpleRevision createForTheSameVersionOf(@NotNull VirtualFile file) { - Entry entry = CvsEntriesManager.getInstance().getEntryFor(file.getParent(), file.getName()); - return new SimpleRevision(entry.getRevision()); - - } - public SimpleRevision(String revision) { myRevision = prepareRevision(revision); } - private String prepareRevision(String revision) { + private static String prepareRevision(String revision) { if (revision == null) { return null; } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsstatuses/CvsChangeProvider.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsstatuses/CvsChangeProvider.java index 91f7ac8379fc..b22647f5e63e 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsstatuses/CvsChangeProvider.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsstatuses/CvsChangeProvider.java @@ -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. @@ -567,9 +567,10 @@ public class CvsChangeProvider implements ChangeProvider { final Entry entry = myEntriesManager.getEntryFor(virtualFile.getParent(), virtualFile.getName()); if (entry != null) { revision = entry.getRevision(); + operation = GetFileContentOperation.createForFile(virtualFile, new SimpleRevision(revision)); + } else { + operation = GetFileContentOperation.createForFile(myPath); } - - operation = GetFileContentOperation.createForFile(virtualFile, SimpleRevision.createForTheSameVersionOf(virtualFile)); } else { operation = GetFileContentOperation.createForFile(myPath); From 43e479558ee13cbf5f7ea0907cdde1865c7a8ba7 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 23 Feb 2012 16:19:19 +0100 Subject: [PATCH 10/13] fix InputException on clicking Edit by Field... on an empty CVS root (EA-33961) --- .../config/ui/CvsRootAsStringConfigurationPanel.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootAsStringConfigurationPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootAsStringConfigurationPanel.java index 3eb7cf414bf6..08aeca23a90a 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootAsStringConfigurationPanel.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootAsStringConfigurationPanel.java @@ -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. @@ -34,6 +34,7 @@ import java.util.Collection; * author: lesya */ public class CvsRootAsStringConfigurationPanel { + private JTextField myCvsRoot; private JButton myEditFieldByFieldButton; private final Ref myIsUpdating; @@ -54,7 +55,7 @@ public class CvsRootAsStringConfigurationPanel { public void actionPerformed(ActionEvent e) { final CvsRootConfiguration cvsRootConfiguration = CvsApplicationLevelConfiguration.createNewConfiguration(CvsApplicationLevelConfiguration.getInstance()); - saveTo(cvsRootConfiguration); + cvsRootConfiguration.CVS_ROOT = FormUtils.getFieldValue(myCvsRoot, false); final EditCvsConfigurationFieldByFieldDialog dialog = new EditCvsConfigurationFieldByFieldDialog(myCvsRoot.getText()); dialog.show(); if (dialog.isOK()) { From 029fb4020408e079f38665762c29f33bb7052443 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 23 Feb 2012 16:20:17 +0100 Subject: [PATCH 11/13] Make Global CVS Settings... and Configure CVS Roots... DumbAware --- .../actions/ConfigureCvsRootsAction.java | 15 +++++---------- .../cvsSupport2/actions/CvsGlobalAction.java | 8 +++++--- .../cvsSupport2/actions/GlobalSettingsAction.java | 5 +++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/ConfigureCvsRootsAction.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/ConfigureCvsRootsAction.java index f82d28bbc67f..938c25c452f1 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/ConfigureCvsRootsAction.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/ConfigureCvsRootsAction.java @@ -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. @@ -15,13 +15,10 @@ */ package com.intellij.cvsSupport2.actions; -import com.intellij.cvsSupport2.actions.cvsContext.CvsContextWrapper; -import com.intellij.openapi.vcs.actions.VcsContext; import com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration; import com.intellij.cvsSupport2.config.CvsRootConfiguration; import com.intellij.cvsSupport2.config.ui.CvsConfigurationsListEditor; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.vcs.actions.VcsContext; import java.util.ArrayList; import java.util.List; @@ -32,15 +29,13 @@ import java.util.List; public class ConfigureCvsRootsAction extends CvsGlobalAction { public void actionPerformed(AnActionEvent e) { - VcsContext cvsContext = CvsContextWrapper.createCachedInstance(e); - CvsApplicationLevelConfiguration configuration = CvsApplicationLevelConfiguration.getInstance(); - List configurations = configuration.CONFIGURATIONS; - CvsConfigurationsListEditor cvsConfigurationsListEditor = - new CvsConfigurationsListEditor(new ArrayList(configurations), cvsContext.getProject()); + final CvsApplicationLevelConfiguration configuration = CvsApplicationLevelConfiguration.getInstance(); + final List configurations = configuration.CONFIGURATIONS; + final CvsConfigurationsListEditor cvsConfigurationsListEditor = + new CvsConfigurationsListEditor(new ArrayList(configurations), e.getProject()); cvsConfigurationsListEditor.show(); if (cvsConfigurationsListEditor.isOK()) { configuration.CONFIGURATIONS = cvsConfigurationsListEditor.getConfigurations(); } - } } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/CvsGlobalAction.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/CvsGlobalAction.java index 5c3d2c08c8c9..1347a6fe4ba6 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/CvsGlobalAction.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/CvsGlobalAction.java @@ -20,11 +20,13 @@ import com.intellij.cvsSupport2.actions.cvsContext.CvsContextWrapper; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.DumbAware; + +public abstract class CvsGlobalAction extends AnAction implements DumbAware { -public abstract class CvsGlobalAction extends AnAction { public void update(AnActionEvent e) { - CvsContext cvsContext = CvsContextWrapper.createInstance(e); - Presentation presentation = e.getPresentation(); + final CvsContext cvsContext = CvsContextWrapper.createInstance(e); + final Presentation presentation = e.getPresentation(); if (cvsContext.cvsIsActive()) { presentation.setVisible(true); presentation.setEnabled(true); diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/GlobalSettingsAction.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/GlobalSettingsAction.java index dc22ee746412..69f169370e9e 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/GlobalSettingsAction.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/GlobalSettingsAction.java @@ -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. @@ -21,7 +21,8 @@ import com.intellij.openapi.actionSystem.AnActionEvent; /** * author: lesya */ -public class GlobalSettingsAction extends CvsGlobalAction{ +public class GlobalSettingsAction extends CvsGlobalAction { + public void actionPerformed(AnActionEvent e) { new ConfigureCvsGlobalSettingsDialog(e.getProject()).show(); } From 628163b89dd440a7326e474b1f975717f01ad15c Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Thu, 23 Feb 2012 21:03:12 +0400 Subject: [PATCH 12/13] MetaModel --- .../android-designer/src/META-INF/plugin.xml | 5 + .../AndroidDesignerEditorProvider.java | 8 +- .../componentTree/AndroidTreeDecorator.java | 14 +- .../AndroidDesignerEditorPanel.java | 46 ++---- .../designSurface/CreateOperation.java | 81 ---------- .../designer/designSurface/MoveOperation.java | 100 ------------- .../designSurface/ResizeOperation.java | 81 ---------- .../designer/designSurface/TreeOperation.java | 40 ----- .../android/designer/icons/Button.png | Bin 0 -> 612 bytes .../android/designer/icons/DeviceScreen.png | Bin 0 -> 3609 bytes .../android/designer/icons/LinearLayout.png | Bin 0 -> 403 bytes .../android/designer/icons/TextView.png | Bin 0 -> 326 bytes .../designer/model/RadViewComponent.java | 23 ++- .../android/designer/model/RadViewLayout.java | 29 ---- .../designer/model/ViewsMetaManager.java | 33 +++++ .../designer/model/views-meta-model.xml | 83 +++++++++++ .../palette/ViewsPaletteProvider.java | 45 ++++++ .../intellij/designer/model/MetaManager.java | 139 ++++++++++++++++++ .../intellij/designer/model/MetaModel.java | 98 ++++++++++++ .../intellij/designer/model/RadComponent.java | 9 ++ .../palette/AbstractPaletteProvider.java | 62 ++++++++ .../com/intellij/designer/palette/Group.java | 74 ++++++++++ .../com/intellij/designer/palette/Item.java | 76 ++++++++++ 23 files changed, 669 insertions(+), 377 deletions(-) delete mode 100644 plugins/android-designer/src/com/intellij/android/designer/designSurface/CreateOperation.java delete mode 100644 plugins/android-designer/src/com/intellij/android/designer/designSurface/MoveOperation.java delete mode 100644 plugins/android-designer/src/com/intellij/android/designer/designSurface/ResizeOperation.java delete mode 100644 plugins/android-designer/src/com/intellij/android/designer/designSurface/TreeOperation.java create mode 100644 plugins/android-designer/src/com/intellij/android/designer/icons/Button.png create mode 100644 plugins/android-designer/src/com/intellij/android/designer/icons/DeviceScreen.png create mode 100644 plugins/android-designer/src/com/intellij/android/designer/icons/LinearLayout.png create mode 100644 plugins/android-designer/src/com/intellij/android/designer/icons/TextView.png create mode 100644 plugins/android-designer/src/com/intellij/android/designer/model/ViewsMetaManager.java create mode 100644 plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml create mode 100644 plugins/android-designer/src/com/intellij/android/designer/palette/ViewsPaletteProvider.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaModel.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/AbstractPaletteProvider.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Group.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Item.java diff --git a/plugins/android-designer/src/META-INF/plugin.xml b/plugins/android-designer/src/META-INF/plugin.xml index b808ad518995..eba7e57be3ab 100644 --- a/plugins/android-designer/src/META-INF/plugin.xml +++ b/plugins/android-designer/src/META-INF/plugin.xml @@ -12,6 +12,11 @@ + + + + diff --git a/plugins/android-designer/src/com/intellij/android/designer/AndroidDesignerEditorProvider.java b/plugins/android-designer/src/com/intellij/android/designer/AndroidDesignerEditorProvider.java index 54d96b5af92d..3a150cf5b537 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/AndroidDesignerEditorProvider.java +++ b/plugins/android-designer/src/com/intellij/android/designer/AndroidDesignerEditorProvider.java @@ -34,8 +34,7 @@ import org.jetbrains.annotations.NotNull; * @author Alexander Lobas */ public final class AndroidDesignerEditorProvider implements FileEditorProvider, DumbAware { - @Override - public boolean accept(final @NotNull Project project, final @NotNull VirtualFile file) { + public static boolean acceptLayout(final @NotNull Project project, final @NotNull VirtualFile file) { PsiFile psiFile = ApplicationManager.getApplication().runReadAction(new Computable() { @Override public PsiFile compute() { @@ -47,6 +46,11 @@ public final class AndroidDesignerEditorProvider implements FileEditorProvider, LayoutDomFileDescription.isLayoutFile((XmlFile)psiFile); } + @Override + public boolean accept(final @NotNull Project project, final @NotNull VirtualFile file) { + return acceptLayout(project, file); + } + @NotNull @Override public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) { diff --git a/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java b/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java index adfb60d15977..7738eaab0d47 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java +++ b/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java @@ -17,6 +17,7 @@ package com.intellij.android.designer.componentTree; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.componentTree.TreeComponentDecorator; +import com.intellij.designer.model.MetaModel; import com.intellij.designer.model.RadComponent; import com.intellij.ui.ColoredTreeCellRenderer; @@ -26,7 +27,16 @@ import com.intellij.ui.ColoredTreeCellRenderer; public final class AndroidTreeDecorator extends TreeComponentDecorator { @Override public void decorate(RadComponent component, ColoredTreeCellRenderer renderer) { - RadViewComponent view = (RadViewComponent)component; - renderer.append(view.getTitle()); + MetaModel metaModel = component.getMetaModel(); + + // TODO + if (metaModel == null) { + RadViewComponent viewComponent = (RadViewComponent)component; + renderer.append(viewComponent.getTag().getName()); + } + else { + renderer.append(metaModel.getPaletteItem().getTitle()); + renderer.setIcon(metaModel.getIcon()); + } } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java index fd9e3ace6a87..90ad838fb665 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java @@ -24,6 +24,7 @@ import com.android.resources.UiMode; import com.android.sdklib.IAndroidTarget; import com.intellij.android.designer.componentTree.AndroidTreeDecorator; import com.intellij.android.designer.model.RadViewComponent; +import com.intellij.android.designer.model.ViewsMetaManager; import com.intellij.designer.DesignerToolWindowManager; import com.intellij.designer.componentTree.TreeComponentDecorator; import com.intellij.designer.designSurface.ComponentDecorator; @@ -34,10 +35,12 @@ import com.intellij.designer.designSurface.selection.DirectionResizePoint; import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator; import com.intellij.designer.designSurface.tools.ComponentCreationFactory; import com.intellij.designer.designSurface.tools.CreationTool; +import com.intellij.designer.model.MetaManager; import com.intellij.designer.model.RadComponent; import com.intellij.designer.utils.Position; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; @@ -96,23 +99,6 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { catch (Throwable e) { showError("Parse error: ", e); } - - // TODO: temp code - - myGlassLayer.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(final KeyEvent event) { - if (event.getKeyCode() == KeyEvent.VK_F2) { - myToolProvider.setActiveTool(new CreationTool(true, new ComponentCreationFactory() { - @Override - @NotNull - public RadComponent create() throws Exception { - return new RadViewComponent(null, event.isControlDown() ? "swing" : "android"); - } - })); - } - } - }); } private void reparseFile() { @@ -133,7 +119,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { private void parseFile() throws Throwable { final RadViewComponent[] rootComponents = new RadViewComponent[1]; - + final MetaManager metaManager = ViewsMetaManager.getInstance(myModule.getProject()); final String layoutXmlText = ApplicationManager.getApplication().runReadAction(new Computable() { RadViewComponent myComponent; @@ -144,7 +130,9 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { root.accept(new XmlRecursiveElementVisitor() { @Override public void visitXmlTag(XmlTag tag) { - myComponent = new RadViewComponent(myComponent, tag.getName()); + myComponent = new RadViewComponent(myComponent); + myComponent.setTag(tag); + myComponent.setMetaModel(metaManager.getModelByTag(tag.getName())); if (rootComponents[0] == null) { rootComponents[0] = myComponent; @@ -162,7 +150,12 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { }); // TODO: run in background - createRenderer(layoutXmlText); + try { + createRenderer(layoutXmlText); + } + catch (IndexNotReadyException e) { + createRenderer(layoutXmlText); + } Result result = mySession.getResult(); if (!result.isSuccess()) { @@ -182,10 +175,6 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { rootPanel.setBackground(Color.WHITE); rootPanel.add(rootView); - if (myRootComponent != null) { - myLayeredPane.remove(((RadViewComponent)myRootComponent).getNativeComponent().getParent()); - } - removeNativeRoot(); myRootComponent = rootComponents[0]; myLayeredPane.add(rootPanel, LAYER_COMPONENT); @@ -197,12 +186,13 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { } } - private static void updateRootComponent(RadViewComponent[] rootComponents, List views, JComponent nativeComponent) { + private void updateRootComponent(RadViewComponent[] rootComponents, List views, JComponent nativeComponent) { RadViewComponent rootComponent = rootComponents[0]; int size = views.size(); if (size == 1) { - RadViewComponent newRootComponent = new RadViewComponent(null, "Device Screen"); + RadViewComponent newRootComponent = new RadViewComponent(null); + newRootComponent.setMetaModel(ViewsMetaManager.getInstance(myModule.getProject()).getModelByTag("")); newRootComponent.getChildren().add(rootComponent); rootComponent.setParent(newRootComponent); @@ -223,7 +213,6 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { private static void updateComponent(RadViewComponent component, ViewInfo view, JComponent nativeComponent, int parentX, int parentY) { component.setNativeComponent(nativeComponent); - //System.out.println(view.getClassName() +" = " + mySession.getDefaultProperties(view.getViewObject())); int left = parentX + view.getLeft(); int top = parentY + view.getTop(); @@ -294,9 +283,6 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { @Override protected EditOperation processRootOperation(OperationContext context) { - if (context.is("top_resize")) { - return new ResizeOperation(context); - } return null; } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/CreateOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/CreateOperation.java deleted file mode 100644 index 91128abb0a0d..000000000000 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/CreateOperation.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.android.designer.designSurface; - -import com.intellij.android.designer.model.RadViewComponent; -import com.intellij.designer.designSurface.EditOperation; -import com.intellij.designer.designSurface.FeedbackLayer; -import com.intellij.designer.designSurface.OperationContext; -import com.intellij.designer.designSurface.feedbacks.AlphaComponent; -import com.intellij.designer.model.RadComponent; - -import javax.swing.*; -import java.awt.*; -import java.util.List; - -/** - * @author Alexander Lobas - */ -public class CreateOperation implements EditOperation { - private final OperationContext myContext; - private final RadViewComponent myContainer; - private JComponent myFeedback; - - public CreateOperation(RadViewComponent container, OperationContext context) { - myContainer = container; - myContext = context; - } - - @Override - public void setComponent(RadComponent component) { - } - - @Override - public void setComponents(List components) { - } - - @Override - public void showFeedback() { - FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); - - if (myFeedback == null) { - myFeedback = new AlphaComponent(Color.GREEN, Color.LIGHT_GRAY); - layer.add(myFeedback); - } - - myFeedback.setBounds(myContainer.getBounds(layer)); - layer.repaint(); - } - - @Override - public void eraseFeedback() { - if (myFeedback != null) { - FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); - layer.remove(myFeedback); - layer.repaint(); - myFeedback = null; - } - } - - @Override - public boolean canExecute() { - return true; - } - - @Override - public void execute() throws Exception { - } -} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/MoveOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/MoveOperation.java deleted file mode 100644 index c69568d4d628..000000000000 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/MoveOperation.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.android.designer.designSurface; - -import com.intellij.android.designer.model.RadViewComponent; -import com.intellij.designer.designSurface.EditOperation; -import com.intellij.designer.designSurface.FeedbackLayer; -import com.intellij.designer.designSurface.OperationContext; -import com.intellij.designer.designSurface.feedbacks.AlphaComponent; -import com.intellij.designer.model.RadComponent; - -import javax.swing.*; -import java.awt.*; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Alexander Lobas - */ -public class MoveOperation implements EditOperation { - private final OperationContext myContext; - private List myComponents; - private List myFeedbackList; - - public MoveOperation(OperationContext context) { - myContext = context; - } - - @Override - public void setComponent(RadComponent component) { - } - - @Override - public void setComponents(List components) { - myComponents = components; - } - - @Override - public void showFeedback() { - FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); - int size = myComponents.size(); - - if (myFeedbackList == null) { - myFeedbackList = new ArrayList(); - - for (int i = 0; i < size; i++) { - JComponent feedback = new AlphaComponent(Color.GREEN, Color.LIGHT_GRAY); - myFeedbackList.add(feedback); - layer.add(feedback); - } - } - - for (int i = 0; i < size; i++) { - myFeedbackList.get(i).setBounds(myContext.getTransformedRectangle(myComponents.get(i).getBounds(layer))); - } - - layer.repaint(); - } - - @Override - public void eraseFeedback() { - if (myFeedbackList != null) { - FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); - - for (JComponent feedback : myFeedbackList) { - layer.remove(feedback); - } - - layer.repaint(); - myFeedbackList = null; - } - } - - @Override - public boolean canExecute() { - return true; - } - - @Override - public void execute() throws Exception { - for (RadComponent component : myComponents) { - Rectangle bounds = myContext.getTransformedRectangle(component.getBounds()); - RadViewComponent viewComponent = (RadViewComponent)component; - viewComponent.setBounds(bounds.x, bounds.y, bounds.width, bounds.height); - } - } -} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/ResizeOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/ResizeOperation.java deleted file mode 100644 index 6e95d6d8decd..000000000000 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/ResizeOperation.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.android.designer.designSurface; - -import com.intellij.designer.designSurface.EditOperation; -import com.intellij.designer.designSurface.FeedbackLayer; -import com.intellij.designer.designSurface.OperationContext; -import com.intellij.designer.designSurface.feedbacks.AlphaComponent; -import com.intellij.designer.model.RadComponent; -import com.intellij.designer.utils.Position; - -import javax.swing.*; -import java.awt.*; -import java.util.List; - -/** - * @author Alexander Lobas - */ -public class ResizeOperation implements EditOperation { - private final OperationContext myContext; - private RadComponent myComponent; - private JComponent myFeedback; - - public ResizeOperation(OperationContext context) { - myContext = context; - } - - @Override - public void setComponent(RadComponent component) { - myComponent = component; - } - - @Override - public void setComponents(List component) { - } - - @Override - public void showFeedback() { - FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); - - if (myFeedback == null) { - myFeedback = new AlphaComponent(Color.GREEN, Color.LIGHT_GRAY); - layer.add(myFeedback); - } - - myFeedback.setBounds(myContext.getTransformedRectangle(myComponent.getBounds(layer))); - layer.repaint(); - } - - @Override - public void eraseFeedback() { - if (myFeedback != null) { - FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); - layer.remove(myFeedback); - layer.repaint(); - myFeedback = null; - } - } - - @Override - public boolean canExecute() { - return myContext.getResizeDirection() != Position.SOUTH; - } - - @Override - public void execute() throws Exception { - } -} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/TreeOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/TreeOperation.java deleted file mode 100644 index ee6ae2a370bb..000000000000 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/TreeOperation.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.android.designer.designSurface; - -import com.intellij.android.designer.model.RadViewComponent; -import com.intellij.designer.componentTree.TreeEditOperation; -import com.intellij.designer.designSurface.OperationContext; -import com.intellij.designer.model.RadComponent; - -/** - * @author Alexander Lobas - */ -public class TreeOperation extends TreeEditOperation { - public TreeOperation(RadComponent host, OperationContext context) { - super(host, context); - } - - @Override - protected boolean canExecute(RadComponent insertBefore) { - return !"TableRow".equals(((RadViewComponent)myHost).getTitle()); - } - - @Override - protected void execute(RadComponent insertBefore) throws Exception { - System.out.println("Execute(" + myHost + ") insert " + myComponents + " before " + insertBefore); - } -} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/icons/Button.png b/plugins/android-designer/src/com/intellij/android/designer/icons/Button.png new file mode 100644 index 0000000000000000000000000000000000000000..d85e010a3787793a3b90bbbaa4e3bee85508d5da GIT binary patch literal 612 zcmV-q0-ODbP)j;`;*B8VaaSZV?}%!C*<}34K)gS1%zBK7gj2j{%ABplvrhdGPss2fN*VfT@mnLbuz^ghHW%-|yFcxxT*A>2%LoL9tjIcDr4KZ&a(* zN2}G!gu~&z!C+u477GIsCY?_2aKsaVPz&$iGyyy$GM~>6+wC@j_kiG!phlyCu&`FE zu{lh$*<|y$4}LohXX<;abrR%qxm(5t-}MUx4Vt*GSNzui0000KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0009-Nkl%WGU!0D$rD+{et^napG+p~)m>5^1EhShP{G#ZqyhQj5!~EAffC z6H%e7fJN*^5M7B-=tg{?g7_9HBGf8^5mTy#KwD#)$#WjLckVss+;fhL`~%-_^@&U0 zzDTLs!a0M@Gd#ao4NLWXg=pkZP$;(q)>zeFmhtLB*8guw_HHDeaO5&2OL_zV;P8Wp zVrA@bW9sNLg{W~nEY+q34or&8`O=`6o zhCUOMO^ShrfdVxEp|LKb-|G?Y2ryM_F2O3CQP#`iwPmZi zIckeL4>rkEk*~g6geZp^5LrO86Yr43J2;hLjl>zLwH*8#B;6Z}ac`qtvDKNQbE7QW zeG?ykvBEFEuMiLV?4J&J>G|8(?(ERn_RuN?r^sb|&1$veCB5~fPW#Gdalebr5?*+8 zipP$RV~xjJTd}#BAaqKzA*h5IT4gvRiMO{tFO2{QfXDF3ojlx+)((8P^aeeu-dRP0#md(?N>L256O{ zWQtN5!s%VP+xfEFZl6iI{RL|+fe-=*B-^V$sCaYLj!ivLD26A(f`6+Z_i+kmWUjLK zO499o6mM^Tp2hKH1PCE^XA(kSbA>W;vD>~n?+4!5VySr0=5kVC&~k9y<@&PGYFSAs ft+fc@0r39-#Zt?&-GO_;00000NkvXXu0mjf3G~f^ literal 0 HcmV?d00001 diff --git a/plugins/android-designer/src/com/intellij/android/designer/icons/LinearLayout.png b/plugins/android-designer/src/com/intellij/android/designer/icons/LinearLayout.png new file mode 100644 index 0000000000000000000000000000000000000000..b293fe7c593a08cd5165ee93c5791e4beeb12d64 GIT binary patch literal 403 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Kw; z@XqUVHb4>10*}aI1_o|n5N2eUHAey{$X?><>&kwcQBp)hOzc^)XL1ayt4fS%h`nj51#$ZSo?CCbGGmG%hl6oX7=R2{k`t`>!tU0Z_B;B zYu&FZyRSbhR%~6ibXH)C4bx0X4@adFGkA?VSX?KtFz7HmI42;sadu-*e%Iv?p0&&M zc%5{F*8Q6GpsUifSLEn}jxhZ*GLsH_c8GQhznz=F6VRkGVcw%aE031M$@4`I-YGuu z@=ti@Gqcj=LfTF9d4w|6BnmXU*Qj30n0`!iuizP`ud@=|gca@810o+Abk94LHck1~ r$4iRe-aPm&by-31-GA=?b#)9&HqO$GpM3iV(B}-Eu6{1-oD!Mj~*+1S)z0#7}|vCr~3l zvH?K44zF&YA`7U(e5j2vXf9X}avjJ5pqLv>-zFm?9+&~$K>Qsj$pxgZgEXKSa2tpd zf!=!or0;{|ij0i7fCk9J47dx#XG}~?%z*SNApWMOr^k)tg$`&qEdcSinVE5ZHZ~Uj z1Tw$?2%xs0<1lmsfb4l7{zgMXu8)R>5?}*>lFd*Jwm=uC18Gel2Fe+&MDoH7AP$5D zG}QmxU;}^x*MRskTA;24;?L&h=2}n#76I`Okk^2QhQicsHa6xXI#GcF7?`lwhGBjI Y0EVG<`Cy621^@s607*qoM6N<$f@lzf1ONa4 literal 0 HcmV?d00001 diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java index 41f1d7299b40..a1fed127fcb9 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java @@ -16,6 +16,7 @@ package com.intellij.android.designer.model; import com.intellij.designer.model.RadComponent; +import com.intellij.psi.xml.XmlTag; import javax.swing.*; import java.awt.*; @@ -28,13 +29,12 @@ import java.util.List; * @author Alexander Lobas */ public class RadViewComponent extends RadComponent { - private final String myTitle; private final List myChildren = new ArrayList(); private Component myNativeComponent; private final Rectangle myBounds = new Rectangle(); + private XmlTag myTag; - public RadViewComponent(RadViewComponent parent, String title) { - myTitle = title; + public RadViewComponent(RadViewComponent parent) { setParent(parent); if (parent != null) { parent.getChildren().add(this); @@ -42,20 +42,19 @@ public class RadViewComponent extends RadComponent { setLayout(new RadViewLayout(this)); } + public XmlTag getTag() { + return myTag; + } + + public void setTag(XmlTag tag) { + myTag = tag; + } + @Override public List getChildren() { return myChildren; } - public String getTitle() { - return myTitle; - } - - @Override - public String toString() { - return super.toString() + " - " + myTitle; - } - @Override public Rectangle getBounds() { return myBounds; diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java index fb3f861a6807..8d380af0ccc2 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java @@ -15,13 +15,7 @@ */ package com.intellij.android.designer.model; -import com.intellij.android.designer.designSurface.CreateOperation; -import com.intellij.android.designer.designSurface.MoveOperation; -import com.intellij.android.designer.designSurface.TreeOperation; -import com.intellij.designer.componentTree.TreeEditOperation; import com.intellij.designer.designSurface.ComponentDecorator; -import com.intellij.designer.designSurface.EditOperation; -import com.intellij.designer.designSurface.OperationContext; import com.intellij.designer.designSurface.selection.NonResizeSelectionDecorator; import com.intellij.designer.model.RadComponent; import com.intellij.designer.model.RadLayout; @@ -42,27 +36,4 @@ public class RadViewLayout extends RadLayout { public ComponentDecorator getChildSelectionDecorator(RadComponent component) { return new NonResizeSelectionDecorator(Color.RED, 1); } - - @Override - public EditOperation processChildOperation(OperationContext context) { - if (context.getArea().isTree()) { - if (!myContainer.getChildren().isEmpty() && TreeEditOperation.isTarget(myContainer, context)) { - /*if ("TableRow".equals(myContainer.getTitle())) { - return null; - }*/ - return new TreeOperation(myContainer, context); - } - return null; - } - if (context.isMove()) { - return new MoveOperation(context); - } - if (context.isCreate()) { - RadViewComponent component = (RadViewComponent)context.getComponents().get(0); - if ("android".equals(component.getTitle())) { - return new CreateOperation(myContainer, context); - } - } - return null; - } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/ViewsMetaManager.java b/plugins/android-designer/src/com/intellij/android/designer/model/ViewsMetaManager.java new file mode 100644 index 000000000000..2508db8deb4c --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/model/ViewsMetaManager.java @@ -0,0 +1,33 @@ +/* + * 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.android.designer.model; + +import com.intellij.designer.model.MetaManager; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.project.Project; + +/** + * @author Alexander Lobas + */ +public class ViewsMetaManager extends MetaManager { + public ViewsMetaManager(Project project) { + super(project, "views-meta-model.xml"); + } + + public static MetaManager getInstance(Project project) { + return ServiceManager.getService(project, ViewsMetaManager.class); + } +} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml b/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml new file mode 100644 index 000000000000..449fc164cf2c --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + ]]> + + + + + + + + + + + ]]> + + + + + + + + + + + ]]> + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/palette/ViewsPaletteProvider.java b/plugins/android-designer/src/com/intellij/android/designer/palette/ViewsPaletteProvider.java new file mode 100644 index 000000000000..583dfa915b29 --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/palette/ViewsPaletteProvider.java @@ -0,0 +1,45 @@ +/* + * 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.android.designer.palette; + +import com.intellij.android.designer.AndroidDesignerEditorProvider; +import com.intellij.android.designer.model.ViewsMetaManager; +import com.intellij.designer.model.MetaManager; +import com.intellij.designer.palette.AbstractPaletteProvider; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +/** + * @author Alexander Lobas + */ +public class ViewsPaletteProvider extends AbstractPaletteProvider { + private final Project myProject; + + public ViewsPaletteProvider(Project project) { + myProject = project; + } + + @Override + protected boolean accept(VirtualFile virtualFile) { + return AndroidDesignerEditorProvider.acceptLayout(myProject, virtualFile); + } + + @Override + protected MetaManager getMetaManager() { + return ViewsMetaManager.getInstance(myProject); + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java new file mode 100644 index 000000000000..22d11dae714c --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java @@ -0,0 +1,139 @@ +/* + * 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.palette.Group; +import com.intellij.designer.palette.Item; +import com.intellij.ide.palette.PaletteGroup; +import com.intellij.openapi.components.AbstractProjectComponent; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; +import com.intellij.util.containers.hash.HashMap; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; +import org.jetbrains.annotations.Nullable; + +import java.beans.PropertyChangeSupport; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author Alexander Lobas + */ +public abstract class MetaManager { + private static final String META = "meta"; + private static final String PALETTE = "palette"; + private static final String GROUP = "group"; + private static final String NAME = "name"; + private static final String ITEM = "item"; + private static final String TAG = "tag"; + + private static final Logger LOG = Logger.getInstance("#com.intellij.designer.model.MetaManager"); + + private final Map myTag2Model = new HashMap(); + private final Map myTarget2Model = new HashMap(); + private final List myPaletteGroups = new ArrayList(); + + private PropertyChangeSupport myPaletteChangeSupport; + + protected MetaManager(Project project, String name) { + try { + InputStream stream = getClass().getResourceAsStream(name); + Document document = new SAXBuilder().build(stream); + stream.close(); + + Element rootElement = document.getRootElement(); + ClassLoader classLoader = getClass().getClassLoader(); + + for (Object element : rootElement.getChildren(META)) { + loadModel(classLoader, (Element)element); + } + + for (Object element : rootElement.getChild(PALETTE).getChildren(GROUP)) { + loadGroup(name, (Element)element); + } + } + catch (Throwable e) { + LOG.error(e); + } + } + + @SuppressWarnings("unchecked") + private void loadModel(ClassLoader classLoader, Element element) throws Exception { + Class model = (Class)classLoader.loadClass(element.getAttributeValue("model")); + String target = element.getAttributeValue("class"); + String tag = element.getAttributeValue(TAG); + + MetaModel meta = new MetaModel(model, target, tag); + + String layout = element.getAttributeValue("layout"); + if (layout != null) { + meta.setLayout((Class)classLoader.loadClass(layout)); + } + + Element presentation = element.getChild("presentation"); + if (presentation != null) { + meta.setPresentation(presentation.getAttributeValue("title"), presentation.getAttributeValue("icon")); + } + + Element palette = element.getChild("palette"); + meta.setPaletteItem( + new Item(palette.getAttributeValue("title"), palette.getAttributeValue("icon"), palette.getAttributeValue("tooltip"))); + + Element creation = element.getChild("creation"); + if (creation != null) { + meta.setCreation(creation.getTextTrim()); + } + + myTag2Model.put(tag, meta); + + if (target != null) { + myTarget2Model.put(target, meta); + } + } + + private void loadGroup(String tab, Element element) throws Exception { + Group group = new Group(tab, element.getAttributeValue(NAME)); + + for (Object child : element.getChildren(ITEM)) { + String tag = ((Element)child).getAttributeValue(TAG); + group.addItem(getModelByTag(tag).getPaletteItem()); + } + + myPaletteGroups.add(group); + } + + @Nullable + public MetaModel getModelByTag(String tag) { + return myTag2Model.get(tag); + } + + @Nullable + public MetaModel getModelByTarget(String target) { + return myTarget2Model.get(target); + } + + public PaletteGroup[] getPaletteGroups() { + return myPaletteGroups.toArray(new PaletteGroup[myPaletteGroups.size()]); + } + + public void setPaletteChangeSupport(PropertyChangeSupport paletteChangeSupport) { + myPaletteChangeSupport = paletteChangeSupport; + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaModel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaModel.java new file mode 100644 index 000000000000..ad361e454da1 --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaModel.java @@ -0,0 +1,98 @@ +/* + * 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.palette.Item; +import com.intellij.openapi.util.IconLoader; + +import javax.swing.*; + +/** + * @author Alexander Lobas + */ +public class MetaModel { + private final Class myModel; + private Class myLayout; + private final String myTarget; + private final String myTag; + private Item myPaletteItem; + private String myTitle; + private String myIconPath; + private Icon myIcon; + private String myCreation; + + public MetaModel(Class model, String target, String tag) { + myModel = model; + myTarget = target; + myTag = tag; + } + + public Class getModel() { + return myModel; + } + + public Class getLayout() { + return myLayout; + } + + public void setLayout(Class layout) { + myLayout = layout; + } + + public String getTarget() { + return myTarget; + } + + public String getTag() { + return myTag; + } + + public String getCreation() { + return myCreation; + } + + public void setCreation(String creation) { + myCreation = creation; + } + + public String getTitle() { + return myTitle; + } + + public Icon getIcon() { + if (myIcon == null) { + if (myIconPath == null) { + return myPaletteItem.getIcon(); + } + myIcon = IconLoader.getIcon(myIconPath); + } + return myIcon; + } + + public void setPresentation(String title, String iconPath) { + myTitle = title; + myIconPath = iconPath; + myIcon = null; + } + + public Item getPaletteItem() { + return myPaletteItem; + } + + public void setPaletteItem(Item paletteItem) { + myPaletteItem = paletteItem; + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java index 90c146dbd80e..3b1a7c1794e2 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java @@ -33,10 +33,19 @@ import java.util.Map; * @author Alexander Lobas */ public abstract class RadComponent { + protected MetaModel myMetaModel; private RadComponent myParent; private RadLayout myLayout; private final Map myClientProperties = new HashMap(); + public MetaModel getMetaModel() { + return myMetaModel; + } + + public void setMetaModel(MetaModel metaModel) { + myMetaModel = metaModel; + } + ////////////////////////////////////////////////////////////////////////////////////////// // // Hierarchy diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/AbstractPaletteProvider.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/AbstractPaletteProvider.java new file mode 100644 index 000000000000..ea9d96101c4e --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/AbstractPaletteProvider.java @@ -0,0 +1,62 @@ +/* + * 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.palette; + +import com.intellij.designer.model.MetaManager; +import com.intellij.ide.palette.PaletteGroup; +import com.intellij.ide.palette.PaletteItemProvider; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; + +/** + * @author Alexander Lobas + */ +public abstract class AbstractPaletteProvider implements PaletteItemProvider { + private static final Logger LOG = Logger.getInstance("#com.intellij.designer.palette.AbstractPaletteProvider"); + + private final PropertyChangeSupport myPropertyChangeSupport = new PropertyChangeSupport(this); + + @Override + public PaletteGroup[] getActiveGroups(VirtualFile virtualFile) { + if (accept(virtualFile)) { + MetaManager manager = getMetaManager(); + if (manager != null) { + manager.setPaletteChangeSupport(myPropertyChangeSupport); + return manager.getPaletteGroups(); + } + LOG.error("VirtualFile: " + virtualFile + " accepted but MetaManager is null"); + } + return PaletteGroup.EMPTY_ARRAY; + } + + protected abstract boolean accept(VirtualFile virtualFile); + + protected abstract MetaManager getMetaManager(); + + @Override + public void addListener(PropertyChangeListener listener) { + myPropertyChangeSupport.addPropertyChangeListener(listener); + } + + @Override + public void removeListener(PropertyChangeListener listener) { + myPropertyChangeSupport.removePropertyChangeListener(listener); + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Group.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Group.java new file mode 100644 index 000000000000..ed8d7790ea9f --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Group.java @@ -0,0 +1,74 @@ +/* + * 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.palette; + +import com.intellij.ide.palette.PaletteGroup; +import com.intellij.ide.palette.PaletteItem; +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Alexander Lobas + */ +public final class Group implements PaletteGroup { + private final String myTabName; + private final String myName; + private List myItems = new ArrayList(); + + public Group(String tabName, String name) { + myTabName = tabName; + myName = name; + } + + public void addItem(@NotNull Item item) { + myItems.add(item); + } + + @Override + public PaletteItem[] getItems() { + return myItems.toArray(new PaletteItem[myItems.size()]); + } + + @Override + public String getName() { + return myName; + } + + @Override + public String getTabName() { + return myTabName; + } + + @Override + public ActionGroup getPopupActionGroup() { + return (ActionGroup)ActionManager.getInstance().getAction("Designer.PaletteGroupPopupMenu"); + } + + @Override + public Object getData(Project project, String dataId) { + return null; // TODO: Auto-generated method stub + } + + @Override + public void handleDrop(Project project, PaletteItem item, int index) { + // TODO: Auto-generated method stub + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Item.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Item.java new file mode 100644 index 000000000000..06da4e8306ae --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Item.java @@ -0,0 +1,76 @@ +/* + * 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.palette; + +import com.intellij.ide.dnd.DnDDragStartBean; +import com.intellij.ide.palette.PaletteItem; +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.IconLoader; +import com.intellij.ui.ColoredListCellRenderer; +import com.intellij.ui.SimpleTextAttributes; + +import javax.swing.*; + +/** + * @author Alexander Lobas + */ +public final class Item implements PaletteItem { + private String myTitle; + private String myIconPath; + private Icon myIcon; + private String myTooltip; + + public Item(String title, String iconPath, String tooltip) { + myTitle = title; + myIconPath = iconPath; + myTooltip = tooltip; + } + + public String getTitle() { + return myTitle; + } + + public Icon getIcon() { + if (myIcon == null) { + myIcon = IconLoader.getIcon(myIconPath); + } + return myIcon; + } + + @Override + public void customizeCellRenderer(ColoredListCellRenderer cellRenderer, boolean selected, boolean hasFocus) { + cellRenderer.setIcon(getIcon()); + cellRenderer.append(myTitle, SimpleTextAttributes.REGULAR_ATTRIBUTES); + cellRenderer.setToolTipText(myTooltip); + } + + @Override + public DnDDragStartBean startDragging() { + return null; + } + + @Override + public ActionGroup getPopupActionGroup() { + return (ActionGroup)ActionManager.getInstance().getAction("Designer.PaletteItemPopupMenu"); + } + + @Override + public Object getData(Project project, String dataId) { + return null; // TODO: Auto-generated method stub + } +} \ No newline at end of file From 81bfa16edb0cec1c946046e03d9544cc5f09188d Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 23 Feb 2012 21:04:09 +0400 Subject: [PATCH 13/13] Ignore settings and quickfix for Python package requirements inspection (PY-5671) --- .../src/com/intellij/codeInspection/inspection-black-list.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/inspection-black-list.txt b/platform/lang-impl/src/com/intellij/codeInspection/inspection-black-list.txt index 1ce49dbf958b..0310181f4ccb 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/inspection-black-list.txt +++ b/platform/lang-impl/src/com/intellij/codeInspection/inspection-black-list.txt @@ -34,6 +34,7 @@ com.jetbrains.php.lang.inspections.PhpUnusedParameterInspection com.jetbrains.python.inspections.PyCompatibilityInspection com.jetbrains.python.inspections.PyRedundantParenthesesInspection com.jetbrains.python.inspections.PyUnresolvedReferencesInspection +com.jetbrains.python.inspections.PyPackageRequirementsInspection com.jetbrains.python.inspections.PyUnusedLocalInspection com.jetbrains.quirksmode.QuirksModeInspectionTool com.jetbrains.rest.inspections.RestRoleInspection