Cleanup (warnings; formatting)

This commit is contained in:
Roman Shevchenko
2016-09-25 14:54:29 +03:00
parent e8e78ac4a5
commit acb243c511
6 changed files with 58 additions and 40 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -17,15 +17,14 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.roots.ExternalLibraryDescriptor;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.DependencyScope;
import com.intellij.openapi.roots.ExternalLibraryDescriptor;
import com.intellij.openapi.roots.JavaProjectModelModificationService;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.util.Consumer;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
@@ -34,17 +33,17 @@ import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
class AddExternalLibraryToDependenciesQuickFix extends OrderEntryFix {
class AddExternalLibraryToDependenciesQuickFix extends AddOrderEntryFix {
private final Module myCurrentModule;
private final PsiReference myReference;
private final ExternalLibraryDescriptor myLibraryDescriptor;
private final String myQualifiedClassName;
public AddExternalLibraryToDependenciesQuickFix(@NotNull Module currentModule,
@NotNull ExternalLibraryDescriptor libraryDescriptor, @NotNull PsiReference reference,
@NotNull ExternalLibraryDescriptor libraryDescriptor,
@NotNull PsiReference reference,
@Nullable String qualifiedClassName) {
super(reference);
myCurrentModule = currentModule;
myReference = reference;
myLibraryDescriptor = libraryDescriptor;
myQualifiedClassName = qualifiedClassName;
}
@@ -71,11 +70,12 @@ class AddExternalLibraryToDependenciesQuickFix extends OrderEntryFix {
@Override
public void invoke(@NotNull Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
DependencyScope scope = suggestScopeByLocation(myCurrentModule, myReference.getElement());
JavaProjectModelModificationService.getInstance(project).addDependency(myCurrentModule, myLibraryDescriptor, scope).done(
aVoid -> new WriteAction() {
JavaProjectModelModificationService.getInstance(project)
.addDependency(myCurrentModule, myLibraryDescriptor, scope)
.done(aVoid -> new WriteAction() {
protected void run(@NotNull final Result result) {
importClass(myCurrentModule, editor, myReference, myQualifiedClassName);
}
}.execute());
}
}
}
@@ -32,19 +32,18 @@ import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
class AddLibraryToDependenciesFix extends OrderEntryFix {
class AddLibraryToDependenciesFix extends AddOrderEntryFix {
private final Library myLibrary;
private final Module myCurrentModule;
private final PsiReference myReference;
private final String myQualifiedClassName;
public AddLibraryToDependenciesFix(@NotNull Module currentModule,
@NotNull Library library,
@NotNull PsiReference reference,
@Nullable String qualifiedClassName) {
super(reference);
myLibrary = library;
myCurrentModule = currentModule;
myReference = reference;
myQualifiedClassName = qualifiedClassName;
}
@@ -44,20 +44,19 @@ import java.util.*;
* @author anna
* @since 20.11.2012
*/
class AddModuleDependencyFix extends OrderEntryFix {
class AddModuleDependencyFix extends AddOrderEntryFix {
private static final Logger LOG = Logger.getInstance(AddModuleDependencyFix.class);
private final Module myCurrentModule;
private final VirtualFile myRefVFile;
private final List<PsiClass> myClasses;
private final PsiReference myReference;
private final Set<Module> myModules;
public AddModuleDependencyFix(Module currentModule, VirtualFile refVFile, List<PsiClass> classes, PsiReference reference) {
super(reference);
myCurrentModule = currentModule;
myRefVFile = refVFile;
myClasses = classes;
myReference = reference;
myModules = new LinkedHashSet<>();
final PsiElement psiElement = reference.getElement();
@@ -79,10 +78,10 @@ class AddModuleDependencyFix extends OrderEntryFix {
}
public AddModuleDependencyFix(Module currentModule, VirtualFile refVFile, Set<Module> modules, PsiReference reference) {
super(reference);
myCurrentModule = currentModule;
myRefVFile = refVFile;
myClasses = Collections.emptyList();
myReference = reference;
myModules = modules;
}
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.psi.PsiReference;
abstract class AddOrderEntryFix extends OrderEntryFix {
@SuppressWarnings("StatefulEp") protected final PsiReference myReference;
protected AddOrderEntryFix(PsiReference reference) {
myReference = reference;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.impl.source.resolve.reference.impl.providers;
import com.intellij.codeInsight.daemon.EmptyResolveMessageProvider;
@@ -26,11 +25,10 @@ import org.jetbrains.annotations.NotNull;
import java.util.*;
public class PsiPackageReference extends PsiPolyVariantReferenceBase<PsiElement> implements EmptyResolveMessageProvider {
private final PackageReferenceSet myReferenceSet;
private final int myIndex;
public PsiPackageReference(final PackageReferenceSet set, final TextRange range, final int index) {
public PsiPackageReference(PackageReferenceSet set, TextRange range, int index) {
super(set.getElement(), range, set.isSoft());
myReferenceSet = set;
myIndex = index;
@@ -54,27 +52,27 @@ public class PsiPackageReference extends PsiPolyVariantReferenceBase<PsiElement>
public Object[] getVariants() {
Set<PsiPackage> subPackages = new HashSet<>();
for (PsiPackage psiPackage : getContext()) {
subPackages.addAll(Arrays.asList(psiPackage.getSubPackages(myReferenceSet.getResolveScope())));
subPackages.addAll(Arrays.asList(psiPackage.getSubPackages(myReferenceSet.getResolveScope())));
}
return subPackages.toArray();
}
@NotNull
@Override
public String getUnresolvedMessagePattern() {
//noinspection UnresolvedPropertyKey
return JavaErrorMessages.message("cannot.resolve.package");
}
@Override
@NotNull
public ResolveResult[] multiResolve(final boolean incompleteCode) {
public ResolveResult[] multiResolve(boolean incompleteCode) {
return doMultiResolve();
}
@NotNull
protected ResolveResult[] doMultiResolve() {
final Collection<PsiPackage> packages = new HashSet<>();
Collection<PsiPackage> packages = new HashSet<>();
for (PsiPackage parentPackage : getContext()) {
packages.addAll(myReferenceSet.resolvePackageName(parentPackage, getValue()));
}
@@ -82,18 +80,16 @@ public class PsiPackageReference extends PsiPolyVariantReferenceBase<PsiElement>
}
@Override
public PsiElement bindToElement(@NotNull final PsiElement element) throws IncorrectOperationException {
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
if (!(element instanceof PsiPackage)) {
throw new IncorrectOperationException("Cannot bind to " + element);
}
final String newName = ((PsiPackage)element).getQualifiedName();
final TextRange range =
new TextRange(getReferenceSet().getReference(0).getRangeInElement().getStartOffset(), getRangeInElement().getEndOffset());
final ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(getElement());
return manipulator.handleContentChange(getElement(), range, newName);
TextRange range = new TextRange(getReferenceSet().getReference(0).getRangeInElement().getStartOffset(), getRangeInElement().getEndOffset());
String newName = ((PsiPackage)element).getQualifiedName();
return ElementManipulators.getManipulator(getElement()).handleContentChange(getElement(), range, newName);
}
public PackageReferenceSet getReferenceSet() {
return myReferenceSet;
}
}
}
@@ -98,14 +98,11 @@ public final class SocketLock {
}
finally {
try {
underLocks(new Callable<Void>() {
@Override
public Void call() throws Exception {
FileUtil.delete(new File(myConfigPath, PORT_FILE));
FileUtil.delete(new File(mySystemPath, PORT_FILE));
FileUtil.delete(new File(mySystemPath, TOKEN_FILE));
return null;
}
underLocks(() -> {
FileUtil.delete(new File(myConfigPath, PORT_FILE));
FileUtil.delete(new File(mySystemPath, PORT_FILE));
FileUtil.delete(new File(mySystemPath, TOKEN_FILE));
return null;
});
}
catch (Exception e) {
@@ -262,6 +259,7 @@ public final class SocketLock {
return ActivateStatus.NO_INSTANCE;
}
@SuppressWarnings("ALL")
private static void printPID(int port) {
try {
Socket socket = new Socket(InetAddress.getLoopbackAddress(), port);