Merge remote-tracking branch 'origin/master'

This commit is contained in:
Maxim.Mossienko
2012-03-06 23:10:54 +04:00
32 changed files with 608 additions and 373 deletions
@@ -130,7 +130,9 @@ public class JavaChainLookupElement extends LookupElementDecorator<LookupElement
return true;
}
if (expr instanceof PsiReferenceExpression || expr instanceof PsiMethodCallExpression) {
if (expr instanceof PsiJavaCodeReferenceElement ||
expr instanceof PsiMethodCallExpression ||
expr instanceof PsiArrayAccessExpression) {
return false;
}
@@ -20,16 +20,13 @@ import com.intellij.codeInsight.ExpectedTypeInfoImpl;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementWeigher;
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Pair;
import com.intellij.patterns.PsiJavaPatterns;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.NameUtil;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.filters.ElementFilter;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.search.searches.DeepestSuperMethodsSearch;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
@@ -85,15 +82,12 @@ public class JavaCompletionSorting {
@Nullable
private static LookupElementWeigher recursion(CompletionParameters parameters, final ExpectedTypeInfo[] expectedInfos) {
final PsiElement position = parameters.getPosition();
final PsiMethod positionMethod = PsiTreeUtil.getParentOfType(position, PsiMethod.class, false);
final ElementFilter filter = JavaCompletionUtil.recursionFilter(position);
final PsiMethodCallExpression expression = PsiTreeUtil.getParentOfType(position, PsiMethodCallExpression.class, true, PsiClass.class);
final PsiReferenceExpression reference = expression != null ? expression.getMethodExpression() : PsiTreeUtil.getParentOfType(position, PsiReferenceExpression.class);
if (reference == null) return null;
return new RecursionWeigher(filter, position, reference, expression, positionMethod, expectedInfos);
return new RecursionWeigher(position, reference, expression, expectedInfos);
}
@Nullable
@@ -315,96 +309,6 @@ public class JavaCompletionSorting {
}
private static class RecursionWeigher extends LookupElementWeigher {
private final ElementFilter myFilter;
private final PsiElement myPosition;
private final PsiReferenceExpression myReference;
private final PsiMethodCallExpression myExpression;
private final PsiMethod myPositionMethod;
private final ExpectedTypeInfo[] myExpectedInfos;
private final PsiExpression myQualifier;
private final boolean myDelegate;
public RecursionWeigher(ElementFilter filter,
PsiElement position,
@NotNull PsiReferenceExpression reference,
PsiMethodCallExpression expression,
PsiMethod positionMethod, ExpectedTypeInfo[] expectedInfos) {
super("recursion");
myFilter = filter;
myPosition = position;
myReference = reference;
myExpression = expression;
myPositionMethod = positionMethod;
myExpectedInfos = expectedInfos;
myQualifier = myReference.getQualifierExpression();
myDelegate = myQualifier != null && !(myQualifier instanceof PsiThisExpression);
}
private enum Result {
delegation,
normal,
passingObjectToItself,
recursive,
}
@NotNull
@Override
public Result weigh(@NotNull LookupElement element) {
final Object object = element.getObject();
if (!(object instanceof PsiMethod || object instanceof PsiVariable || object instanceof PsiExpression)) return Result.normal;
if (myFilter != null && !myFilter.isAcceptable(object, myPosition)) {
return Result.recursive;
}
if (isPassingObjectToItself(object)) {
return Result.passingObjectToItself;
}
if (myExpression != null && myPositionMethod != null) {
if (myExpectedInfos != null) {
final PsiType itemType = JavaCompletionUtil.getLookupElementType(element);
if (itemType != null) {
for (final ExpectedTypeInfo expectedInfo : myExpectedInfos) {
if (myPositionMethod.equals(expectedInfo.getCalledMethod()) && expectedInfo.getType().isAssignableFrom(itemType)) {
return myDelegate ? Result.delegation : Result.recursive;
}
}
}
}
return Result.normal;
}
if (object instanceof PsiMethod && myPositionMethod != null) {
final PsiMethod method = (PsiMethod)object;
if (PsiTreeUtil.isAncestor(myReference, myPosition, false) &&
Comparing.equal(method.getName(), myPositionMethod.getName())) {
if (!myDelegate && findDeepestSuper(method).equals(findDeepestSuper(myPositionMethod))) {
return Result.recursive;
}
return Result.delegation;
}
}
return Result.normal;
}
private boolean isPassingObjectToItself(Object object) {
if (object instanceof PsiThisExpression) {
return !myDelegate || myQualifier instanceof PsiSuperExpression;
}
return myQualifier instanceof PsiReferenceExpression &&
object.equals(((PsiReferenceExpression)myQualifier).advancedResolve(true).getElement());
}
@NotNull
private static PsiMethod findDeepestSuper(@NotNull final PsiMethod method) {
final PsiMethod first = DeepestSuperMethodsSearch.search(method).findFirst();
return first == null ? method : first;
}
}
private enum ExpectedTypeMatching {
ofDefaultType,
expected,
@@ -677,23 +677,6 @@ public class JavaCompletionUtil {
return containsMethodCalls(getQualifier(qualifier));
}
@Nullable
static ElementFilter recursionFilter(PsiElement element) {
if (PsiJavaPatterns.psiElement().afterLeaf(PsiKeyword.RETURN).inside(PsiReturnStatement.class).accepts(element)) {
return new ExcludeDeclaredFilter(ElementClassFilter.METHOD);
}
if (PsiJavaPatterns.psiElement().inside(
PsiJavaPatterns.or(
PsiJavaPatterns.psiElement(PsiAssignmentExpression.class),
PsiJavaPatterns.psiElement(PsiVariable.class))).
andNot(PsiJavaPatterns.psiElement().afterLeaf(".")).accepts(element)) {
return new AndFilter(new ExcludeSillyAssignment(),
new ExcludeDeclaredFilter(new ClassFilter(PsiVariable.class)));
}
return null;
}
public static void insertClassReference(@NotNull PsiClass psiClass, @NotNull PsiFile file, int offset) {
insertClassReference(psiClass, file, offset, offset);
}
@@ -0,0 +1,194 @@
/*
* 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.completion;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementWeigher;
import com.intellij.openapi.util.Comparing;
import com.intellij.patterns.PsiJavaPatterns;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.filters.AndFilter;
import com.intellij.psi.filters.ClassFilter;
import com.intellij.psi.filters.ElementFilter;
import com.intellij.psi.filters.element.ExcludeDeclaredFilter;
import com.intellij.psi.filters.element.ExcludeSillyAssignment;
import com.intellij.psi.scope.ElementClassFilter;
import com.intellij.psi.search.searches.DeepestSuperMethodsSearch;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author peter
*/
class RecursionWeigher extends LookupElementWeigher {
private final ElementFilter myFilter;
private final PsiElement myPosition;
private final PsiReferenceExpression myReference;
@Nullable private final PsiMethodCallExpression myExpression;
private final PsiMethod myPositionMethod;
private final ExpectedTypeInfo[] myExpectedInfos;
private final PsiExpression myCallQualifier;
private final PsiExpression myPositionQualifier;
private final boolean myDelegate;
public RecursionWeigher(PsiElement position,
@NotNull PsiReferenceExpression reference,
PsiMethodCallExpression expression,
ExpectedTypeInfo[] expectedInfos) {
super("recursion");
myFilter = recursionFilter(position);
myPosition = position;
myReference = reference;
myExpression = expression;
myPositionMethod = PsiTreeUtil.getParentOfType(position, PsiMethod.class, false);
myExpectedInfos = expectedInfos;
myCallQualifier = normalizeQualifier(myReference.getQualifierExpression());
myPositionQualifier = normalizeQualifier(position.getParent() instanceof PsiJavaCodeReferenceElement
? ((PsiJavaCodeReferenceElement)position.getParent()).getQualifier()
: null);
myDelegate = isDelegatingCall();
}
@Nullable
private static PsiExpression normalizeQualifier(PsiElement qualifier) {
return qualifier instanceof PsiThisExpression || !(qualifier instanceof PsiExpression) ? null : (PsiExpression)qualifier;
}
private boolean isDelegatingCall() {
if (myCallQualifier != null &&
myPositionQualifier != null &&
myCallQualifier != myPositionQualifier &&
CodeInsightUtil.areExpressionsEquivalent(myCallQualifier, myPositionQualifier)) {
return false;
}
if (myCallQualifier == null && myPositionQualifier == null) {
return false;
}
return true;
}
@Nullable
static ElementFilter recursionFilter(PsiElement element) {
if (PsiJavaPatterns.psiElement().afterLeaf(PsiKeyword.RETURN).inside(PsiReturnStatement.class).accepts(element)) {
return new ExcludeDeclaredFilter(ElementClassFilter.METHOD);
}
if (PsiJavaPatterns.psiElement().inside(
PsiJavaPatterns.or(
PsiJavaPatterns.psiElement(PsiAssignmentExpression.class),
PsiJavaPatterns.psiElement(PsiVariable.class))).
andNot(PsiJavaPatterns.psiElement().afterLeaf(".")).accepts(element)) {
return new AndFilter(new ExcludeSillyAssignment(),
new ExcludeDeclaredFilter(new ClassFilter(PsiVariable.class)));
}
return null;
}
private enum Result {
delegation,
normal,
passingObjectToItself,
recursive,
}
@NotNull
@Override
public Result weigh(@NotNull LookupElement element) {
final Object object = element.getObject();
if (!(object instanceof PsiMethod || object instanceof PsiVariable || object instanceof PsiExpression)) return Result.normal;
if (myFilter != null && !myFilter.isAcceptable(object, myPosition)) {
return Result.recursive;
}
if (isPassingObjectToItself(object)) {
return Result.passingObjectToItself;
}
if (myExpression != null) {
if (myExpectedInfos != null) {
final PsiType itemType = JavaCompletionUtil.getLookupElementType(element);
for (final ExpectedTypeInfo expectedInfo : myExpectedInfos) {
PsiMethod calledMethod = expectedInfo.getCalledMethod();
if (calledMethod != null && itemType != null) {
if (calledMethod.equals(myPositionMethod) && expectedInfo.getType().isAssignableFrom(itemType)) {
return myDelegate ? Result.delegation : Result.recursive;
}
if (isGetterSetterAssignment(object, calledMethod)) {
return myDelegate ? Result.delegation : Result.recursive;
}
}
}
}
return Result.normal;
}
if (object instanceof PsiMethod && myPositionMethod != null) {
final PsiMethod method = (PsiMethod)object;
if (PsiTreeUtil.isAncestor(myReference, myPosition, false) &&
Comparing.equal(method.getName(), myPositionMethod.getName())) {
if (!myDelegate && findDeepestSuper(method).equals(findDeepestSuper(myPositionMethod))) {
return Result.recursive;
}
return Result.delegation;
}
}
return Result.normal;
}
private static boolean isGetterSetterAssignment(Object lookupObject, PsiMethod calledMethod) {
if (!PropertyUtil.isSimplePropertySetter(calledMethod)) {
return false;
}
String prop = PropertyUtil.getPropertyName(calledMethod);
assert prop != null;
if (lookupObject instanceof PsiField &&
prop.equals(JavaCodeStyleManager.getInstance(calledMethod.getProject())
.variableNameToPropertyName(((PsiField)lookupObject).getName(), VariableKind.FIELD))) {
return true;
}
if (lookupObject instanceof PsiMethod &&
PropertyUtil.isSimplePropertyGetter((PsiMethod)lookupObject) &&
prop.equals(PropertyUtil.getPropertyName((PsiMethod)lookupObject))) {
return true;
}
return false;
}
private boolean isPassingObjectToItself(Object object) {
if (object instanceof PsiThisExpression) {
return !myDelegate || myCallQualifier instanceof PsiSuperExpression;
}
return myCallQualifier instanceof PsiReferenceExpression &&
object.equals(((PsiReferenceExpression)myCallQualifier).advancedResolve(true).getElement());
}
@NotNull
private static PsiMethod findDeepestSuper(@NotNull final PsiMethod method) {
final PsiMethod first = DeepestSuperMethodsSearch.search(method).findFirst();
return first == null ? method : first;
}
}
@@ -49,9 +49,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import static com.intellij.patterns.PsiJavaPatterns.psiElement;
import static com.intellij.patterns.PsiJavaPatterns.psiMethod;
@@ -99,7 +97,7 @@ public class ReferenceExpressionCompletionContributor {
}
if (!allowRecursion) {
final ElementFilter filter = JavaCompletionUtil.recursionFilter(element);
final ElementFilter filter = RecursionWeigher.recursionFilter(element);
if (filter != null) {
return new ElementExtractorFilter(filter);
}
@@ -126,8 +124,15 @@ public class ReferenceExpressionCompletionContributor {
final Set<LookupElement> base =
JavaSmartCompletionContributor.completeReference(element, reference, filter, false, true, parameters.getParameters(), null);
for (final LookupElement item : base) {
addSingleArrayElementAccess(element, item, parameters, result);
for (final LookupElement item : new LinkedHashSet<LookupElement>(base)) {
ExpressionLookupItem access = getSingleArrayElementAccess(element, item);
if (access != null) {
base.add(access);
PsiType type = access.getType();
if (type != null && parameters.getExpectedType().isAssignableFrom(type)) {
result.consume(access);
}
}
}
if (secondTime) {
@@ -218,24 +223,25 @@ public class ReferenceExpressionCompletionContributor {
return used;
}
private static void addSingleArrayElementAccess(PsiElement element, LookupElement item, JavaSmartCompletionParameters parameters,
Consumer<LookupElement> result) {
@Nullable
private static ExpressionLookupItem getSingleArrayElementAccess(PsiElement element, LookupElement item) {
if (item.getObject() instanceof PsiLocalVariable) {
final PsiLocalVariable variable = (PsiLocalVariable)item.getObject();
final PsiType type = variable.getType();
if (type instanceof PsiArrayType && parameters.getExpectedType().isAssignableFrom(((PsiArrayType)type).getComponentType())) {
final PsiExpression expression = variable.getInitializer();
if (expression instanceof PsiNewExpression) {
final PsiNewExpression newExpression = (PsiNewExpression)expression;
final PsiExpression[] dimensions = newExpression.getArrayDimensions();
if (dimensions.length == 1 && "1".equals(dimensions[0].getText()) && newExpression.getArrayInitializer() == null) {
final String text = variable.getName() + "[0]";
final PsiExpression conversion = createExpression(text, element);
result.consume(new ExpressionLookupItem(conversion).setIcon(variable.getIcon(Iconable.ICON_FLAG_VISIBILITY)));
}
final PsiExpression expression = variable.getInitializer();
if (type instanceof PsiArrayType && expression instanceof PsiNewExpression) {
final PsiNewExpression newExpression = (PsiNewExpression)expression;
final PsiExpression[] dimensions = newExpression.getArrayDimensions();
if (dimensions.length == 1 && "1".equals(dimensions[0].getText()) && newExpression.getArrayInitializer() == null) {
final String text = variable.getName() + "[0]";
final PsiExpression conversion = createExpression(text, element);
ExpressionLookupItem result = new ExpressionLookupItem(conversion);
result.setIcon(variable.getIcon(Iconable.ICON_FLAG_VISIBILITY));
return result;
}
}
}
return null;
}
private static PsiExpression createExpression(String text, PsiElement element) {
@@ -568,6 +568,10 @@ public class OverrideImplementUtil {
}
};
mergeAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.ALT_MASK)), myTree);
Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts("OverrideMethods");
mergeAction.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myTree);
group.add(mergeAction);
}
};
@@ -0,0 +1,11 @@
class Bar {
Goo getGoo();
}
class Goo {}
class Foo {
{
Bar[] ref = new Bar[1];
Goo g = ref[0].getGoo();<caret>
}
}
@@ -0,0 +1,11 @@
class Bar {
Goo getGoo();
}
class Goo {}
class Foo {
{
Bar[] ref = new Bar[1];
Goo g = <caret>
}
}
@@ -0,0 +1,13 @@
public class Aaaaaaa {
int color;
void setColor(int color) {}
int getColor() {}
int getZooColor() {}
{
setColor(<caret>);
}
}
@@ -0,0 +1,13 @@
public class Aaaaaaa {
int color;
void setColor(int color) {}
int getColor() {}
int getZooColor() {}
void foo(Aaaaaaa a) {
setColor(a.<caret>);
}
}
@@ -23,6 +23,7 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase {
public void testMethodAsQualifier() throws Throwable { doTest(); }
public void testFieldAsQualifier() throws Throwable { doTest(); }
public void testArrayRefAsQualifier() throws Throwable { doTest(); }
public void testMethodWithParams() throws Throwable { doTest(); }
public void testMergeMethods() throws Throwable { doTest(); }
@@ -296,6 +296,13 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assert 'FList.emptyList' in lookup.items[5].allLookupStrings
}
public void testDispreferGetterInSetterCall() {
checkPreferredItems 0, 'getZooColor', 'hashCode', 'color', 'getColor'
}
public void testPreferOtherGetterInSetterCall() {
checkPreferredItems 0, 'color', 'getColor', 'getZooColor', 'hashCode'
}
@Override
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + BASE_PATH;
@@ -77,7 +77,7 @@ public class PropertyUtil {
}
@SuppressWarnings("HardCodedStringLiteral")
public static boolean isSimplePropertySetter(PsiMethod method) {
public static boolean isSimplePropertySetter(@Nullable PsiMethod method) {
if (method == null) return false;
if (method.isConstructor()) return false;
@@ -155,7 +155,7 @@ public abstract class JBPopupFactory {
* @param showDisabledActions if true, disabled actions are shown as disabled; if false, disabled actions are not shown
* @return the popup instance.
*/
public abstract ListPopup createActionGroupPopup(String title,
public abstract ListPopup createActionGroupPopup(@Nullable String title,
ActionGroup actionGroup,
@NotNull DataContext dataContext,
ActionSelectionAid selectionAidMethod,
@@ -30,7 +30,7 @@ import java.util.*;
/**
* @author Konstantin Bulenkov
*/
class CommonActionsPanel extends JPanel {
public class CommonActionsPanel extends JPanel {
public static enum Buttons {
ADD, EDIT, REMOVE, UP, DOWN;
@@ -193,14 +193,7 @@ class CommonActionsPanel extends JPanel {
@Override
public ShortcutSet getShortcut() {
switch (myButton) {
case ADD: return CommonShortcuts.getNewForDialogs();
case EDIT: return CustomShortcutSet.fromString("ENTER");
case REMOVE: return CustomShortcutSet.fromString(SystemInfo.isMac ? "meta BACK_SPACE" : "alt DELETE");
case UP: return CustomShortcutSet.fromString("alt UP");
case DOWN: return CustomShortcutSet.fromString("alt DOWN");
}
return null;
return getCommonShortcut(myButton);
}
@Override
@@ -244,6 +237,17 @@ class CommonActionsPanel extends JPanel {
}
}
public static ShortcutSet getCommonShortcut(Buttons button) {
switch (button) {
case ADD: return CommonShortcuts.getNewForDialogs();
case EDIT: return CustomShortcutSet.fromString("ENTER");
case REMOVE: return CustomShortcutSet.fromString(SystemInfo.isMac ? "meta BACK_SPACE" : "alt DELETE");
case UP: return CustomShortcutSet.fromString("alt UP");
case DOWN: return CustomShortcutSet.fromString("alt DOWN");
}
return null;
}
interface ListenerFactory {
Listener createListener(CommonActionsPanel panel);
}
@@ -18,7 +18,6 @@ package com.intellij.ui.table;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.config.Storage;
import com.intellij.util.ui.ListTableModel;
import com.intellij.util.ui.Table;
import org.jetbrains.annotations.NonNls;
import javax.swing.*;
@@ -31,7 +30,7 @@ import java.util.Arrays;
/**
* Do NOT add code that assumes that table has same number of rows as model. It isn't true!
*/
public class BaseTableView extends Table {
public class BaseTableView extends JBTable {
private static final Logger LOG = Logger.getInstance("#com.intellij.ui.table.BaseTableView");
public BaseTableView(final ListTableModel model) {
@@ -23,6 +23,7 @@ import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.WaitForProgressToShow;
import com.intellij.util.xmlb.XmlSerializer;
import com.intellij.util.xmlb.XmlSerializerUtil;
@@ -180,7 +181,13 @@ public class HttpConfigurable implements PersistentStateComponent<HttpConfigurab
proxy.add("-Dhttp.proxyHost=" + httpConfigurable.PROXY_HOST);
proxy.add("-Dhttp.proxyPort=" + httpConfigurable.PROXY_PORT);
proxy.add("-Dhttps.proxyHost=" + httpConfigurable.PROXY_HOST);
proxy.add("-Dhttps.proxyPort=" + Integer.toString(httpConfigurable.PROXY_PORT));
proxy.add("-Dhttps.proxyPort=" + httpConfigurable.PROXY_PORT);
if (httpConfigurable.KEEP_PROXY_PASSWORD && StringUtil.isNotEmpty(httpConfigurable.PROXY_LOGIN)) {
proxy.add("-Dproxy.authentication.username=" + httpConfigurable.PROXY_LOGIN);
proxy.add("-Dproxy.authentication.password=" + httpConfigurable.getPlainProxyPassword());
}
}
return proxy;
}
@@ -62,6 +62,10 @@ public class UpdateSettings implements PersistentStateComponent<Element>, UserUp
}
public UpdateSettings() {
updateDefaultChannel();
}
private void updateDefaultChannel() {
if (ApplicationInfoImpl.getShadowInstance().isEAP()) {
UPDATE_CHANNEL_TYPE = ChannelStatus.EAP_CODE;
}
@@ -85,6 +89,7 @@ public class UpdateSettings implements PersistentStateComponent<Element>, UserUp
catch (InvalidDataException e) {
LOG.info(e);
}
updateDefaultChannel();
}
@NotNull
@@ -590,7 +590,7 @@ action.BuildAllArtifacts.text=Build All Artifacts
group.BuildArtifactsGroup.text=Build Artifact
group.RunMenu.text=R_un
group.RunnerActions.text=Run/Debug
action.editRunConfigurations.text=Edit Configu_rations
action.editRunConfigurations.text=Edit Configu_rations...
action.editRunConfigurations.description=Open edit Run/Debug configurations dialog
action.Stop.text=Stop
action.Stop.description=Stop process
@@ -632,7 +632,7 @@ action.ToggleFieldBreakpoint.text=Toggle _Field Watchpoint
action.ToggleFieldBreakpoint.description=Toggle field watchpoint for the field at caret
action.ToggleBreakpointEnabled.text=Toggle _Breakpoint Enabled
action.ToggleBreakpointEnabled.description=Enable/disable breakpoint at the current line
action.ViewBreakpoints.text=View Brea_kpoints
action.ViewBreakpoints.text=View Brea_kpoints...
action.ViewBreakpoints.description=View and manage all breakpoints and watchpoints
action.ExportThreads.text=Export T_hreads...
action.ExportThreads.description=Save all threads information to a text file or clipboard
@@ -987,7 +987,7 @@ public class FileUtil {
@RegExp
@NotNull
public static String convertAntToRegexp(@NotNull String antPattern, boolean ignoreStartingSlash) {
final StringBuilder builder = new StringBuilder(antPattern.length());
final StringBuilder builder = new StringBuilder();
int asteriskCount = 0;
boolean recursive = true;
final int start = ignoreStartingSlash && (StringUtil.startsWithChar(antPattern, '/') || StringUtil.startsWithChar(antPattern, '\\')) ? 1 : 0;
@@ -19,13 +19,11 @@ import com.android.ide.common.rendering.api.RenderSession;
import com.android.ide.common.rendering.api.Result;
import com.android.ide.common.rendering.api.ViewInfo;
import com.android.ide.common.resources.configuration.*;
import com.android.resources.NightMode;
import com.android.resources.UiMode;
import com.android.sdklib.IAndroidTarget;
import com.intellij.android.designer.actions.ProfileAction;
import com.intellij.android.designer.componentTree.AndroidTreeDecorator;
import com.intellij.android.designer.model.RadViewComponent;
import com.intellij.android.designer.model.ViewsMetaManager;
import com.intellij.android.designer.profile.ProfileManager;
import com.intellij.designer.DesignerToolWindowManager;
import com.intellij.designer.componentTree.TreeComponentDecorator;
import com.intellij.designer.designSurface.ComponentDecorator;
@@ -53,7 +51,10 @@ import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ThrowableRunnable;
import org.jetbrains.android.facet.AndroidFacet;
import org.jetbrains.android.sdk.AndroidPlatform;
import org.jetbrains.android.uipreview.*;
import org.jetbrains.android.uipreview.LayoutDeviceConfiguration;
import org.jetbrains.android.uipreview.LocaleData;
import org.jetbrains.android.uipreview.RenderUtil;
import org.jetbrains.android.uipreview.RenderingException;
import org.jetbrains.android.util.AndroidSdkNotConfiguredException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -77,11 +78,22 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
public AndroidDesignerEditorPanel(@NotNull Module module, @NotNull VirtualFile file) {
super(module, file);
showProgress("Load configuration");
myProfileAction = new ProfileAction(this, new Runnable() {
@Override
public void run() {
myActionPanel.update();
// TODO: Auto-generated method stub
if (myRootComponent == null) {
myPSIChangeListener.addRequest();
}
else {
myPSIChangeListener.addRequest(new Runnable() {
@Override
public void run() {
updateRenderer();
}
});
}
}
});
@@ -100,21 +112,6 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
});
// TODO: work over activate() / deactivate()
myPSIChangeListener.start();
// TODO: save last parse result (screen image, component info) to project output
// TODO: and use for next open editor (no wait first long init Android RenderLib)
try {
parseFile(new Runnable() {
@Override
public void run() {
showDesignerCard();
}
});
}
catch (Throwable e) {
showError("Parse error: ", e);
}
}
private void reparseFile() {
@@ -137,7 +134,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
}
}
private void parseFile(final Runnable runnable) throws Throwable {
private void parseFile(final Runnable runnable) {
final RadViewComponent[] rootComponents = new RadViewComponent[1];
final MetaManager metaManager = ViewsMetaManager.getInstance(getProject());
final String layoutXmlText = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@@ -172,16 +169,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
createRenderer(layoutXmlText, new ThrowableRunnable<Throwable>() {
@Override
public void run() throws Throwable {
Result result = mySession.getResult();
if (!result.isSuccess()) {
Throwable exception = result.getException();
if (exception != null) {
throw exception;
}
else {
throw new Exception("No session result");
}
}
checkRenderer();
RootView rootView = new RootView(mySession.getImage(), 30, 20);
updateRootComponent(rootComponents, mySession.getRootViews(), rootView);
@@ -199,6 +187,41 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
});
}
private void updateRenderer() {
final String layoutXmlText = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return myXmlFile.getText();
}
});
createRenderer(layoutXmlText, new ThrowableRunnable<Throwable>() {
@Override
public void run() throws Throwable {
checkRenderer();
RadViewComponent rootComponent = (RadViewComponent)myRootComponent;
RootView rootView = (RootView)rootComponent.getNativeComponent();
rootView.setImage(mySession.getImage());
updateRootComponent(rootComponent, mySession.getRootViews(), rootView);
myLayeredPane.repaint();
}
});
}
private void checkRenderer() throws Throwable {
Result result = mySession.getResult();
if (!result.isSuccess()) {
Throwable exception = result.getException();
if (exception != null) {
throw exception;
}
else {
throw new Exception("No session result");
}
}
}
private void removeNativeRoot() {
if (myRootComponent != null) {
myLayeredPane.remove(((RadViewComponent)myRootComponent).getNativeComponent().getParent());
@@ -208,8 +231,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
private void updateRootComponent(RadViewComponent[] rootComponents, List<ViewInfo> views, JComponent nativeComponent) {
RadViewComponent rootComponent = rootComponents[0];
int size = views.size();
if (size == 1) {
if (views.size() == 1) {
RadViewComponent newRootComponent = new RadViewComponent(null);
newRootComponent.setMetaModel(ViewsMetaManager.getInstance(getProject()).getModelByTag("<root>"));
newRootComponent.getChildren().add(rootComponent);
@@ -217,13 +239,21 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
updateComponent(rootComponent, views.get(0), nativeComponent, 0, 0);
rootComponents[0] = rootComponent = newRootComponent;
rootComponents[0] = newRootComponent;
newRootComponent.setNativeComponent(nativeComponent);
newRootComponent.setBounds(0, 0, nativeComponent.getWidth(), nativeComponent.getHeight());
}
else {
List<RadComponent> children = rootComponent.getChildren();
for (int i = 0; i < size; i++) {
updateComponent((RadViewComponent)children.get(i), views.get(i), nativeComponent, 0, 0);
}
updateRootComponent(rootComponent, views, nativeComponent);
}
}
private static void updateRootComponent(RadViewComponent rootComponent, List<ViewInfo> views, JComponent nativeComponent) {
int size = views.size();
List<RadComponent> children = rootComponent.getChildren();
for (int i = 0; i < size; i++) {
updateComponent((RadViewComponent)children.get(i), views.get(i), nativeComponent, 0, 0);
}
rootComponent.setNativeComponent(nativeComponent);
@@ -247,7 +277,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
}
private void createRenderer(final String layoutXmlText, final ThrowableRunnable<Throwable> runnable) throws Exception {
private void createRenderer(final String layoutXmlText, final ThrowableRunnable<Throwable> runnable) {
if (mySession == null) {
ApplicationManager.getApplication().invokeLater(
new Runnable() {
@@ -278,28 +308,32 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
throw new AndroidSdkNotConfiguredException();
}
IAndroidTarget target = platform.getTarget();
AndroidFacet facet = AndroidFacet.getInstance(myModule);
ProfileManager manager = myProfileAction.getProfileManager();
LayoutDeviceManager layoutDeviceManager = new LayoutDeviceManager();
layoutDeviceManager.loadDevices(platform.getSdkData());
LayoutDevice layoutDevice = layoutDeviceManager.getCombinedList().get(0);
LayoutDeviceConfiguration deviceConfiguration = layoutDevice.getConfigurations().get(0);
LayoutDeviceConfiguration deviceConfiguration = manager.getSelectedDeviceConfiguration();
if (deviceConfiguration == null) {
throw new RenderingException("Device is not specified");
}
FolderConfiguration config = new FolderConfiguration();
config.set(deviceConfiguration.getConfiguration());
config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL));
config.setNightModeQualifier(new NightModeQualifier(NightMode.NIGHT));
config.setLanguageQualifier(new LanguageQualifier());
config.setRegionQualifier(new RegionQualifier());
config.setUiModeQualifier(new UiModeQualifier(manager.getSelectedDockMode()));
config.setNightModeQualifier(new NightModeQualifier(manager.getSelectedNightMode()));
LocaleData locale = manager.getSelectedLocale();
if (locale == null) {
throw new RenderingException("Locale is not specified");
}
config.setLanguageQualifier(new LanguageQualifier(locale.getLanguage()));
config.setRegionQualifier(new RegionQualifier(locale.getRegion()));
float xdpi = deviceConfiguration.getDevice().getXDpi();
float ydpi = deviceConfiguration.getDevice().getYDpi();
ThemeData theme = new ThemeData("Theme", false);
mySession = RenderUtil.createRenderSession(getProject(), layoutXmlText, myFile, target, facet, config, xdpi, ydpi, theme);
mySession = RenderUtil
.createRenderSession(getProject(), layoutXmlText, myFile, manager.getSelectedTarget(), facet, config, xdpi, ydpi,
manager.getSelectedTheme());
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
@@ -314,6 +348,14 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
}
});
}
catch (RenderingException e) {
// TODO
e.printStackTrace();
}
catch (AndroidSdkNotConfiguredException e) {
// TODO
e.printStackTrace();
}
catch (final Throwable e) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
@@ -427,11 +469,19 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
}
private static class RootView extends JComponent {
private final BufferedImage myImage;
private int myX;
private int myY;
private BufferedImage myImage;
public RootView(BufferedImage image, int x, int y) {
myX = x;
myY = y;
setImage(image);
}
public void setImage(BufferedImage image) {
myImage = image;
setBounds(x, y, image.getWidth(), image.getHeight());
setBounds(myX, myY, image.getWidth(), image.getHeight());
}
@Override
@@ -18,6 +18,7 @@ package com.intellij.android.designer.designSurface;
import com.intellij.openapi.application.ModalityState;
import com.intellij.psi.*;
import com.intellij.util.Alarm;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -54,20 +55,28 @@ public class ExternalPSIChangeListener extends PsiTreeChangeAdapter {
}
}
private void update(PsiTreeChangeEvent event) {
private void updatePsi(PsiTreeChangeEvent event) {
if (myRunState && myFile == event.getFile()) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(new Runnable() {
@Override
public void run() {
if (myRunState) {
myRunnable.run();
}
}
}, myDelayMillis, ModalityState.stateForComponent(myComponent));
addRequest();
}
}
public void addRequest() {
addRequest(myRunnable);
}
public void addRequest(final Runnable runnable) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(new Runnable() {
@Override
public void run() {
if (myRunState) {
runnable.run();
}
}
}, myDelayMillis, ModalityState.stateForComponent(myComponent));
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// PSI
@@ -76,31 +85,31 @@ public class ExternalPSIChangeListener extends PsiTreeChangeAdapter {
@Override
public void childAdded(PsiTreeChangeEvent event) {
update(event);
updatePsi(event);
}
@Override
public void childRemoved(PsiTreeChangeEvent event) {
update(event);
updatePsi(event);
}
@Override
public void childReplaced(PsiTreeChangeEvent event) {
update(event);
updatePsi(event);
}
@Override
public void childMoved(PsiTreeChangeEvent event) {
update(event);
updatePsi(event);
}
@Override
public void childrenChanged(PsiTreeChangeEvent event) {
update(event);
updatePsi(event);
}
@Override
public void propertyChanged(PsiTreeChangeEvent event) {
update(event);
updatePsi(event);
}
}
@@ -132,6 +132,7 @@ public class ProfileManager {
@Override
protected boolean selectionChanged(LayoutDeviceConfiguration item) {
updateDeviceConfiguration(item);
myRefreshAction.run();
return true;
}
};
@@ -141,7 +142,6 @@ public class ProfileManager {
protected boolean selectionChanged(IAndroidTarget item) {
updateTarget(item);
updateThemes();
myRefreshAction.run();
return true;
}
};
@@ -63,6 +63,7 @@ import com.intellij.psi.PsiManager;
import com.intellij.util.*;
import com.intellij.util.cls.ClsFormatException;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.net.HttpConfigurable;
import gnu.trove.THashSet;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.groovy.compiler.rt.GroovycRunner;
@@ -150,6 +151,7 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler {
if (profileGroovyc) {
parameters.getVMParametersList().add("-XX:+HeapDumpOnOutOfMemoryError");
}
parameters.getVMParametersList().addAll(HttpConfigurable.getProxyCmdLineProperties());
//debug
//parameters.getVMParametersList().add("-Xdebug"); parameters.getVMParametersList().add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239");
@@ -41,6 +41,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrRe
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyConstantExpressionEvaluator;
import java.util.*;
@@ -365,12 +366,20 @@ public class StubGenerator implements ClassItemGenerator {
//type
PsiType declaredType =
typeElement == null ? PsiType.getJavaLangObject(variable.getManager(), variable.getResolveScope()) : typeElement.getType();
final String initializer = GroovyToJavaGenerator.getDefaultValueText(declaredType.getCanonicalText());
writeType(text, declaredType, variableDeclaration, classNameProvider);
text.append(' ').append(name).append(" = ").append(initializer);
text.append(' ').append(name).append(" = ").append(getVariableInitializer(variable, declaredType));
text.append(";\n");
}
}
private static String getVariableInitializer(GrVariable variable, PsiType declaredType) {
if (declaredType instanceof PsiPrimitiveType) {
Object eval = GroovyConstantExpressionEvaluator.evaluate(variable.getInitializerGroovy());
if (eval instanceof Number || eval instanceof Boolean) {
return eval.toString();
}
}
return GroovyToJavaGenerator.getDefaultValueText(declaredType.getCanonicalText());
}
}
@@ -32,6 +32,7 @@ import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingManager;
import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
import com.intellij.util.net.HttpConfigurable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.util.GroovyUtils;
@@ -100,6 +101,7 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner {
final String confPath = getConfPath(groovyHome);
params.getVMParametersList().add("-Dgroovy.starter.conf=" + confPath);
params.getVMParametersList().addAll(HttpConfigurable.getProxyCmdLineProperties());
params.setMainClass("org.codehaus.groovy.tools.GroovyStarter");
@@ -561,6 +561,25 @@ class Main {
assertEmpty make()
}
public void testCompileTimeConstants() {
myFixture.addFileToProject 'Gr.groovy', '''
interface Gr {
String HELLO = "Hello"
int MAGIC = 239
Boolean BOOL = true
boolean bool = true
}'''
myFixture.addFileToProject 'Main.java', '''
public class Main {
public static void main(String[] args) {
System.out.println(Gr.HELLO + ", " + Gr.BOOL + Gr.bool + Gr.MAGIC);
}
}
'''
make()
assertOutput 'Main', 'Hello, truetrue239'
}
public static class IdeaModeTest extends GroovyCompilerTest {
@Override protected boolean useJps() { false }
}
@@ -18,8 +18,8 @@ package org.jetbrains.idea.maven.compiler;
import com.intellij.compiler.CompilerConfigurationImpl;
import com.intellij.compiler.CompilerIOUtil;
import com.intellij.compiler.impl.CompilerUtil;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.compiler.*;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
@@ -37,11 +37,13 @@ import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.util.containers.CollectionFactory;
import com.intellij.util.text.CaseInsensitiveStringHashingStrategy;
import gnu.trove.THashMap;
import gnu.trove.THashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.dom.MavenPropertyResolver;
import org.jetbrains.idea.maven.model.MavenResource;
import org.jetbrains.idea.maven.project.MavenProject;
@@ -57,6 +59,8 @@ import java.util.regex.Pattern;
public class MavenResourceCompiler implements ClassPostProcessingCompiler {
private static final Key<List<String>> FILES_TO_DELETE_KEY = Key.create(MavenResourceCompiler.class.getSimpleName() + ".FILES_TO_DELETE");
private static final Set<String> DEFAULT_NON_FILTERED_EXTENSIONS = CollectionFactory.newSet("jpg", "jpeg", "gif", "bmp", "png");
private Map<String, Set<String>> myOutputItemsCache = new THashMap<String, Set<String>>();
public MavenResourceCompiler(Project project) {
@@ -76,7 +80,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
while (modulesSize-- > 0) {
String module = CompilerIOUtil.readString(in);
int pathsSize = in.readInt();
Set<String> paths = createPathsSet(pathsSize);
Set<String> paths = createPathsSet();
while (pathsSize-- > 0) {
paths.add(CompilerIOUtil.readString(in));
}
@@ -93,10 +97,10 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
}
}
private static Set<String> createPathsSet(int size) {
private static Set<String> createPathsSet() {
return SystemInfo.isFileSystemCaseSensitive
? new THashSet<String>(size)
: new THashSet<String>(size, CaseInsensitiveStringHashingStrategy.INSTANCE);
? new THashSet<String>()
: new THashSet<String>(CaseInsensitiveStringHashingStrategy.INSTANCE);
}
private void saveCache(final Project project) {
@@ -140,54 +144,60 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
final Project project = context.getProject();
final MavenProjectsManager mavenProjectManager = MavenProjectsManager.getInstance(project);
if (!mavenProjectManager.isMavenizedProject()) return ProcessingItem.EMPTY_ARRAY;
return new ReadAction<ProcessingItem[]>() {
protected void run(Result<ProcessingItem[]> resultObject) throws Throwable {
// make sure null reference will not be returned. By default return empty array
resultObject.setResult(ProcessingItem.EMPTY_ARRAY);
List<ProcessingItem> allItemsToProcess = new ArrayList<ProcessingItem>();
List<String> filesToDelete = new ArrayList<String>();
for (Module eachModule : context.getCompileScope().getAffectedModules()) {
MavenProject mavenProject = mavenProjectManager.findProject(eachModule);
if (mavenProject == null) continue;
List<ProcessingItem> allItemsToProcess = new ArrayList<ProcessingItem>();
List<String> filesToDelete = new ArrayList<String>();
Properties properties = loadPropertiesAndFilters(context, mavenProject);
AccessToken accessToken = ReadAction.start();
try {
for (Module eachModule : context.getCompileScope().getAffectedModules()) {
MavenProject mavenProject = mavenProjectManager.findProject(eachModule);
if (mavenProject == null) continue;
List<String> nonFilteredExtensions = collectNonFilteredExtensions(mavenProject);
String escapeString = MavenJDOMUtil.findChildValueByPath(mavenProject.getPluginConfiguration("org.apache.maven.plugins",
"maven-resources-plugin"),
"escapeString", "\\");
Properties properties = loadPropertiesAndFilters(context, mavenProject);
long propertiesHashCode = calculateHashCode(mavenProject, properties);
Set<String> nonFilteredExtensions = collectNonFilteredExtensions(mavenProject);
String escapeString = MavenJDOMUtil.findChildValueByPath(mavenProject.getPluginConfiguration("org.apache.maven.plugins",
"maven-resources-plugin"),
"escapeString", "\\");
List<ProcessingItem> moduleItemsToProcess = new ArrayList<ProcessingItem>();
collectProcessingItems(eachModule, mavenProject, context, properties, propertiesHashCode,
nonFilteredExtensions, escapeString, false, moduleItemsToProcess);
collectProcessingItems(eachModule, mavenProject, context, properties, propertiesHashCode,
nonFilteredExtensions, escapeString, true, moduleItemsToProcess);
collectItemsToDelete(eachModule, moduleItemsToProcess, filesToDelete);
allItemsToProcess.addAll(moduleItemsToProcess);
}
long propertiesHashCode = calculateHashCode(mavenProject, properties);
if (!filesToDelete.isEmpty()) {
allItemsToProcess.add(new FakeProcessingItem());
}
context.putUserData(FILES_TO_DELETE_KEY, filesToDelete);
resultObject.setResult(allItemsToProcess.toArray(new ProcessingItem[allItemsToProcess.size()]));
removeObsoleteModulesFromCache(project);
saveCache(project);
List<MyProcessingItem> moduleItemsToProcess = new ArrayList<MyProcessingItem>();
collectProcessingItems(eachModule, mavenProject, context, properties, propertiesHashCode,
nonFilteredExtensions, escapeString, false, moduleItemsToProcess);
collectProcessingItems(eachModule, mavenProject, context, properties, propertiesHashCode,
nonFilteredExtensions, escapeString, true, moduleItemsToProcess);
collectItemsToDelete(eachModule, moduleItemsToProcess, filesToDelete);
allItemsToProcess.addAll(moduleItemsToProcess);
}
}.execute().getResultObject();
if (!filesToDelete.isEmpty()) {
allItemsToProcess.add(new FakeProcessingItem());
}
context.putUserData(FILES_TO_DELETE_KEY, filesToDelete);
removeObsoleteModulesFromCache(project);
saveCache(project);
}
finally {
accessToken.finish();
}
return allItemsToProcess.toArray(new ProcessingItem[allItemsToProcess.size()]);
}
private static List<String> collectNonFilteredExtensions(MavenProject mavenProject) {
List<String> result = new ArrayList<String>(Arrays.asList("jpg", "jpeg", "gif", "bmp", "png"));
private static Set<String> collectNonFilteredExtensions(MavenProject mavenProject) {
Element config = mavenProject.getPluginConfiguration("org.apache.maven.plugins", "maven-resources-plugin");
if (config == null) return result;
if (config == null) return DEFAULT_NON_FILTERED_EXTENSIONS;
List<String> customNonFilteredExtensions = MavenJDOMUtil.findChildrenValuesByPath(config, "nonFilteredFileExtensions", "nonFilteredFileExtension");
if (customNonFilteredExtensions.isEmpty()) return DEFAULT_NON_FILTERED_EXTENSIONS;
Set<String> result = new HashSet<String>();
result.addAll(DEFAULT_NON_FILTERED_EXTENSIONS);
result.addAll(customNonFilteredExtensions);
for (String each : MavenJDOMUtil.findChildrenValuesByPath(config, "nonFilteredFileExtensions", "nonFilteredFileExtension")) {
result.add(each);
}
return result;
}
@@ -221,15 +231,15 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
return properties;
}
private void collectProcessingItems(Module module,
MavenProject mavenProject,
CompileContext context,
Properties properties,
long propertiesHashCode,
List<String> nonFilteredExtensions,
String escapeString,
boolean tests,
List<ProcessingItem> result) {
private static void collectProcessingItems(Module module,
MavenProject mavenProject,
CompileContext context,
Properties properties,
long propertiesHashCode,
Set<String> nonFilteredExtensions,
String escapeString,
boolean tests,
List<MyProcessingItem> result) {
String outputDir = CompilerPaths.getModuleOutputPath(module, tests);
if (outputDir == null) {
context.addMessage(CompilerMessageCategory.ERROR, "Maven: Module '" + module.getName() + "'output is not specified", null, -1, -1);
@@ -265,7 +275,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
}
}
public static List<Pattern> collectPatterns(List<String> values, String defaultValue) {
public static List<Pattern> collectPatterns(@Nullable List<String> values, @Nullable String defaultValue) {
List<Pattern> result = new ArrayList<Pattern>();
if (values == null || values.isEmpty()) {
if (defaultValue == null) return Collections.emptyList();
@@ -277,21 +287,21 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
return result;
}
private void collectProcessingItems(Module module,
VirtualFile sourceRoot,
VirtualFile currentDir,
String outputDir,
List<Pattern> includes,
List<Pattern> excludes,
boolean isSourceRootFiltered,
Properties properties,
long propertiesHashCode,
List<String> nonFilteredExtensions,
String escapeString,
List<ProcessingItem> result,
ProgressIndicator indicator) {
private static void collectProcessingItems(Module module,
VirtualFile sourceRoot,
VirtualFile currentDir,
String outputDir,
List<Pattern> includes,
List<Pattern> excludes,
boolean isSourceRootFiltered,
Properties properties,
long propertiesHashCode,
Set<String> nonFilteredExtensions,
String escapeString,
List<MyProcessingItem> result,
ProgressIndicator indicator) {
indicator.checkCanceled();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
for (VirtualFile eachSourceFile : currentDir.getChildren()) {
if (eachSourceFile.isDirectory()) {
collectProcessingItems(module,
@@ -315,6 +325,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
continue;
}
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
if (fileIndex.isIgnored(eachSourceFile)) continue;
if (!MavenUtil.isIncluded(relPath, includes, excludes)) continue;
@@ -337,29 +348,20 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
}
}
private void collectItemsToDelete(Module module, List<ProcessingItem> processingItems, List<String> result) {
Set<String> currentPaths = createPathsSet(processingItems.size());
for (ProcessingItem each : processingItems) {
if (!(each instanceof MyProcessingItem)) continue;
currentPaths.add(((MyProcessingItem)each).getOutputPath());
private void collectItemsToDelete(Module module, List<MyProcessingItem> processingItems, List<String> result) {
Set<String> currentPaths = createPathsSet();
for (MyProcessingItem each : processingItems) {
currentPaths.add(each.getOutputPath());
}
Set<String> cachedPaths = null;
Set<String> otherModulesCachedPaths = new THashSet<String>();
for (Map.Entry<String, Set<String>> eachEntry : myOutputItemsCache.entrySet()) {
if (eachEntry.getKey().equals(module.getName())) {
cachedPaths = eachEntry.getValue();
Set<String> cachedPaths = myOutputItemsCache.put(module.getName(), currentPaths);
if (cachedPaths != null) {
for (Set<String> set : myOutputItemsCache.values()) {
cachedPaths.removeAll(set);
}
else {
otherModulesCachedPaths.addAll(eachEntry.getValue());
}
}
myOutputItemsCache.put(module.getName(), currentPaths);
if (cachedPaths == null) return;
cachedPaths.removeAll(currentPaths);
cachedPaths.removeAll(otherModulesCachedPaths);
result.addAll(cachedPaths);
result.addAll(cachedPaths);
}
}
private void removeObsoleteModulesFromCache(final Project project) {
@@ -383,14 +385,13 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
deleteOutdatedFile(context.getUserData(FILES_TO_DELETE_KEY), filesToRefresh);
int count = 0;
for (final ProcessingItem each : items) {
if (!(each instanceof MyProcessingItem)) continue;
for (int i = 0; i < items.length; i++) {
if (!(items[i] instanceof MyProcessingItem)) continue;
context.getProgressIndicator().setFraction(((double)count) / items.length);
context.getProgressIndicator().setFraction(((double)i) / items.length);
context.getProgressIndicator().checkCanceled();
MyProcessingItem eachItem = (MyProcessingItem)each;
MyProcessingItem eachItem = (MyProcessingItem)items[i];
VirtualFile sourceVirtualFile = eachItem.getFile();
File sourceFile = new File(sourceVirtualFile.getPath());
File outputFile = new File(eachItem.getOutputPath());
@@ -410,7 +411,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
String charset = sourceVirtualFile.getCharset().name();
String text = new String(FileUtil.loadFileBytes(sourceFile), charset);
String escapedCharacters = sourceVirtualFile.getName().endsWith(".properties") ? "\\" : null;
PrintWriter printWriter = new PrintWriter(outputFile, charset);
try {
MavenPropertyResolver.doFilterText(eachItem.getModule(),
@@ -428,8 +429,8 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
FileUtil.copy(sourceFile, outputFile);
}
((MyValididtyState)each.getValidityState()).setOutputFileTimestamp(outputFile.lastModified());
result.add(each);
eachItem.getValidityState().setOutputFileTimestamp(outputFile.lastModified());
result.add(eachItem);
filesToRefresh.add(outputFile);
}
catch (IOException e) {
@@ -445,7 +446,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
return result.toArray(new ProcessingItem[result.size()]);
}
private void deleteOutdatedFile(List<String> filesToDelete, List<File> filesToRefresh) {
private static void deleteOutdatedFile(List<String> filesToDelete, List<File> filesToRefresh) {
for (String each : filesToDelete) {
File file = new File(each);
if (FileUtil.delete(file)) {
@@ -514,7 +515,8 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
return myEscapeString;
}
public ValidityState getValidityState() {
@NotNull
public MyValididtyState getValidityState() {
return myState;
}
}
@@ -538,7 +540,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler {
private static class MyValididtyState implements ValidityState {
private final long mySourceFileTimestamp;
private volatile long myOutputFileTimestamp;
private long myOutputFileTimestamp;
private final boolean myFiltered;
private final long myPropertiesHashCode;
private final String myEscapeString;
@@ -271,9 +271,11 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
protected final void showProgress(String message) {
myProgressMessage.setText(message);
myProgressIcon.resume();
myLayeredPane.add(myProgressPanel, LAYER_PROGRESS);
myLayeredPane.repaint();
if (myProgressPanel.getParent() == null) {
myProgressIcon.resume();
myLayeredPane.add(myProgressPanel, LAYER_PROGRESS);
myLayeredPane.repaint();
}
}
protected final void hideProgress() {
@@ -127,6 +127,7 @@ public abstract class AbstractTableView<T> extends JPanel implements TypeSafeDat
final ActionManager actionManager = ActionManager.getInstance();
final ToolbarPosition position = getToolbarPosition();
final ActionToolbar myActionToolbar = actionManager.createActionToolbar(ActionPlaces.PROJECT_VIEW_TOOLBAR, actionGroup, position == ToolbarPosition.TOP || position == ToolbarPosition.BOTTOM);
myActionToolbar.setTargetComponent(myTable);
final JComponent toolbarComponent = myActionToolbar.getComponent();
final MatteBorder matteBorder = BorderFactory.createMatteBorder(0, 0, position == ToolbarPosition.TOP ? 1 : 0, 0, Color.darkGray);
toolbarComponent.setBorder(BorderFactory.createCompoundBorder(matteBorder, toolbarComponent.getBorder()));
@@ -169,14 +170,6 @@ public abstract class AbstractTableView<T> extends JPanel implements TypeSafeDat
tuneTable(myTable);
}
protected final void fireTableChanged() {
final int row = myTable.getSelectedRow();
getTableModel().fireTableDataChanged();
if (row >= 0 && row < myTableModel.getRowCount()) {
myTable.getSelectionModel().setSelectionInterval(row, row);
}
}
protected void adjustColumnWidths() {
final ColumnInfo[] columnInfos = myTableModel.getColumnInfos();
for (int i = 0; i < columnInfos.length; i++) {
@@ -205,10 +198,6 @@ public abstract class AbstractTableView<T> extends JPanel implements TypeSafeDat
protected final void updateTooltip(final MouseEvent e) {
final int i = myTable.columnAtPoint(e.getPoint());
final int k = myTable.rowAtPoint(e.getPoint());
//myTable.getTableHeader().setToolTipText(((DefaultTableCellRenderer)myTable.getCellRenderer(i,k)).getToolTipText();
if (i >= 0) {
myTable.getTableHeader().setToolTipText(myTableModel.getColumnInfos()[i].getTooltipText());
}
@@ -25,11 +25,12 @@ import com.intellij.openapi.util.IconLoader;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.psi.xml.XmlElement;
import com.intellij.ui.CommonActionsPanel;
import com.intellij.util.ArrayUtil;
import com.intellij.util.EventDispatcher;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.highlighting.DomCollectionProblemDescriptor;
@@ -63,22 +64,6 @@ public class DomCollectionControl<T extends DomElement> extends DomUIControl imp
private List<T> myCollectionElements = new ArrayList<T>();
private ColumnInfo<T, ?>[] myColumnInfos;
private boolean myEditable = false;
private final AnAction myAddAction = new AddAction() {
protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) {
return DomCollectionControl.this;
}
};
private final AnAction myEditAction = new EditAction() {
protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) {
return DomCollectionControl.this;
}
};
private final AnAction myRemoveAction = new RemoveAction() {
protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) {
return DomCollectionControl.this;
}
};
public static final Icon ADD_ICON = IconLoader.getIcon("/general/add.png");
public static final Icon EDIT_ICON = IconLoader.getIcon("/actions/editSource.png");
public static final Icon REMOVE_ICON = IconLoader.getIcon("/general/remove.png");
@@ -169,7 +154,7 @@ public class DomCollectionControl<T extends DomElement> extends DomUIControl imp
else {
myCollectionPanel = boundComponent;
}
myCollectionPanel.setToolbarActions(myAddAction, myEditAction, myRemoveAction);
myCollectionPanel.setToolbarActions(new AddAction(), new EditAction(), new RemoveAction());
myCollectionPanel.installPopup(ActionPlaces.J2EE_ATTRIBUTES_VIEW_POPUP, createPopupActionGroup());
myCollectionPanel.initializeTable();
myCollectionPanel.addCustomDataProvider(this);
@@ -389,8 +374,13 @@ public class DomCollectionControl<T extends DomElement> extends DomUIControl imp
}
public static class AddAction extends AddDomElementAction {
public AddAction() {
setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD));
}
protected boolean isEnabled(final AnActionEvent e) {
return getDomCollectionControl(e) != null || "ProjectViewToolbar".equals(e.getPlace());
return getDomCollectionControl(e) != null;
}
protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) {
@@ -428,22 +418,20 @@ public class DomCollectionControl<T extends DomElement> extends DomUIControl imp
}
public static class EditAction extends AnAction {
protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) {
return DomCollectionControl.getDomCollectionControl(e);
}
public EditAction() {
super(ApplicationBundle.message("action.edit"), null, DomCollectionControl.EDIT_ICON);
setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.EDIT));
}
public void actionPerformed(AnActionEvent e) {
final DomCollectionControl control = getDomCollectionControl(e);
final DomCollectionControl control = DomCollectionControl.getDomCollectionControl(e);
control.doEdit();
control.reset();
}
public void update(AnActionEvent e) {
final DomCollectionControl control = getDomCollectionControl(e);
final DomCollectionControl control = DomCollectionControl.getDomCollectionControl(e);
final boolean visible = control != null && control.isEditable();
e.getPresentation().setVisible(visible);
e.getPresentation().setEnabled(visible && control.getComponent().getTable().getSelectedRowCount() == 1);
@@ -453,21 +441,18 @@ public class DomCollectionControl<T extends DomElement> extends DomUIControl imp
public static class RemoveAction extends AnAction {
public RemoveAction() {
super(ApplicationBundle.message("action.remove"), null, DomCollectionControl.REMOVE_ICON);
}
protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) {
return DomCollectionControl.getDomCollectionControl(e);
setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.REMOVE));
}
public void actionPerformed(AnActionEvent e) {
final DomCollectionControl control = getDomCollectionControl(e);
final DomCollectionControl control = DomCollectionControl.getDomCollectionControl(e);
control.doRemove();
control.reset();
}
public void update(AnActionEvent e) {
final boolean enabled;
final DomCollectionControl control = getDomCollectionControl(e);
final DomCollectionControl control = DomCollectionControl.getDomCollectionControl(e);
if (control != null) {
final JTable table = control.getComponent().getTable();
enabled = table != null && table.getSelectedRowCount() > 0;
@@ -22,8 +22,12 @@ import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.ui.CommonActionsPanel;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.xml.*;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.DomManager;
import com.intellij.util.xml.ElementPresentationManager;
import com.intellij.util.xml.TypeChooser;
import com.intellij.util.xml.reflect.DomCollectionChildDescription;
import com.intellij.util.xml.ui.DomCollectionControl;
import org.jetbrains.annotations.NotNull;
@@ -31,7 +35,6 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
@@ -41,8 +44,6 @@ import java.util.List;
*/
public abstract class AddDomElementAction extends AnAction {
private final static ShortcutSet shortcutSet = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0));
public AddDomElementAction() {
super(ApplicationBundle.message("action.add"), null, DomCollectionControl.ADD_ICON);
}
@@ -84,7 +85,7 @@ public abstract class AddDomElementAction extends AnAction {
final DataContext dataContext = e.getDataContext();
final ListPopup groupPopup =
JBPopupFactory.getInstance().createActionGroupPopup(null,//J2EEBundle.message("label.menu.title.add.activation.config.property"),
JBPopupFactory.getInstance().createActionGroupPopup(null,
group, dataContext, JBPopupFactory.ActionSelectionAid.NUMBERING, true);
showPopup(groupPopup, e);
@@ -137,8 +138,9 @@ public abstract class AddDomElementAction extends AnAction {
}
if (actions.size() > 1 && showAsPopup()) {
ActionGroup group = new ActionGroup() {
@NotNull
public AnAction[] getChildren(@Nullable AnActionEvent e) {
return actions.toArray(AnAction.EMPTY_ARRAY);
return actions.toArray(new AnAction[actions.size()]);
}
};
return new AnAction[]{new ShowPopupAction(group)};
@@ -150,7 +152,7 @@ public abstract class AddDomElementAction extends AnAction {
}
}
return actions.toArray(AnAction.EMPTY_ARRAY);
return actions.toArray(new AnAction[actions.size()]);
}
protected abstract AnAction createAddingAction(final AnActionEvent e,
@@ -178,12 +180,12 @@ public abstract class AddDomElementAction extends AnAction {
protected ShowPopupAction(ActionGroup group) {
super(ApplicationBundle.message("action.add"), null, DomCollectionControl.ADD_ICON);
myGroup = group;
setShortcutSet(shortcutSet);
setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD));
}
public void actionPerformed(AnActionEvent e) {
final ListPopup groupPopup =
JBPopupFactory.getInstance().createActionGroupPopup(null,//J2EEBundle.message("label.menu.title.add.activation.config.property"),
JBPopupFactory.getInstance().createActionGroupPopup(null,
myGroup, e.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, true);
showPopup(groupPopup, e);