Merge remote-tracking branch 'origin/master'

This commit is contained in:
Konstantin Bulenkov
2012-09-11 13:13:13 +04:00
27 changed files with 306 additions and 100 deletions
@@ -210,6 +210,7 @@ public class CreateClassDialog extends DialogWrapper {
final boolean isMultipleSourceRoots = ProjectRootManager.getInstance(myProject).getContentSourceRoots().length > 1;
myDestinationCB.setVisible(isMultipleSourceRoots);
label.setVisible(isMultipleSourceRoots);
label.setLabelFor(myDestinationCB);
return panel;
}
@@ -115,7 +115,7 @@ class CopyClassDialog extends DialogWrapper{
final boolean isMultipleSourceRoots = ProjectRootManager.getInstance(myProject).getContentSourceRoots().length > 1;
myDestinationCB.setVisible(!myDoClone && isMultipleSourceRoots);
label.setVisible(!myDoClone && isMultipleSourceRoots);
label.setLabelFor(myDestinationCB);
return FormBuilder.createFormBuilder()
.addComponent(myInformationLabel)
@@ -74,8 +74,9 @@ public abstract class JavaExtractSuperBaseDialog extends ExtractSuperBaseDialog<
if (sourceRoots.length <= 1) return super.createDestinationRootPanel();
final JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
panel.add(new JBLabel(RefactoringBundle.message("target.destination.folder")), BorderLayout.NORTH);
final JBLabel label = new JBLabel(RefactoringBundle.message("target.destination.folder"));
panel.add(label, BorderLayout.NORTH);
label.setLabelFor(myDestinationFolderComboBox);
myDestinationFolderComboBox.setData(myProject, myTargetDirectory, new Pass<String>() {
@Override
public void pass(String s) {
@@ -3,7 +3,7 @@
<grid id="27dc6" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="420" height="440"/>
<xy x="20" y="20" width="579" height="440"/>
</constraints>
<properties/>
<clientProperties>
@@ -75,6 +75,7 @@
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="c2c7f"/>
<text resource-bundle="messages/RefactoringBundle" key="target.destination.folder"/>
</properties>
</component>
@@ -2,7 +2,7 @@
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.refactoring.replaceConstructorWithBuilder.ReplaceConstructorWithBuilderDialog">
<grid id="27dc6" binding="myWholePanel" layout-manager="GridBagLayout">
<constraints>
<xy x="387" y="313" width="358" height="210"/>
<xy x="387" y="313" width="515" height="270"/>
</constraints>
<properties/>
<border type="none"/>
@@ -86,6 +86,7 @@
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<labelFor value="3e899"/>
<text resource-bundle="messages/RefactoringBundle" key="target.destination.folder"/>
</properties>
</component>
@@ -68,6 +68,7 @@
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="cf692"/>
<text resource-bundle="messages/RefactoringBundle" key="target.destination.folder"/>
</properties>
</component>
@@ -111,6 +111,15 @@ public class TypeConversionUtil {
return boxedType != null && areTypesConvertible(boxedType, toType);
}
if (!fromIsPrimitive) {
if (fromType instanceof PsiClassType && ((PsiClassType)fromType).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_7)) {
final PsiClassType classType = (PsiClassType)fromType;
final PsiClass psiClass = classType.resolve();
if (psiClass == null || psiClass instanceof PsiTypeParameter) return false;
final PsiClassType boxedType = ((PsiPrimitiveType)toType).getBoxedType(psiClass.getManager(), psiClass.getResolveScope());
if (boxedType != null) {
return isAssignable(fromType, boxedType);
}
}
return fromTypeRank == toTypeRank ||
fromTypeRank <= MAX_NUMERIC_RANK && toTypeRank <= MAX_NUMERIC_RANK && fromTypeRank < toTypeRank;
}
@@ -71,14 +71,20 @@ class C {
MethodHandle mh1 = MethodHandles.convertArguments(mh0, MethodType.methodType(Integer.class, String.class));
System.out.println((Integer) mh1.invokeExact("daddy"));
}
void supported() {
Object o = 42;
int i = (int) o;
String s = "";
int i1 = <error descr="Inconvertible types; cannot cast 'java.lang.String' to 'int'">(int) s</error>;
System.out.println(i);
m((int) o);
}
void unsupported() {
Object o = 42;
int i = <error descr="Inconvertible types; cannot cast 'java.lang.Object' to 'int'">(int) o</error>;
System.out.println(i);
m(<error descr="Inconvertible types; cannot cast 'java.lang.Object' to 'int'">(int) o</error>);
if (<error descr="Inconvertible types; cannot cast 'java.lang.Object' to 'int'">o instanceof int</error>) {
i = (Integer) o;
int i = (Integer) o;
System.out.println(i);
}
}
@@ -28,6 +28,9 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @see com.intellij.psi.PsiLanguageInjectionHost
*/
public interface MultiHostInjector {
ExtensionPointName<MultiHostInjector> MULTIHOST_INJECTOR_EP_NAME = ExtensionPointName.create("com.intellij.multiHostInjector");
@@ -60,4 +60,23 @@ public abstract class LiteralTextEscaper<T extends PsiLanguageInjectionHost> {
public abstract boolean isOneLine();
public static <T extends PsiLanguageInjectionHost> LiteralTextEscaper<T> createSimple(T element) {
return new LiteralTextEscaper<T>(element) {
@Override
public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
outChars.append(rangeInsideHost.substring(myHost.getText()));
return true;
}
@Override
public int getOffsetInHost(int offsetInDecoded, @NotNull TextRange rangeInsideHost) {
return rangeInsideHost.getStartOffset() + offsetInDecoded;
}
@Override
public boolean isOneLine() {
return true;
}
};
}
}
@@ -64,7 +64,6 @@ public abstract class PathReferenceManager {
* @param endingSlashNotAllowed true if paths like "/foo/" should not be resolved.
* @param relativePathsAllowed true if the folder of the file containing the PsiElement should be used as "root".
* Otherwise, web application root will be used.
* @param suitableFileTypes
*@param additionalProviders additional providers to process. @return created references or an empty array.
*/
@NotNull
@@ -162,7 +162,6 @@ com.siyeh.ig.methodmetrics.MethodCouplingInspection
com.siyeh.ig.methodmetrics.MultipleReturnPointsPerMethodInspection
com.siyeh.ig.methodmetrics.NestingDepthInspection
com.siyeh.ig.methodmetrics.NonCommentSourceStatementsInspection
com.siyeh.ig.methodmetrics.ParametersPerConstructorInspection
com.siyeh.ig.methodmetrics.ParametersPerMethodInspection
com.siyeh.ig.methodmetrics.ThreeNegationsPerMethodInspection
com.siyeh.ig.methodmetrics.ThrownExceptionsPerMethodInspection
@@ -72,7 +72,7 @@ public class ProgramRunnerUtil {
return;
}
if (!RunManagerImpl.canRunConfiguration(configuration, executor) || (showSettings && RunManagerImpl.isEditBeforeRun(configuration))) {
if (!RunManagerImpl.canRunConfiguration(configuration, executor) || (showSettings && configuration.isEditBeforeRun())) {
if (!RunDialog.editConfiguration(project, configuration, "Edit configuration", executor)) {
return;
}
@@ -761,10 +761,6 @@ public class RunManagerImpl extends RunManagerEx implements JDOMExternalizable,
setActiveConfiguration(tempConfiguration);
}
public static boolean isEditBeforeRun(@NotNull final RunnerAndConfigurationSettings configuration) {
return configuration.isEditBeforeRun();
}
Collection<RunnerAndConfigurationSettings> getStableConfigurations() {
final Map<Integer, RunnerAndConfigurationSettings> result =
new LinkedHashMap<Integer, RunnerAndConfigurationSettings>(myConfigurations);
@@ -15,10 +15,7 @@
*/
package com.intellij.execution.ui;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.Executor;
import com.intellij.execution.ExecutorRegistry;
import com.intellij.execution.TerminateRemoteProcessDialog;
import com.intellij.execution.*;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessHandler;
@@ -35,6 +32,7 @@ import com.intellij.openapi.application.impl.LaterInvocator;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
@@ -566,7 +564,7 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
public void contentRemoveQuery(final ContentManagerEvent event) {
if (event.getContent() == myContent) {
final boolean canClose = closeQuery();
final boolean canClose = closeQuery(false);
if (!canClose) {
event.consume();
}
@@ -588,7 +586,7 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
if (myContent == null) return true;
final boolean canClose = closeQuery();
final boolean canClose = closeQuery(true);
if (canClose) {
myContent.getManager().removeContent(myContent, true);
myContent = null;
@@ -599,7 +597,7 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
public void projectClosing(final Project project) {
}
private boolean closeQuery() {
private boolean closeQuery(boolean modal) {
final RunContentDescriptor descriptor = getRunContentDescriptorByContent(myContent);
if (descriptor == null) {
@@ -628,14 +626,38 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
else {
processHandler.detachProcess();
}
waitForProcess(descriptor);
waitForProcess(descriptor, modal);
return true;
}
}
private void waitForProcess(final RunContentDescriptor descriptor) {
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
public void run() {
private void waitForProcess(final RunContentDescriptor descriptor, final boolean modal) {
final ProcessHandler processHandler = descriptor.getProcessHandler();
final boolean killable = !modal && (processHandler instanceof KillableProcess) && ((KillableProcess)processHandler).canKillProcess();
String title = ExecutionBundle.message("terminating.process.progress.title", descriptor.getDisplayName());
ProgressManager.getInstance().run(new Task.Backgroundable(myProject, title, true) {
{
if (killable) {
String cancelText= ExecutionBundle.message("terminating.process.progress.kill");
setCancelText(cancelText);
setCancelTooltipText(cancelText);
}
}
@Override
public boolean isConditionalModal() {
return modal;
}
@Override
public boolean shouldStartInBackground() {
return !modal;
}
@Override
public void run(@NotNull final ProgressIndicator progressIndicator) {
final Semaphore semaphore = new Semaphore();
semaphore.down();
@@ -653,31 +675,34 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
}
});
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null) {
progressIndicator.setText(ExecutionBundle.message("waiting.for.vm.detach.progress.text"));
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public void run() {
while (true) {
if (progressIndicator.isCanceled() || !progressIndicator.isRunning()) {
semaphore.up();
break;
}
try {
synchronized (this) {
wait(2000L);
}
}
catch (InterruptedException ignore) {
progressIndicator.setText(ExecutionBundle.message("waiting.for.vm.detach.progress.text"));
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public void run() {
while (true) {
if (progressIndicator.isCanceled() || !progressIndicator.isRunning()) {
semaphore.up();
break;
}
try {
synchronized (this) {
wait(2000L);
}
}
catch (InterruptedException ignore) {
}
}
});
}
}
});
semaphore.waitFor();
}
}, ExecutionBundle.message("terminating.process.progress.title", descriptor.getDisplayName()), true, myProject);
@Override
public void onCancel() {
if (killable && !processHandler.isProcessTerminated()) {
((KillableProcess)processHandler).killProcess();
}
}
});
}
}
@@ -359,7 +359,7 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc
@Override
public PsiFileSystemItem resolve() {
ResolveResult[] resolveResults = multiResolve(false);
return resolveResults.length == 1 ? (PsiFileSystemItem)resolveResults[0].getElement() : null;
return resolveResults.length == 1 ? (PsiFileSystemItem)resolveResults[0].getElement() : null;
}
@Nullable
@@ -242,7 +242,10 @@ public class MultiHostRegistrarImpl implements MultiHostRegistrar, ModificationT
finally {
viewProvider.setPatchingLeaves(false);
}
assert parsedNode.getText().equals(documentText) : exceptionContext("After patch: doc:\n'" + documentText + "'\n---PSI:\n'" + parsedNode.getText() + "'\n---chars:\n'"+outChars+"'");
if (!parsedNode.getText().equals(documentText)) {
throw new AssertionError(exceptionContext(
"After patch: doc:\n'" + documentText + "'\n---PSI:\n'" + parsedNode.getText() + "'\n---chars:\n'" + outChars + "'"));
}
virtualFile.setContent(null, documentWindow.getText(), false);
@@ -220,10 +220,6 @@ public abstract class InplaceRefactoring {
}
protected boolean acceptReference(PsiReference reference) {
final PsiElement element = reference.getElement();
if (element instanceof PsiNamedElement) {
return Comparing.strEqual(((PsiNamedElement)element).getName(), myElementToRename.getName());
}
return true;
}
@@ -80,6 +80,15 @@ public class MemberInplaceRenamer extends VariableInplaceRenamer {
return new MemberInplaceRenamer(variable, getSubstituted(), editor, initialName, myOldName);
}
@Override
protected boolean acceptReference(PsiReference reference) {
final PsiElement element = reference.getElement();
if (element instanceof PsiNamedElement) {
return Comparing.strEqual(((PsiNamedElement)element).getName(), myElementToRename.getName());
}
return super.acceptReference(reference);
}
@Override
protected PsiElement checkLocalScope() {
PsiFile currentFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
@@ -156,6 +156,7 @@ run.configuration.select.alternate.jre.label=Select Alternative JRE
run.configuration.select.jre.dir.label=Select directory with JRE to run with
run.configuration.arguments.help.panel.copy.action.name=Copy
terminating.process.progress.title=Terminating ''{0}''
terminating.process.progress.kill=Kill process
waiting.for.vm.detach.progress.text=Waiting for process detach
restart.error.message.title=Restart Error
rerun.configuration.action.name=Rerun ''{0}''
@@ -1283,6 +1283,7 @@ non.comment.source.statements.problem.descriptor=<code>#ref</code> is too long (
parameters.per.method.problem.descriptor=<code>#ref()</code> has too many parameters (num parameters = {0}) #loc
parameters.per.constructor.problem.descriptor=<code>#ref()</code> has too many parameters (num parameters = {0}) #loc
parameter.limit.option=Parameter limit:
constructor.visibility.option=Ignore constructors with visibility
three.negations.per.method.ignore.option=Ignore negations in 'equals()' methods
three.negations.per.method.ignore.assert.option=Ignore negations in 'assert' statements
three.negations.per.method.problem.descriptor=<code>#ref</code> contains {0} negations #loc
@@ -1989,3 +1990,7 @@ public.constructor.problem.descriptor=Public constructor <code>#ref()</code>
public.constructor.quickfix=Replace constructor with factory method
junit3.style.test.method.in.junit4.class.display.name=Old style JUnit test method in JUnit 4 class
junit3.style.test.method.in.junit4.class.problem.descriptor=Old style JUnit test method <code>#ref</code> in JUnit 4 class
none=none
private=private
package.local.private=package local & private
protected.package.local.private=protected, package local & private
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 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,44 +16,133 @@
package com.siyeh.ig.methodmetrics;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiParameterList;
import com.intellij.ui.ListCellRendererWrapper;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspectionVisitor;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ParametersPerConstructorInspection extends MethodMetricInspection {
private enum Scope {
NONE {
@Override
String getText() {
return InspectionGadgetsBundle.message("none");
}
},
PRIVATE {
@Override
String getText() {
return InspectionGadgetsBundle.message("private");
}
},
PACKAGE_LOCAL {
@Override
String getText() {
return InspectionGadgetsBundle.message("package.local.private");
}
},
PROTECTED {
@Override
String getText() {
return InspectionGadgetsBundle.message("protected.package.local.private");
}
};
abstract String getText();
}
@SuppressWarnings("PublicField") public Scope ignoreScope = Scope.NONE;
@Override
@NotNull
public String getID() {
return "ConstructorWithTooManyParameters";
}
@Override
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"parameters.per.constructor.display.name");
return InspectionGadgetsBundle.message("parameters.per.constructor.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos) {
final Integer parameterCount = (Integer)infos[0];
return InspectionGadgetsBundle.message(
"parameters.per.constructor.problem.descriptor", parameterCount);
return InspectionGadgetsBundle.message("parameters.per.constructor.problem.descriptor", parameterCount);
}
@Override
protected int getDefaultLimit() {
return 5;
}
@Override
protected String getConfigurationLabel() {
return InspectionGadgetsBundle.message("parameter.limit.option");
}
public BaseInspectionVisitor buildVisitor() {
return new ParametersPerMethodVisitor();
@Override
public JComponent createOptionsPanel() {
final JPanel panel = new JPanel();
final JLabel textFieldLabel = new JLabel(getConfigurationLabel());
final JFormattedTextField valueField = prepareNumberEditor("m_limit");
final JLabel comboBoxLabel = new JLabel(InspectionGadgetsBundle.message("constructor.visibility.option"));
final JComboBox comboBox = new JComboBox();
comboBox.addItem(Scope.NONE);
comboBox.addItem(Scope.PRIVATE);
comboBox.addItem(Scope.PACKAGE_LOCAL);
comboBox.addItem(Scope.PROTECTED);
comboBox.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof Scope) setText(((Scope)value).getText());
}
});
comboBox.setSelectedItem(ignoreScope);
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ignoreScope = (Scope)comboBox.getSelectedItem();
}
});
comboBox.setPrototypeDisplayValue(Scope.PROTECTED);
final GroupLayout layout = new GroupLayout(panel);
layout.setAutoCreateGaps(true);
panel.setLayout(layout);
final GroupLayout.ParallelGroup horizontal = layout.createParallelGroup();
horizontal.addGroup(layout.createSequentialGroup()
.addComponent(textFieldLabel)
.addComponent(valueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
horizontal.addGroup(layout.createSequentialGroup()
.addComponent(comboBoxLabel).addComponent(comboBox, 100, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
layout.setHorizontalGroup(horizontal);
final GroupLayout.SequentialGroup vertical = layout.createSequentialGroup();
vertical.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(textFieldLabel)
.addComponent(valueField));
vertical.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(comboBoxLabel)
.addComponent(comboBox));
layout.setVerticalGroup(vertical);
return panel;
}
private class ParametersPerMethodVisitor extends BaseInspectionVisitor {
@Override
public BaseInspectionVisitor buildVisitor() {
return new ParametersPerConstructorVisitor();
}
private class ParametersPerConstructorVisitor extends BaseInspectionVisitor {
@Override
public void visitMethod(@NotNull PsiMethod method) {
@@ -64,6 +153,13 @@ public class ParametersPerConstructorInspection extends MethodMetricInspection {
if (!method.isConstructor()) {
return;
}
if (ignoreScope != Scope.NONE) {
switch (ignoreScope.ordinal()) {
case 3: if (method.hasModifierProperty(PsiModifier.PROTECTED)) return;
case 2: if (method.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) return;
case 1: if (method.hasModifierProperty(PsiModifier.PRIVATE)) return;
}
}
final PsiParameterList parameterList = method.getParameterList();
final int parametersCount = parameterList.getParametersCount();
if (parametersCount <= getLimit()) {
@@ -6,6 +6,9 @@ with too many parameters can be a good sign that refactoring is necessary.
<p>
Use the field provided below to specify the maximum acceptable number of parameters a constructor might have.
<p>
Use the combobox below to specify if the inspection should ignore private, package local & private or protected, package local and
private constructors
<p>
<small>Powered by InspectionGadgets</small>
</body>
</html>
@@ -34,6 +34,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.expectedTypes.SupertypeConstraint;
import org.jetbrains.plugins.groovy.lang.psi.expectedTypes.TypeConstraint;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
@@ -47,49 +48,68 @@ import java.util.ArrayList;
*/
public class GrSetStrongTypeIntention extends Intention {
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
if (element instanceof GrVariableDeclaration) {
GrVariable[] variables = ((GrVariableDeclaration)element).getVariables();
ArrayList<TypeConstraint> types = new ArrayList<TypeConstraint>();
for (GrVariable variable : variables) {
if (variable.getInitializerGroovy() != null) {
PsiType type = variable.getInitializerGroovy().getType();
PsiElement parent = element.getParent();
if (!(parent instanceof GrVariable)) return;
PsiElement elementToBuildTemplate;
GrVariable[] variables;
if (parent.getParent() instanceof GrVariableDeclaration) {
variables = ((GrVariableDeclaration)parent.getParent()).getVariables();
elementToBuildTemplate = parent.getParent();
}
else {
variables = new GrVariable[]{((GrVariable)parent)};
elementToBuildTemplate = parent;
}
ArrayList<TypeConstraint> types = new ArrayList<TypeConstraint>();
for (GrVariable variable : variables) {
GrExpression initializer = variable.getInitializerGroovy();
if (initializer != null) {
PsiType type = initializer.getType();
if (type != null) {
types.add(SupertypeConstraint.create(type));
}
}
}
TemplateBuilderImpl builder = new TemplateBuilderImpl(element);
TemplateBuilderImpl builder = new TemplateBuilderImpl(elementToBuildTemplate);
PsiManager manager = element.getManager();
PsiManager manager = element.getManager();
GrModifierList modifierList = ((GrVariableDeclaration)element).getModifierList();
GrModifierList modifierList = ((GrVariable)parent).getModifierList();
PsiElement replaceElement;
if (modifierList.hasModifierProperty(GrModifier.DEF) && modifierList.getModifiers().length == 1) {
replaceElement = PsiUtil.findModifierInList(modifierList, GrModifier.DEF);
PsiElement replaceElement;
if (modifierList != null && modifierList.hasModifierProperty(GrModifier.DEF) && modifierList.getModifiers().length == 1) {
replaceElement = PsiUtil.findModifierInList(modifierList, GrModifier.DEF);
}
else {
if (elementToBuildTemplate instanceof GrVariableDeclaration) {
((GrVariableDeclaration)elementToBuildTemplate).setType(TypesUtil.createType("Abc", element));
}
else {
((GrVariableDeclaration)element).setType(TypesUtil.createType("Abc", element));
replaceElement = ((GrVariableDeclaration)element).getTypeElementGroovy();
((GrVariable)parent).setType(TypesUtil.createType("Abc", element));
}
assert replaceElement != null;
TypeConstraint[] constraints = types.toArray(new TypeConstraint[types.size()]);
ChooseTypeExpression chooseTypeExpression = new ChooseTypeExpression(constraints, manager, replaceElement.getResolveScope());
builder.replaceElement(replaceElement, chooseTypeExpression);
final PsiElement afterPostprocess = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(element);
final Template template = builder.buildTemplate();
TextRange range = afterPostprocess.getTextRange();
Document document = editor.getDocument();
document.deleteString(range.getStartOffset(), range.getEndOffset());
TemplateManager templateManager = TemplateManager.getInstance(project);
templateManager.startTemplate(editor, template);
replaceElement = ((GrVariable)parent).getTypeElementGroovy();
}
assert replaceElement != null;
TypeConstraint[] constraints = types.toArray(new TypeConstraint[types.size()]);
ChooseTypeExpression chooseTypeExpression = new ChooseTypeExpression(constraints, manager, replaceElement.getResolveScope());
builder.replaceElement(replaceElement, chooseTypeExpression);
final PsiElement afterPostprocess = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(elementToBuildTemplate);
final Template template = builder.buildTemplate();
TextRange range = afterPostprocess.getTextRange();
Document document = editor.getDocument();
document.deleteString(range.getStartOffset(), range.getEndOffset());
TemplateManager templateManager = TemplateManager.getInstance(project);
templateManager.startTemplate(editor, template);
}
@NotNull
@@ -98,10 +118,19 @@ public class GrSetStrongTypeIntention extends Intention {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (element instanceof GrVariableDeclaration && ((GrVariableDeclaration)element).getTypeElementGroovy() == null) {
GrVariable[] variables = ((GrVariableDeclaration)element).getVariables();
for (GrVariable variable : variables) {
if (variable.getInitializerGroovy() != null) return true;
PsiElement parent = element.getParent();
if (parent instanceof GrVariable &&
((GrVariable)parent).getTypeElementGroovy() == null &&
element == ((GrVariable)parent).getNameIdentifierGroovy()) {
PsiElement pparent = parent.getParent();
if (pparent instanceof GrVariableDeclaration) {
GrVariable[] variables = ((GrVariableDeclaration)pparent).getVariables();
for (GrVariable variable : variables) {
if (isVarDeclaredWithInitializer(variable)) return true;
}
}
else {
return isVarDeclaredWithInitializer((GrVariable)parent);
}
}
@@ -109,4 +138,9 @@ public class GrSetStrongTypeIntention extends Intention {
}
};
}
private static boolean isVarDeclaredWithInitializer(GrVariable variable) {
GrExpression initializer = variable.getInitializerGroovy();
return initializer != null && initializer.getType() != null;
}
}
@@ -45,7 +45,7 @@ public class InitialInfo implements ExtractInfoHelper {
private final Project myProject;
private final GrStatement[] myStatements;
private final boolean myHasReturnValue;
private String[] myArgumentNames;
private final String[] myArgumentNames;
public InitialInfo(VariableInfo[] inputInfos,
VariableInfo[] outputInfos,
@@ -238,7 +238,7 @@ public class MavenModuleImporter {
if (sdk != null) {
String versionString = sdk.getVersionString();
if (versionString != null) {
if (versionString.contains("1.5.") || versionString.contains("1.4.") || versionString.contains("1.3.") || versionString.contains("1.2.")) {
if (versionString.contains("1.5") || versionString.contains("1.4") || versionString.contains("1.3") || versionString.contains("1.2")) {
return;
}
}
@@ -205,12 +205,10 @@ public class MavenServerManager extends RemoteObjectWrapper<MavenServer> {
for (String param : mavenOptsList.getParameters()) {
if (param.startsWith("-Xmx")) {
params.getVMParametersList().add(param);
xmxSet = true;
}
else if (param.startsWith("-Xms") || param.startsWith("-XX:MaxPermSize") || param.startsWith("-XX:PermSize")) {
params.getVMParametersList().add(param);
}
params.getVMParametersList().add(param);
}
}