Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntentionDescriptionNotFoundInspection now ignores classes inherited from SyntheticIntentionAction #33

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class JetBrainsEmitter implements Emitter {
static final boolean REPLACE_TYPES_WITH_INTERFACES = true;
private String AUTHOR = null;

@Override
public void emit(FileManager fileManager, ModelDesc model, File outputRoot) {
final NamespaceDesc nsdDef = model.nsdMap.get("");
final Set<String> simpleTypes = new TreeSet<>();
Expand Down Expand Up @@ -95,7 +96,7 @@ public void generateClass(FileManager fileManager, TypeDesc td, ModelDesc model,
}
}
for (FieldDesc fd : td.fdMap.values()) {
if (fd.simpleTypesString != null && fd.simpleTypesString.indexOf(":fully-qualified-classType;") != -1) {
if (fd.simpleTypesString != null && fd.simpleTypesString.contains(":fully-qualified-classType;")) {
externalClasses.add("com.intellij.psi.PsiClass");
}
if (fd.contentQualifiedName != null && fd.contentQualifiedName.indexOf('.') > 0) {
Expand All @@ -119,7 +120,7 @@ public void generateClass(FileManager fileManager, TypeDesc td, ModelDesc model,
out.println("// DTD/Schema : " + nsd.name);
}
out.println("");
if (NOT_COMPARE_MODE && pkgName != null && pkgName.length() > 0) {
if (NOT_COMPARE_MODE && pkgName != null && !pkgName.isEmpty()) {
out.println("package " + pkgName + ";");
}
out.println();
Expand Down Expand Up @@ -264,44 +265,44 @@ public void generateClass(FileManager fileManager, TypeDesc td, ModelDesc model,
String newType = field.clType < 0 ? elementType : type;
String converterString = null;
if (field.simpleTypesString != null) {
if (field.simpleTypesString.indexOf(":fully-qualified-classType;") != -1) { // localType, remoteType, etc.
if (field.simpleTypesString.contains(":fully-qualified-classType;")) { // localType, remoteType, etc.
newType = "PsiClass";
//converterString = (JB_OFF ? "//" : "")+"\t@Convert (PsiClassReferenceConverter.class)";
}
else if (field.simpleTypesString.indexOf(":ejb-linkType;") != -1) {
else if (field.simpleTypesString.contains(":ejb-linkType;")) {
}
else if (field.simpleTypesString.indexOf(":ejb-ref-nameType;") != -1) { // jndi-nameType
else if (field.simpleTypesString.contains(":ejb-ref-nameType;")) { // jndi-nameType
}
else if (field.simpleTypesString.indexOf(":pathType;") != -1) {
else if (field.simpleTypesString.contains(":pathType;")) {
}
else if (field.simpleTypesString.indexOf(":java-identifierType;") != -1) {
else if (field.simpleTypesString.contains(":java-identifierType;")) {
//out.println((JB_OFF ? "//" : "") +"\t@Convert (JavaIdentifierConverter.class)");
}
else if (field.simpleTypesString.indexOf(":QName;") != -1) {
else if (field.simpleTypesString.contains(":QName;")) {
// ???
}
else if (field.simpleTypesString.indexOf(":integer;") != -1) { // BigDecimal
else if (field.simpleTypesString.contains(":integer;")) { // BigDecimal
newType = REPLACE_TYPES_WITH_INTERFACES ? "Integer" : "int";
}
else if (field.simpleTypesString.indexOf(":int;") != -1) {
else if (field.simpleTypesString.contains(":int;")) {
newType = REPLACE_TYPES_WITH_INTERFACES ? "Integer" : "int";
}
else if (field.simpleTypesString.indexOf(":byte;") != -1) {
else if (field.simpleTypesString.contains(":byte;")) {
newType = REPLACE_TYPES_WITH_INTERFACES ? "Byte" : "byte";
}
else if (field.simpleTypesString.indexOf(":short;") != -1) {
else if (field.simpleTypesString.contains(":short;")) {
newType = REPLACE_TYPES_WITH_INTERFACES ? "Short" : "short";
}
else if (field.simpleTypesString.indexOf(":long;") != -1) {
else if (field.simpleTypesString.contains(":long;")) {
newType = REPLACE_TYPES_WITH_INTERFACES ? "Long" : "long";
}
else if (field.simpleTypesString.indexOf(":float;") != -1) {
else if (field.simpleTypesString.contains(":float;")) {
newType = REPLACE_TYPES_WITH_INTERFACES ? "Float" : "float";
}
else if (field.simpleTypesString.indexOf(":double;") != -1) {
else if (field.simpleTypesString.contains(":double;")) {
newType = REPLACE_TYPES_WITH_INTERFACES ? "Double" : "double";
}
else if (field.simpleTypesString.indexOf(":boolean;") != -1) { // true-falseType
else if (field.simpleTypesString.contains(":boolean;")) { // true-falseType
newType = REPLACE_TYPES_WITH_INTERFACES ? "Boolean" : "boolean";
}
for (int idx = 0; idx != -1; ) {
Expand Down Expand Up @@ -470,7 +471,7 @@ else if (!name.equals(field.name)) {
try {
out.close();
}
catch (Exception ex) {
catch (Exception ignore) {
}
fileManager.releaseOutputFile(outFile);
}
Expand Down Expand Up @@ -531,7 +532,7 @@ private void generateSuper(FileManager fileManager, NamespaceDesc nsd, ModelDesc
out.close();
}
}
catch (Exception ex) {
catch (Exception ignore) {
}
fileManager.releaseOutputFile(outFile);
}
Expand Down Expand Up @@ -662,7 +663,7 @@ else if ((fd.clType == -FieldDesc.OBJ || fd.clType == -FieldDesc.STR)
try {
out.close();
}
catch (Exception ex) {
catch (Exception ignore) {
}
fileManager.releaseOutputFile(outFile);
}
Expand All @@ -680,7 +681,7 @@ public static void printDocumentation(PrintWriter out, String str, String prefix
}

public static String toPresentationName(String typeName) {
StringBuffer sb = new StringBuffer(typeName.length() + 10);
StringBuilder sb = new StringBuilder(typeName.length() + 10);
boolean prevUp = true;
for (int i = 0; i < typeName.length(); i++) {
char c = typeName.charAt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,44 @@
import java.util.List;

public class DescriptionCheckerUtil {
@Nonnull
@RequiredReadAction
public static PsiDirectory[] getDescriptionsDirs(Module module, DescriptionType descriptionType) {
List<PsiDirectory> dirs = new ArrayList<>();
ModuleRootManager manager = ModuleRootManager.getInstance(module);
PsiManager psiManager = PsiManager.getInstance(module.getProject());
@Nonnull
@RequiredReadAction
public static PsiDirectory[] getDescriptionsDirs(Module module, DescriptionType descriptionType) {
List<PsiDirectory> dirs = new ArrayList<>();
ModuleRootManager manager = ModuleRootManager.getInstance(module);
PsiManager psiManager = PsiManager.getInstance(module.getProject());

for (ContentFolder folder : manager.getContentFolders(LanguageContentFolderScopes.production())) {
VirtualFile file = folder.getFile();
if (file == null) {
continue;
}
for (ContentFolder folder : manager.getContentFolders(LanguageContentFolderScopes.production())) {
VirtualFile file = folder.getFile();
if (file == null) {
continue;
}

VirtualFile childDir = file.findFileByRelativePath(descriptionType.getDescriptionFolder());
if (childDir != null) {
PsiDirectory dir = psiManager.findDirectory(childDir);
if (dir != null) {
dirs.add(dir);
VirtualFile childDir = file.findFileByRelativePath(descriptionType.getDescriptionFolder());
if (childDir != null) {
PsiDirectory dir = psiManager.findDirectory(childDir);
if (dir != null) {
dirs.add(dir);
}
}
}
}
}

return dirs.toArray(PsiDirectory.EMPTY_ARRAY);
}
return dirs.toArray(PsiDirectory.EMPTY_ARRAY);
}

@Nullable
public static String getDescriptionDirName(PsiClass aClass) {
String descriptionDir = "";
PsiClass each = aClass;
while (each != null) {
String name = each.getName();
if (StringUtil.isEmptyOrSpaces(name)) {
return null;
}
descriptionDir = name + descriptionDir;
each = each.getContainingClass();
@Nullable
@RequiredReadAction
public static String getDescriptionDirName(PsiClass aClass) {
String descriptionDir = "";
PsiClass each = aClass;
while (each != null) {
String name = each.getName();
if (StringUtil.isEmptyOrSpaces(name)) {
return null;
}
descriptionDir = name + descriptionDir;
each = each.getContainingClass();
}
return descriptionDir;
}
return descriptionDir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,57 +26,69 @@
import java.util.Set;

public enum DescriptionType {
INTENTION(Set.of("com.intellij.codeInsight.intention.IntentionAction", "consulo.language.editor.intention.IntentionAction"),
"intentionDescriptions",
true),
INSPECTION(Set.of("com.intellij.codeInspection.InspectionProfileEntry",
"consulo.language.editor.inspection.scheme.InspectionProfileEntry"),
"inspectionDescriptions", false),
POSTFIX_TEMPLATES(Set.of("com.intellij.codeInsight.template.postfix.templates.PostfixTemplate",
"consulo.language.editor.postfixTemplate.PostfixTemplate"),
"postfixTemplates", true);
INTENTION(
Set.of("com.intellij.codeInsight.intention.IntentionAction", "consulo.language.editor.intention.IntentionAction"),
"intentionDescriptions",
true
),
INSPECTION(
Set.of(
"com.intellij.codeInspection.InspectionProfileEntry",
"consulo.language.editor.inspection.scheme.InspectionProfileEntry"
),
"inspectionDescriptions",
false
),
POSTFIX_TEMPLATES(
Set.of(
"com.intellij.codeInsight.template.postfix.templates.PostfixTemplate",
"consulo.language.editor.postfixTemplate.PostfixTemplate"
),
"postfixTemplates",
true
);

private final Set<String> myClassNames;
private final String myDescriptionFolder;
private final boolean myFixedDescriptionFilename;
private final Set<String> myClassNames;
private final String myDescriptionFolder;
private final boolean myFixedDescriptionFilename;

DescriptionType(Set<String> classes, String descriptionFolder, boolean fixedDescriptionFilename) {
myClassNames = classes;
myDescriptionFolder = descriptionFolder;
myFixedDescriptionFilename = fixedDescriptionFilename;
}
DescriptionType(Set<String> classes, String descriptionFolder, boolean fixedDescriptionFilename) {
myClassNames = classes;
myDescriptionFolder = descriptionFolder;
myFixedDescriptionFilename = fixedDescriptionFilename;
}

@Nonnull
public Set<String> getClassNames() {
return myClassNames;
}
@Nonnull
public Set<String> getClassNames() {
return myClassNames;
}

public String getDescriptionFolder() {
return myDescriptionFolder;
}
public String getDescriptionFolder() {
return myDescriptionFolder;
}

public boolean isFixedDescriptionFilename() {
return myFixedDescriptionFilename;
}
public boolean isFixedDescriptionFilename() {
return myFixedDescriptionFilename;
}

@Nullable
public PsiClass findClass(@Nonnull Project project, @Nonnull GlobalSearchScope scope) {
JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
for (String className : myClassNames) {
PsiClass aClass = psiFacade.findClass(className, scope);
if (aClass != null) {
return aClass;
}
@Nullable
public PsiClass findClass(@Nonnull Project project, @Nonnull GlobalSearchScope scope) {
JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
for (String className : myClassNames) {
PsiClass aClass = psiFacade.findClass(className, scope);
if (aClass != null) {
return aClass;
}
}
return null;
}
return null;
}

public boolean isInheritor(PsiClass psiClass) {
for (String className : myClassNames) {
if (InheritanceUtil.isInheritor(psiClass, className)) {
return true;
}
public boolean isInheritor(PsiClass psiClass) {
for (String className : myClassNames) {
if (InheritanceUtil.isInheritor(psiClass, className)) {
return true;
}
}
return false;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,28 @@
*/
@ExtensionImpl
public class DevKitEntryPoints implements ImplicitUsageProvider {
private static final String domClassName = DomElement.class.getName();
private static final String domClassName = DomElement.class.getName();

@Override
public boolean isImplicitUsage(PsiElement element) {
if (element instanceof PsiClass psiClass) {
if (InheritanceUtil.isInheritor(psiClass, domClassName)) {
return true;
}
}

if (element instanceof PsiField || element instanceof PsiMethod || element instanceof PsiClass) {
return AnnotationUtil.isAnnotated((PsiModifierListOwner)element, UsedInPlugin.class.getName(), 0);
@Override
public boolean isImplicitUsage(PsiElement element) {
if (element instanceof PsiClass psiClass && InheritanceUtil.isInheritor(psiClass, domClassName)) {
return true;
}

//noinspection SimplifiableIfStatement
if (element instanceof PsiField || element instanceof PsiMethod || element instanceof PsiClass) {
return AnnotationUtil.isAnnotated((PsiModifierListOwner)element, UsedInPlugin.class.getName(), 0);
}
return false;
}
return false;
}

@Override
public boolean isImplicitRead(PsiElement element) {
return false;
}
@Override
public boolean isImplicitRead(PsiElement element) {
return false;
}

@Override
public boolean isImplicitWrite(PsiElement element) {
return false;
}
@Override
public boolean isImplicitWrite(PsiElement element) {
return false;
}
}
Loading
Loading