Skip to content

Commit

Permalink
Misc tweaks to abstract type and icons
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed May 14, 2024
1 parent 0fb5791 commit d773f97
Show file tree
Hide file tree
Showing 18 changed files with 246 additions and 18 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/intellij/plugins/haxe/HaxeComponentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ public Icon getIcon() {
}
}, MODULE(11) {
public Icon getIcon() {
return HaxeIcons.MultiDefinition;
return HaxeIcons.Module;
}
}, ABSTRACT(12) {
public Icon getIcon() {
return HaxeIcons.Abstract;
}
};

Expand Down Expand Up @@ -149,17 +153,23 @@ public static HaxeComponentType valueOf(int key) {
return CLASSVARIABLE;
case 10:
return TYPE_PARAMETER;
case 11:
return MODULE;
case 12:
return ABSTRACT;
}
return null;
}

@Nullable
public static HaxeComponentType typeOf(PsiElement element) {
if (element instanceof HaxeClassDeclaration ||
element instanceof HaxeExternClassDeclaration ||
element instanceof HaxeAbstractTypeDeclaration) {
element instanceof HaxeExternClassDeclaration) {
return CLASS;
}
if (element instanceof HaxeAbstractTypeDeclaration) {
return ABSTRACT;
}
if (element instanceof HaxeEnumDeclaration) {
return ENUM;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String getQuickNavigateInfo(PsiElement element, PsiElement originalElemen
if (namedComponent != null) {
if (type == null) return mainBuilder.toString();
switch (type) {
case CLASS, INTERFACE, TYPEDEF, ENUM -> processType(mainBuilder, namedComponent, renderer);
case CLASS, ABSTRACT, INTERFACE, TYPEDEF, ENUM -> processType(mainBuilder, namedComponent, renderer);
case METHOD, FUNCTION -> processMethod(mainBuilder, namedComponent, renderer);
case FIELD -> processField(mainBuilder, namedComponent, renderer);
case VARIABLE -> processVariable(mainBuilder, namedComponent, renderer);
Expand Down Expand Up @@ -109,7 +109,7 @@ public String generateDoc(PsiElement element, PsiElement originalElement) {
//TODO support key-value iterator "vars"
if (type == null) return mainBuilder.toString();
switch (type) {
case CLASS, INTERFACE, TYPEDEF, ENUM -> processType(definitionBuilder, namedComponent, renderer);
case CLASS, ABSTRACT, INTERFACE, TYPEDEF, ENUM -> processType(definitionBuilder, namedComponent, renderer);
case METHOD, FUNCTION -> processMethod(definitionBuilder, namedComponent, renderer);
case FIELD -> processField(definitionBuilder, namedComponent, renderer);
case VARIABLE -> processVariable(definitionBuilder, namedComponent, renderer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.intellij.psi.PsiElement;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import icons.HaxeIcons;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
Expand Down Expand Up @@ -66,15 +67,22 @@ public static String getTemplateShortName(String templateName) {
public static Icon getTemplateIcon(String name) {
name = getTemplateShortName(name);
if ("Class".equals(name)) {
return icons.HaxeIcons.Class;
return HaxeIcons.Class;
}
else if ("Interface".equals(name)) {
return icons.HaxeIcons.Interface;
return HaxeIcons.Interface;
}
else if ("Enum".equals(name)) {
return icons.HaxeIcons.Enum;
return HaxeIcons.Enum;
}
return icons.HaxeIcons.HAXE_LOGO;
else if ("Abstract".equals(name)) {
return HaxeIcons.Abstract;
}
else if ("Module".equals(name)) {
return HaxeIcons.Module;
}

return HaxeIcons.HAXE_LOGO;
}

public static PsiElement createClass(String className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static Icon getHaxeFileIcon(HaxeFile file, @Iconable.IconFlags int flags
}
}
if (!declarations.isEmpty()) {
return HaxeIcons.MultiDefinition;
return HaxeIcons.Module;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static TextAttributesKey getAttributeByType(@Nullable HaxeComponentType t
}
return switch (type) {
case TYPE_PARAMETER -> TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_TYPE_PARAMETER);
case CLASS, ENUM, TYPEDEF -> TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_CLASS);
case CLASS, ABSTRACT, ENUM, TYPEDEF -> TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_CLASS);
case INTERFACE -> TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_INTERFACE);
case PARAMETER -> TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_PARAMETER);
case VARIABLE -> TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_LOCAL_VARIABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ private static void checkAbstractMethods(HaxeClassModel clazz, HaxeClassReferenc



List<HaxeMethod> allMethodList = clazz.haxeClass.getHaxeMethodsAll(HaxeComponentType.CLASS, HaxeComponentType.INTERFACE);
Set<HaxeMethod> extendedClassMethodList = new HashSet<>(abstractClass.getHaxeClassModel().haxeClass.getHaxeMethodsAll(HaxeComponentType.CLASS, HaxeComponentType.INTERFACE));
List<HaxeMethod> allMethodList = clazz.haxeClass.getHaxeMethodsAll(HaxeComponentType.CLASS, HaxeComponentType.ABSTRACT, HaxeComponentType.INTERFACE);
Set<HaxeMethod> extendedClassMethodList = new HashSet<>(abstractClass.getHaxeClassModel().haxeClass.getHaxeMethodsAll(HaxeComponentType.CLASS, HaxeComponentType.ABSTRACT, HaxeComponentType.INTERFACE));

Map<String, HaxeMethodModel> abstractMethods = extendedClassMethodList.stream()
.map(HaxeMethodPsiMixin::getModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ public List<HaxeFieldDeclaration> getFieldSelf(@Nullable HaxeGenericResolver res
@Override
public HaxeNamedComponent findHaxeFieldByName(@NotNull final String name, @Nullable HaxeGenericResolver resolver) {
//TODO: debug line remove
List<HaxeNamedComponent> all = this.getHaxeFieldAll(HaxeComponentType.CLASS, HaxeComponentType.ENUM);
List<HaxeNamedComponent> all = this.getHaxeFieldAll(HaxeComponentType.CLASS, HaxeComponentType.ENUM, HaxeComponentType.ABSTRACT);

//List<HaxeNamedComponent> all = CachedValuesManager.getCachedValue(this, () -> AbstractHaxePsiClass.getHaxeFieldAllCached(this));
return ContainerUtil.find(all, component -> name.equals(component.getName()));
}

private static CachedValueProvider.Result<List<HaxeNamedComponent>> getHaxeFieldAllCached(@NotNull AbstractHaxePsiClass haxePsiClass) {
List<HaxeNamedComponent> all = haxePsiClass.getHaxeFieldAll(HaxeComponentType.CLASS, HaxeComponentType.ENUM);
List<HaxeNamedComponent> all = haxePsiClass.getHaxeFieldAll(HaxeComponentType.CLASS, HaxeComponentType.ENUM, HaxeComponentType.ABSTRACT);

List<PsiElement> dependencies = collectCacheDependencies(haxePsiClass);
return CachedValueProvider.Result.create(all, dependencies);
Expand Down Expand Up @@ -281,7 +281,7 @@ public HaxeNamedComponent findHaxeMethodByName(@NotNull final String name, @Null
}

private static CachedValueProvider.Result<List<HaxeMethod>> getHaxeMethodsAllCached(@NotNull AbstractHaxePsiClass haxePsiClass) {
List<HaxeMethod> all = haxePsiClass.getHaxeMethodsAll(HaxeComponentType.CLASS);
List<HaxeMethod> all = haxePsiClass.getHaxeMethodsAll(HaxeComponentType.CLASS, HaxeComponentType.ABSTRACT);

Collection<PsiElement> dependencies = collectCacheDependencies(haxePsiClass);
return CachedValueProvider.Result.create(all, dependencies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public static List<HaxeNamedComponent> getNamedSubComponents(HaxePsiCompositeEle
final HaxeComponentType type = HaxeComponentType.typeOf(element);
if (type == HaxeComponentType.MODULE) {
body = element;
} else if (type == HaxeComponentType.CLASS) {
} else if (type == HaxeComponentType.CLASS || type == HaxeComponentType.ABSTRACT) {
body = PsiTreeUtil.getChildOfAnyType(element, HaxeClassBody.class, HaxeExternClassDeclarationBody.class);
} else if (type == HaxeComponentType.INTERFACE) {
body = PsiTreeUtil.getChildOfType(element, HaxeInterfaceBody.class);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/icons/HaxeIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ private static Icon load(String path) {
public static final Icon Field = load("/icons/nodes/field.svg");
public static final Icon Parameter = load("/icons/nodes/parameter.svg");
public static final Icon Variable = load("/icons/nodes/variable.svg");
public static final Icon MultiDefinition = load("/icons/nodes/module.svg");
public static final Icon Module = load("/icons/nodes/module.svg");
public static final Icon Abstract = load("/icons/nodes/abstract.svg");

public static final Icon TYPEDEF_GUTTER = load("/icons/nodes/typedefGutter.svg");

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/HaxeIconMappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"expui": {
"nodes": {
"class.svg": "icons/nodes/class.svg",
"abstract.svg": "icons/nodes/abstract.svg",
"enum.svg": "icons/nodes/enum.svg",
"field.svg": "icons/nodes/field.svg",
"parameter.svg": "icons/nodes/parameter.svg",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@
<internalFileTemplate name="HaxeClass"/>
<internalFileTemplate name="HaxeInterface"/>
<internalFileTemplate name="HaxeEnum"/>
<internalFileTemplate name="HaxeAbstract"/>
<internalFileTemplate name="HaxeModule"/>
<internalFileTemplate name="NMMLProjectFile"/>

<liveTemplateMacro implementation="com.intellij.plugins.haxe.ide.template.macro.HaxeArrayVariableMacro"/>
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/fileTemplates/internal/HaxeAbstract.hx.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ${PACKAGE_NAME};
abstract ${NAME} {

}
1 change: 1 addition & 0 deletions src/main/resources/fileTemplates/internal/HaxeModule.hx.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package ${PACKAGE_NAME};
57 changes: 57 additions & 0 deletions src/main/resources/icons/expui/nodes/abstract.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions src/main/resources/icons/expui/nodes/abstract_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions src/main/resources/icons/nodes/abstract.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public void testReturnTypeGenerics() throws Exception {
public void testReturnTypeMacros() throws Exception {
doTest(hintsProvider);
}
@Test
public void testReturnTypeHints() throws Exception {
doTest(hintsProvider);
}


}
Loading

0 comments on commit d773f97

Please sign in to comment.