Merge remote-tracking branch 'origin/master'

This commit is contained in:
graann
2018-05-14 15:02:19 +03:00
2 changed files with 11 additions and 29 deletions
@@ -27,7 +27,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import static com.intellij.util.ObjectUtils.assertNotNull;
import static com.intellij.util.ObjectUtils.tryCast;
import static java.util.Collections.emptyList;
@@ -40,10 +39,10 @@ public class VariableAccessFromInnerClassJava10Fix extends BaseIntentionAction {
};
private static final LinkedHashSet<String> ourSuggestions = new LinkedHashSet<>(Arrays.asList(NAMES));
private final SmartPsiElementPointer<PsiElement> myContext;
private final PsiElement myContext;
public VariableAccessFromInnerClassJava10Fix(PsiElement context) {
myContext = SmartPointerManager.createPointer(context);
myContext = context;
}
@Nls(capitalization = Nls.Capitalization.Sentence)
@@ -56,7 +55,7 @@ public class VariableAccessFromInnerClassJava10Fix extends BaseIntentionAction {
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!PsiUtil.isLanguageLevel10OrHigher(file)) return false;
if (myContext.getElement() == null) return false;
if (!myContext.isValid()) return false;
PsiReferenceExpression reference = tryCast(myContext, PsiReferenceExpression.class);
if (reference == null) return false;
PsiLocalVariable variable = tryCast(reference.resolve(), PsiLocalVariable.class);
@@ -69,7 +68,7 @@ public class VariableAccessFromInnerClassJava10Fix extends BaseIntentionAction {
(variable.getTypeElement().isInferredType() &&
type instanceof PsiClassType &&
((PsiClassType)type).resolve() instanceof PsiAnonymousClass)
) {
) {
return false;
}
setText(QuickFixBundle.message("convert.variable.to.field.in.anonymous.class.fix.name", name));
@@ -78,12 +77,10 @@ public class VariableAccessFromInnerClassJava10Fix extends BaseIntentionAction {
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
PsiElement context = myContext.getElement();
assertNotNull(context);
if (!FileModificationService.getInstance().preparePsiElementsForWrite(context)) return;
if (!FileModificationService.getInstance().preparePsiElementsForWrite(myContext)) return;
WriteCommandAction.runWriteCommandAction(project, () -> {
if (context instanceof PsiReferenceExpression && context.isValid()) {
PsiReferenceExpression referenceExpression = (PsiReferenceExpression)context;
if (myContext instanceof PsiReferenceExpression && myContext.isValid()) {
PsiReferenceExpression referenceExpression = (PsiReferenceExpression)myContext;
PsiLocalVariable variable = tryCast(referenceExpression.resolve(), PsiLocalVariable.class);
if (variable == null) return;
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
@@ -91,7 +88,7 @@ public class VariableAccessFromInnerClassJava10Fix extends BaseIntentionAction {
final String variableText = getFieldText(variable, factory, initializer);
PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(context, PsiLambdaExpression.class);
PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(myContext, PsiLambdaExpression.class);
if (lambdaExpression == null) return;
DeclarationInfo declarationInfo = DeclarationInfo.findExistingAnonymousClass(variable);
@@ -1,22 +1,9 @@
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.jps.util;
import com.intellij.openapi.util.SystemInfoRt;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -62,9 +49,7 @@ public class JpsPathUtil {
}
else if (url.startsWith("jar://")) {
url = url.substring("jar://".length());
if (url.endsWith("!/")) {
url = url.substring(0, url.length() - "!/".length());
}
url = StringUtil.trimEnd(url, "!/");
}
return url;
}