mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
Cleanup (duplicates; warnings; typos; formatting)
This commit is contained in:
@@ -160,9 +160,9 @@ public class JavaFindUsagesProvider implements FindUsagesProvider {
|
||||
return "anonymous " + StringUtil.notNullize(name, "class");
|
||||
}
|
||||
else {
|
||||
final PsiClass aClass = (PsiClass)element;
|
||||
String qName = aClass.getQualifiedName();
|
||||
return qName == null ? aClass.getName() : qName;
|
||||
PsiClass aClass = (PsiClass)element;
|
||||
String qName = aClass.getQualifiedName();
|
||||
return qName != null ? qName : aClass.getName() != null ? aClass.getName() : "<unknown>";
|
||||
}
|
||||
}
|
||||
if (element instanceof PsiMethod) {
|
||||
@@ -226,15 +226,19 @@ public class JavaFindUsagesProvider implements FindUsagesProvider {
|
||||
if (element instanceof PsiDirectory) {
|
||||
return getPackageName((PsiDirectory)element, false);
|
||||
}
|
||||
|
||||
if (element instanceof PsiPackage) {
|
||||
return getPackageName((PsiPackage)element);
|
||||
}
|
||||
|
||||
if (element instanceof PsiFile) {
|
||||
return useFullName ? ((PsiFile)element).getVirtualFile().getPresentableUrl() : ((PsiFile)element).getName();
|
||||
}
|
||||
|
||||
if (element instanceof PsiLabeledStatement) {
|
||||
return ((PsiLabeledStatement)element).getLabelIdentifier().getText();
|
||||
}
|
||||
|
||||
if (ThrowSearchUtil.isSearchable(element)) {
|
||||
return ThrowSearchUtil.getSearchableTypeName(element);
|
||||
}
|
||||
@@ -246,87 +250,55 @@ public class JavaFindUsagesProvider implements FindUsagesProvider {
|
||||
}
|
||||
if (name != null) return name;
|
||||
}
|
||||
|
||||
if (element instanceof PsiMethod) {
|
||||
PsiMethod psiMethod = (PsiMethod)element;
|
||||
if (useFullName) {
|
||||
String s = PsiFormatUtil.formatMethod((PsiMethod)element,
|
||||
PsiSubstitutor.EMPTY, PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE |
|
||||
PsiFormatUtilBase.SHOW_NAME |
|
||||
PsiFormatUtilBase.SHOW_PARAMETERS,
|
||||
PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME);
|
||||
final PsiClass psiClass = psiMethod.getContainingClass();
|
||||
if (psiClass != null) {
|
||||
final String qName = psiClass.getQualifiedName();
|
||||
if (qName != null) {
|
||||
if (psiClass.isInterface()) {
|
||||
s = LangBundle.message("java.terms.of.interface", s, qName);
|
||||
}
|
||||
else {
|
||||
s = LangBundle.message("java.terms.of.class", s, qName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
int options = PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS;
|
||||
String s = PsiFormatUtil.formatMethod((PsiMethod)element, PsiSubstitutor.EMPTY, options, PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME);
|
||||
return appendClassName(s, psiMethod.getContainingClass());
|
||||
}
|
||||
else {
|
||||
return PsiFormatUtil.formatMethod(psiMethod,
|
||||
PsiSubstitutor.EMPTY,
|
||||
PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
|
||||
PsiFormatUtilBase.SHOW_TYPE);
|
||||
int options = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS;
|
||||
return PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY, options, PsiFormatUtilBase.SHOW_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
if (element instanceof PsiParameter && ((PsiParameter)element).getDeclarationScope() instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)((PsiParameter)element).getDeclarationScope();
|
||||
int varOptions = PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME;
|
||||
int methodOptions = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS;
|
||||
String s = LangBundle.message("java.terms.variable.of.method",
|
||||
PsiFormatUtil.formatVariable((PsiVariable)element,
|
||||
PsiFormatUtilBase.TYPE_AFTER |
|
||||
PsiFormatUtilBase.SHOW_TYPE |
|
||||
PsiFormatUtilBase.SHOW_NAME,
|
||||
PsiSubstitutor.EMPTY),
|
||||
PsiFormatUtil.formatMethod(method,
|
||||
PsiSubstitutor.EMPTY,
|
||||
PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
|
||||
PsiFormatUtilBase.SHOW_TYPE));
|
||||
|
||||
final PsiClass psiClass = method.getContainingClass();
|
||||
if (psiClass != null && psiClass.getQualifiedName() != null) {
|
||||
if (psiClass.isInterface()) {
|
||||
s = LangBundle.message("java.terms.of.interface", s, psiClass.getQualifiedName());
|
||||
}
|
||||
else {
|
||||
s = LangBundle.message("java.terms.of.class", s, psiClass.getQualifiedName());
|
||||
}
|
||||
}
|
||||
return s;
|
||||
PsiFormatUtil.formatVariable((PsiVariable)element, varOptions, PsiSubstitutor.EMPTY),
|
||||
PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE));
|
||||
return appendClassName(s, method.getContainingClass());
|
||||
}
|
||||
|
||||
if (element instanceof PsiField) {
|
||||
PsiField psiField = (PsiField)element;
|
||||
String s = PsiFormatUtil.formatVariable(psiField,
|
||||
PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME,
|
||||
PsiSubstitutor.EMPTY);
|
||||
PsiClass psiClass = psiField.getContainingClass();
|
||||
if (psiClass != null) {
|
||||
String qName = psiClass.getQualifiedName();
|
||||
if (qName != null) {
|
||||
if (psiClass.isInterface()) {
|
||||
s = LangBundle.message("java.terms.of.interface", s, qName);
|
||||
}
|
||||
else {
|
||||
s = LangBundle.message("java.terms.of.class", s, qName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
int options = PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME;
|
||||
String s = PsiFormatUtil.formatVariable(psiField, options, PsiSubstitutor.EMPTY);
|
||||
return appendClassName(s, psiField.getContainingClass());
|
||||
}
|
||||
|
||||
if (element instanceof PsiVariable) {
|
||||
return PsiFormatUtil.formatVariable((PsiVariable)element,
|
||||
PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME,
|
||||
PsiSubstitutor.EMPTY);
|
||||
int options = PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME;
|
||||
return PsiFormatUtil.formatVariable((PsiVariable)element, options, PsiSubstitutor.EMPTY);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String appendClassName(String s, PsiClass psiClass) {
|
||||
if (psiClass != null) {
|
||||
String qName = psiClass.getQualifiedName();
|
||||
if (qName != null) {
|
||||
s = LangBundle.message(psiClass.isInterface() ? "java.terms.of.interface" : "java.terms.of.class", s, qName);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String getPackageName(PsiDirectory directory, boolean includeRootDir) {
|
||||
PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
|
||||
if (aPackage == null) {
|
||||
@@ -374,4 +346,4 @@ public class JavaFindUsagesProvider implements FindUsagesProvider {
|
||||
public WordsScanner getWordsScanner() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -19,40 +19,44 @@ import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.PlatformPatterns;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameHelper;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.impl.file.PsiDirectoryFactory;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 3/14/11
|
||||
* @author anna
|
||||
* @since 14.03.2011
|
||||
*/
|
||||
public class PsiPackageRenameValidator implements RenameInputValidatorEx {
|
||||
private final ElementPattern<? extends PsiElement> myPattern = PlatformPatterns.psiElement(PsiPackage.class);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ElementPattern<? extends PsiElement> getPattern() {
|
||||
return myPattern;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getErrorMessage(String newName, Project project) {
|
||||
public String getErrorMessage(@NotNull String newName, @NotNull Project project) {
|
||||
if (FileTypeManager.getInstance().isFileIgnored(newName)) {
|
||||
return "Trying to create a package with ignored name, result will not be visible";
|
||||
}
|
||||
|
||||
if (newName.length() > 0) {
|
||||
if (!PsiDirectoryFactory.getInstance(project).isValidPackageName(newName)) {
|
||||
return "Not a valid package name";
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementPattern<? extends PsiElement> getPattern() {
|
||||
return PlatformPatterns.psiElement(PsiPackage.class);
|
||||
public boolean isInputValid(@NotNull String newName, @NotNull PsiElement element, @NotNull ProcessingContext context) {
|
||||
return !newName.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputValid(String newName, PsiElement element, ProcessingContext context) {
|
||||
return newName != null && newName.length() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user