mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git@git.labs.intellij.net:idea/community
This commit is contained in:
@@ -54,9 +54,7 @@ public class MoveToPackageFix implements LocalQuickFix {
|
||||
&& myFile.getManager().isInProject(myFile)
|
||||
&& myFile instanceof PsiJavaFile
|
||||
&& ((PsiJavaFile) myFile).getClasses().length != 0
|
||||
&& myTargetPackage != null
|
||||
&& JavaPsiFacade.getInstance(myFile.getProject()).findPackage(myTargetPackage) != null
|
||||
;
|
||||
&& myTargetPackage != null;
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
|
||||
+2
-5
@@ -63,12 +63,9 @@ public class WrongPackageStatementInspection extends BaseJavaLocalInspectionTool
|
||||
final PsiJavaCodeReferenceElement packageReference = packageStatement.getPackageReference();
|
||||
PsiPackage classPackage = (PsiPackage)packageReference.resolve();
|
||||
List<LocalQuickFix> availableFixes = new ArrayList<LocalQuickFix>();
|
||||
if (classPackage == null) {
|
||||
if (classPackage == null || !Comparing.equal(dirPackage.getQualifiedName(), packageReference.getText(), true)) {
|
||||
availableFixes.add(new AdjustPackageNameFix(packageName));
|
||||
}
|
||||
else if (!Comparing.equal(dirPackage.getQualifiedName(), packageReference.getText(), true)) {
|
||||
availableFixes.add(new AdjustPackageNameFix(packageName));
|
||||
MoveToPackageFix moveToPackageFix = new MoveToPackageFix(classPackage.getQualifiedName());
|
||||
MoveToPackageFix moveToPackageFix = new MoveToPackageFix(classPackage != null ? classPackage.getQualifiedName() : packageReference.getText());
|
||||
if (moveToPackageFix.isAvailable(file)) {
|
||||
availableFixes.add(moveToPackageFix);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,6 @@ public final class GroupByScopeTypeAction extends ToggleAction {
|
||||
|
||||
public void update(final AnActionEvent e) {
|
||||
super.update(e);
|
||||
e.getPresentation().setEnabled(DependencyUISettings.getInstance().SCOPE_TYPE != ProjectPatternProvider.FILE);
|
||||
e.getPresentation().setVisible(DependencyUISettings.getInstance().SCOPE_TYPE != ProjectPatternProvider.FILE);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -62,6 +63,50 @@ public class FormattingAstUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ASTNode getPrevLeaf(@NotNull final ASTNode node, @NotNull IElementType ... typesToIgnore) {
|
||||
ASTNode prev = getPrev(node, typesToIgnore);
|
||||
if (prev == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ASTNode result = prev;
|
||||
ASTNode lastChild = prev.getLastChildNode();
|
||||
while (lastChild != null) {
|
||||
result = lastChild;
|
||||
lastChild = lastChild.getLastChildNode();
|
||||
}
|
||||
|
||||
for (IElementType type : typesToIgnore) {
|
||||
if (result.getElementType() == type) {
|
||||
return getPrevLeaf(result, typesToIgnore);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ASTNode getPrev(@NotNull ASTNode node, @NotNull IElementType... typesToIgnore) {
|
||||
ASTNode prev = node.getTreePrev();
|
||||
ASTNode parent = node.getTreeParent();
|
||||
while (prev == null && parent != null) {
|
||||
prev = parent.getTreePrev();
|
||||
parent = parent.getTreeParent();
|
||||
}
|
||||
|
||||
if (prev == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (IElementType type : typesToIgnore) {
|
||||
if (prev.getElementType() == type) {
|
||||
return getPrev(prev, typesToIgnore);
|
||||
}
|
||||
}
|
||||
|
||||
return prev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to get next non-white space <code>AST</code> node for the given one.
|
||||
*
|
||||
|
||||
@@ -1175,11 +1175,9 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
createSpaceInCode(mySettings.SPACE_WITHIN_FOR_PARENTHESES);
|
||||
}
|
||||
else {
|
||||
ASTNode prev = FormattingAstUtil.getPrevNonWhiteSpaceNode(myChild2);
|
||||
if (prev != null && (prev.getElementType() == JavaTokenType.SEMICOLON || prev == statement.getInitialization()
|
||||
|| prev == statement.getCondition()))
|
||||
{
|
||||
// Handle empty 'condition' section.
|
||||
ASTNode prev = FormattingAstUtil.getPrevLeaf(myChild2, TokenType.WHITE_SPACE, TokenType.ERROR_ELEMENT);
|
||||
if (prev != null && prev.getElementType() == JavaTokenType.SEMICOLON) {
|
||||
// Handle empty 'initialization' or 'condition' section.
|
||||
createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
|
||||
}
|
||||
else {
|
||||
|
||||
+14
-26
@@ -125,22 +125,6 @@ public abstract class AbstractInplaceIntroducer extends VariableInplaceIntroduce
|
||||
super.addHighlights(ranges, editor, highlighters, highlightManager);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static PsiExpression restoreExpression(PsiFile containingFile,
|
||||
PsiVariable psiVariable,
|
||||
PsiElementFactory elementFactory,
|
||||
RangeMarker marker, String exprText) {
|
||||
if (exprText == null) return null;
|
||||
if (psiVariable == null || !psiVariable.isValid()) return null;
|
||||
final PsiElement refVariableElement = containingFile.findElementAt(marker.getStartOffset());
|
||||
final PsiExpression expression = PsiTreeUtil.getParentOfType(refVariableElement, PsiReferenceExpression.class);
|
||||
if (expression instanceof PsiReferenceExpression && (((PsiReferenceExpression)expression).resolve() == psiVariable ||
|
||||
Comparing.strEqual(psiVariable.getName(), ((PsiReferenceExpression)expression).getReferenceName()))) {
|
||||
return (PsiExpression)expression.replace(elementFactory.createExpressionFromText(exprText, psiVariable));
|
||||
}
|
||||
return expression != null && expression.isValid() && expression.getText().equals(exprText) ? expression : null;
|
||||
}
|
||||
|
||||
protected abstract class VisibilityListener implements ChangeListener {
|
||||
private Project myProject;
|
||||
private final String myCommandName;
|
||||
@@ -179,20 +163,24 @@ public abstract class AbstractInplaceIntroducer extends VariableInplaceIntroduce
|
||||
length = PsiModifier.PRIVATE.length();
|
||||
}
|
||||
|
||||
final int startOffset = textOffset + idx;
|
||||
final int endOffset;
|
||||
if (idx == -1) {
|
||||
endOffset = startOffset;
|
||||
}
|
||||
else {
|
||||
endOffset = textOffset + length;
|
||||
}
|
||||
|
||||
String visibility = getVisibility();
|
||||
if (visibility == PsiModifier.PACKAGE_LOCAL) {
|
||||
visibility = "";
|
||||
}
|
||||
final String finalVisibility = visibility;
|
||||
|
||||
final boolean wasPackageLocal = idx == -1;
|
||||
final boolean isPackageLocal = visibility.isEmpty();
|
||||
|
||||
final int startOffset = textOffset + (wasPackageLocal ? 0 : idx);
|
||||
final int endOffset;
|
||||
if (wasPackageLocal) {
|
||||
endOffset = startOffset;
|
||||
}
|
||||
else {
|
||||
endOffset = textOffset + length + (isPackageLocal ? 1 : 0);
|
||||
}
|
||||
|
||||
final String finalVisibility = visibility + (wasPackageLocal ? " " : "");
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
|
||||
+3
-1
@@ -465,6 +465,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
|
||||
for (PsiExpression occurrence : occurrences) {
|
||||
occurrenceMarkers.add(editor.getDocument().createRangeMarker(occurrence.getTextRange()));
|
||||
}
|
||||
final String expressionText = expr.getText();
|
||||
final Runnable runnable =
|
||||
introduce(project, expr, editor, anchorStatement, tempContainer, occurrences, anchorStatementIfAll, settings, variable);
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
@@ -477,9 +478,10 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
|
||||
if (elementToRename != null) {
|
||||
editor.getCaretModel().moveToOffset(elementToRename.getTextOffset());
|
||||
final boolean cantChangeFinalModifier = (hasWriteAccess || inFinalContext) && choice == OccurrencesChooser.ReplaceChoice.ALL;
|
||||
final VariableInplaceRenamer renamer =
|
||||
final VariableInplaceIntroducer renamer =
|
||||
new VariableInplaceIntroducer(project, expression, editor, elementToRename, cantChangeFinalModifier,
|
||||
typeSelectorManager.getTypesForAll().length > 1, exprMarker, occurrenceMarkers, IntroduceVariableBase.REFACTORING_NAME, IntroduceVariableBase.REFACTORING_NAME);
|
||||
renamer.initInitialText(expressionText);
|
||||
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
|
||||
renamer.performInplaceRename(false, new LinkedHashSet<String>(Arrays.asList(suggestedName.names)));
|
||||
}
|
||||
|
||||
+38
@@ -79,6 +79,7 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
private boolean myCantChangeFinalModifier;
|
||||
private String myCommandName;
|
||||
private String myTitle;
|
||||
private String myExpressionText;
|
||||
|
||||
public VariableInplaceIntroducer(final Project project,
|
||||
final TypeExpression expression,
|
||||
@@ -111,7 +112,10 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
editor.putUserData(ReassignVariableUtil.OCCURRENCES_KEY,
|
||||
occurrenceMarkers.toArray(new RangeMarker[occurrenceMarkers.size()]));
|
||||
setAdvertisementText(getAdvertisementText(declarationStatement, defaultType, hasTypeSuggestion));
|
||||
}
|
||||
|
||||
public void initInitialText(String text) {
|
||||
myExpressionText = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,6 +220,24 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
myEditor.getCaretModel().moveToOffset(myExprMarker.getStartOffset());
|
||||
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
|
||||
}
|
||||
if (myExpressionText != null) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final PsiDeclarationStatement element = myPointer.getElement();
|
||||
if (element != null) {
|
||||
final PsiElement[] vars = element.getDeclaredElements();
|
||||
if (vars.length > 0 && vars[0] instanceof PsiVariable) {
|
||||
final PsiFile containingFile = element.getContainingFile();
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myProject);
|
||||
for (RangeMarker occurrenceMarker : myOccurrenceMarkers) {
|
||||
restoreExpression(containingFile, (PsiVariable)vars[0], elementFactory, occurrenceMarker, myExpressionText);
|
||||
}
|
||||
element.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
@@ -396,6 +418,22 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
myBalloon.show(new RelativePoint(new Point(screenPoint.x, y)), Balloon.Position.above);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static PsiExpression restoreExpression(PsiFile containingFile,
|
||||
PsiVariable psiVariable,
|
||||
PsiElementFactory elementFactory,
|
||||
RangeMarker marker, String exprText) {
|
||||
if (exprText == null) return null;
|
||||
if (psiVariable == null || !psiVariable.isValid()) return null;
|
||||
final PsiElement refVariableElement = containingFile.findElementAt(marker.getStartOffset());
|
||||
final PsiExpression expression = PsiTreeUtil.getParentOfType(refVariableElement, PsiReferenceExpression.class);
|
||||
if (expression instanceof PsiReferenceExpression && (((PsiReferenceExpression)expression).resolve() == psiVariable ||
|
||||
Comparing.strEqual(psiVariable.getName(), ((PsiReferenceExpression)expression).getReferenceName()))) {
|
||||
return (PsiExpression)expression.replace(elementFactory.createExpressionFromText(exprText, psiVariable));
|
||||
}
|
||||
return expression != null && expression.isValid() && expression.getText().equals(exprText) ? expression : null;
|
||||
}
|
||||
|
||||
public class FinalListener implements ActionListener {
|
||||
private final Project myProject;
|
||||
private final String myCommandName;
|
||||
|
||||
@@ -527,6 +527,7 @@ public class FindUtil {
|
||||
((DocumentEx) document).setInBulkUpdate(true);
|
||||
}
|
||||
}
|
||||
int newOffset;
|
||||
if (delegate == null || delegate.shouldReplace(result, toReplace)){
|
||||
boolean reallyReplace = toPrompt;
|
||||
if (reallyReplace) {
|
||||
@@ -538,13 +539,17 @@ public class FindUtil {
|
||||
}
|
||||
TextRange textRange = doReplace(project, document, model, result, toReplace, reallyReplace, rangesToChange);
|
||||
replaced = true;
|
||||
int newOffset = model.isForward() ? textRange.getEndOffset() : textRange.getStartOffset();
|
||||
if (newOffset == offset) {
|
||||
newOffset += model.isForward() ? 1 : -1;
|
||||
}
|
||||
offset = newOffset;
|
||||
newOffset = model.isForward() ? textRange.getEndOffset() : textRange.getStartOffset();
|
||||
occurrences++;
|
||||
}
|
||||
else {
|
||||
newOffset = model.isForward() ? result.getEndOffset() : result.getStartOffset();
|
||||
}
|
||||
|
||||
if (newOffset == offset) {
|
||||
newOffset += model.isForward() ? 1 : -1;
|
||||
}
|
||||
offset = newOffset;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.*;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.ModuleListener;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -566,7 +567,9 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent
|
||||
swingRunnable.run();
|
||||
}
|
||||
else {
|
||||
app.invokeAndWait(swingRunnable, ModalityState.defaultModalityState());
|
||||
ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
|
||||
pi.setText("Loading " + module.getName());
|
||||
app.invokeAndWait(swingRunnable, pi.getModalityState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -139,7 +139,7 @@ public class ProjectPatternProvider extends PatternDialectProvider {
|
||||
|
||||
public void update(final AnActionEvent e) {
|
||||
super.update(e);
|
||||
e.getPresentation().setEnabled(DependencyUISettings.getInstance().SCOPE_TYPE == FILE);
|
||||
e.getPresentation().setVisible(DependencyUISettings.getInstance().SCOPE_TYPE == FILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -34,7 +34,7 @@
|
||||
<text value="Allow to send usages statistics to JetBrains"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="d4bdc" layout-manager="GridLayoutManager" row-count="1" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="d4bdc" binding="myRadioButtonPanel" layout-manager="GridLayoutManager" row-count="1" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
|
||||
+19
@@ -21,6 +21,8 @@ import com.intellij.openapi.ui.ex.MultiLineLabel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class StatisticsConfigurationComponent {
|
||||
|
||||
@@ -31,10 +33,26 @@ public class StatisticsConfigurationComponent {
|
||||
private JRadioButton myMonthlyRadioButton;
|
||||
private JRadioButton myWeeklyRadioButton;
|
||||
private JLabel myLabel;
|
||||
private JPanel myRadioButtonPanel;
|
||||
|
||||
public StatisticsConfigurationComponent() {
|
||||
myTitle.setText("Help improve "+ ApplicationNamesInfo.getInstance().getFullProductName() + " by sending anonymous usage statistics to JetBrains");
|
||||
myLabel.setText("<html>We're asking your permission to send information about your plugins configuration (what is enabled and what is not) <br> and feature usage statistics (e.g. how frequently you're using code completion).<br> This data is anonymous, does not contain any personal information, collected for use only by JetBrains<br> and will never be transmitted to any third party.</html>");
|
||||
|
||||
myAllowToSendUsagesCheckBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setRadioButtonsEnabled();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setRadioButtonsEnabled() {
|
||||
final boolean enabled = myAllowToSendUsagesCheckBox.isSelected();
|
||||
|
||||
myWeeklyRadioButton.setEnabled(enabled);
|
||||
myMonthlyRadioButton.setEnabled(enabled);
|
||||
myDailyRadioButton.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public JPanel getJComponent() {
|
||||
@@ -49,6 +67,7 @@ public class StatisticsConfigurationComponent {
|
||||
final UsageStatisticsPersistenceComponent persistenceComponent = UsageStatisticsPersistenceComponent.getInstance();
|
||||
|
||||
myAllowToSendUsagesCheckBox.setSelected(persistenceComponent.isAllowed());
|
||||
setRadioButtonsEnabled();
|
||||
|
||||
final SendPeriod period = persistenceComponent.getPeriod();
|
||||
|
||||
|
||||
+2
-1
@@ -686,9 +686,10 @@ public class SchemaReferencesProvider extends PsiReferenceProvider {
|
||||
}
|
||||
|
||||
public static @Nullable XmlNSDescriptorImpl findRedefinedDescriptor(XmlTag tag, String text) {
|
||||
final String localName = XmlUtil.findLocalNameByQualifiedName(text);
|
||||
for(XmlTag parentTag = tag.getParentTag(); parentTag != null; parentTag = parentTag.getParentTag()) {
|
||||
|
||||
if (text.equals(parentTag.getAttributeValue("name"))) {
|
||||
if (localName.equals(parentTag.getAttributeValue("name"))) {
|
||||
final XmlTag grandParent = parentTag.getParentTag();
|
||||
|
||||
if (grandParent != null && "redefine".equals(grandParent.getLocalName())) {
|
||||
|
||||
Reference in New Issue
Block a user