Skip to content
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
@@ -1,19 +1,21 @@
package com.siberika.idea.pascal.editor.structure;

import com.siberika.idea.pascal.PascalIcons;
import com.siberika.idea.pascal.lang.psi.PasModule;
import consulo.annotation.access.RequiredReadAction;
import consulo.fileEditor.structureView.StructureViewTreeElement;
import consulo.language.editor.structureView.PsiTreeElementBase;
import consulo.localize.LocalizeValue;
import consulo.object.pascal.icon.ObjectPascalIconGroup;
import consulo.ui.image.Image;
import consulo.util.lang.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

import java.util.Collection;

/**
* Author: George Bakhtadze
* Date: 06/05/2015
* @author George Bakhtadze
* @since 2015-05-06
*/
public class PasModuleStructureTreeElement extends PsiTreeElementBase<PasModule> {
protected PasModuleStructureTreeElement(PasModule psiElement) {
Expand All @@ -22,33 +24,31 @@ protected PasModuleStructureTreeElement(PasModule psiElement) {

@NotNull
@Override
@RequiredReadAction
public Collection<StructureViewTreeElement> getChildrenBase() {
return PasStructureViewTreeElement.collectChildren(getElement());
}

@Override
public Image getIcon() {
@RequiredReadAction
public @Nullable Image getIcon() {
if (getElement() != null) {
switch (getElement().getModuleType()) {
case PACKAGE:
case LIBRARY:
return PascalIcons.FILE_LIBRARY;
case PROGRAM:
return PascalIcons.FILE_PROGRAM;
case UNIT:
return PascalIcons.UNIT;
}
return switch (getElement().getModuleType()) {
case PACKAGE, LIBRARY -> ObjectPascalIconGroup.library();
case PROGRAM -> ObjectPascalIconGroup.program();
case UNIT -> ObjectPascalIconGroup.unit();
};
}
return null;
}

@Nullable
@Override
public String getPresentableText() {
@RequiredReadAction
public LocalizeValue getPresentableText() {
String name = getElement() != null ? getElement().getName() : "-";
if (StringUtil.isEmpty(name)) {
name = getElement().getContainingFile().getName();
}
return name;
return LocalizeValue.of(name);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.siberika.idea.pascal.editor.structure;

import com.siberika.idea.pascal.PascalIcons;
import com.siberika.idea.pascal.lang.psi.*;
import com.siberika.idea.pascal.lang.psi.impl.PasField;
import com.siberika.idea.pascal.util.PsiUtil;
import consulo.annotation.access.RequiredReadAction;
import consulo.fileEditor.structureView.StructureViewTreeElement;
import consulo.language.editor.structureView.PsiTreeElementBase;
import consulo.localize.LocalizeValue;
import consulo.object.pascal.icon.ObjectPascalIconGroup;
import consulo.platform.base.icon.PlatformIconGroup;
import consulo.ui.image.Image;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

/**
* Author: George Bakhtadze
* Date: 06/05/2015
* @author George Bakhtadze
* @since 2015-05-06
*/
public class PasStructStructureTreeElement extends PsiTreeElementBase<PascalStructType> {
protected PasStructStructureTreeElement(PascalStructType psiElement) {
Expand All @@ -23,49 +25,49 @@ protected PasStructStructureTreeElement(PascalStructType psiElement) {

@NotNull
@Override
@RequiredReadAction
public Collection<StructureViewTreeElement> getChildrenBase() {
return PasStructureViewTreeElement.collectChildren(getElement());
}

@Override
@RequiredReadAction
public Image getIcon() {
if (getElement() != null) {
PascalStructType el = getElement();
if (el instanceof PasInterfaceTypeDecl) {
return PascalIcons.INTERFACE;
} else if (el instanceof PasClassTypeDecl) {
return PascalIcons.CLASS;
} else if (el instanceof PasObjectDecl) {
return PascalIcons.OBJECT;
} else if (el instanceof PasRecordDecl) {
return PascalIcons.RECORD;
} else if ((el instanceof PasClassHelperDecl) || (el instanceof PasRecordHelperDecl)) {
return PascalIcons.HELPER;
}
}
return null;
return switch (getElement()) {
case PasInterfaceTypeDecl _ -> PlatformIconGroup.nodesInterface();
case PasClassTypeDecl _ -> PlatformIconGroup.nodesClass();
case PasObjectDecl _ -> PlatformIconGroup.nodesAnonymousclass();
case PasRecordDecl _ -> PlatformIconGroup.nodesRecord();
case PasClassHelperDecl _, PasRecordHelperDecl _ -> ObjectPascalIconGroup.helper();
case null, default -> null;
};
}

@Nullable
@Override
public String getPresentableText() {
return getElement() != null ? getElement().getName() : "-";
@RequiredReadAction
public LocalizeValue getPresentableText() {
return getElement() != null ? LocalizeValue.of(getElement().getName()) : LocalizeValue.localizeTODO("-");
}

public static PascalStructType getStructElement(PasField field) {
PasTypeDecl typeDecl = PsiUtil.getTypeDeclaration(field.getElement());
if (typeDecl != null) {
if (typeDecl.getInterfaceTypeDecl() != null) {
return typeDecl.getInterfaceTypeDecl();
} if (typeDecl.getClassTypeDecl() != null) {
}
if (typeDecl.getClassTypeDecl() != null) {
return typeDecl.getClassTypeDecl();
} if (typeDecl.getObjectDecl() != null) {
}
if (typeDecl.getObjectDecl() != null) {
return typeDecl.getObjectDecl();
} if (typeDecl.getRecordDecl() != null) {
}
if (typeDecl.getRecordDecl() != null) {
return typeDecl.getRecordDecl();
} if (typeDecl.getClassHelperDecl() != null) {
}
if (typeDecl.getClassHelperDecl() != null) {
return typeDecl.getClassHelperDecl();
} if (typeDecl.getRecordHelperDecl() != null) {
}
if (typeDecl.getRecordHelperDecl() != null) {
return typeDecl.getRecordHelperDecl();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.siberika.idea.pascal.editor.structure;

import com.siberika.idea.pascal.PascalIcons;
import com.siberika.idea.pascal.lang.psi.PasEntityScope;
import com.siberika.idea.pascal.lang.psi.PascalNamedElement;
import com.siberika.idea.pascal.lang.psi.PascalStructType;
import com.siberika.idea.pascal.lang.psi.impl.PasField;
import com.siberika.idea.pascal.util.PsiUtil;
import consulo.annotation.access.RequiredReadAction;
import consulo.fileEditor.structureView.StructureViewTreeElement;
import consulo.language.editor.structureView.PsiTreeElementBase;
import consulo.language.psi.PsiElement;
import consulo.language.psi.PsiFile;
import consulo.localize.LocalizeValue;
import consulo.platform.base.icon.PlatformIconGroup;
import consulo.ui.image.Image;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -19,11 +21,12 @@
import java.util.Collections;

/**
* Author: George Bakhtadze
* Date: 16/09/2013
* @author George Bakhtadze
* @since 2013-09-16
*/
public class PasStructureViewTreeElement extends PsiTreeElementBase<PsiElement> implements StructureViewTreeElement {
private final PasField field;

protected PasStructureViewTreeElement(PsiElement psiElement, PasField field) {
super(field != null ? field.getElement() : psiElement);
this.field = field;
Expand All @@ -48,10 +51,12 @@ public static Collection<StructureViewTreeElement> collectChildren(@Nullable Pas
PascalStructType structType = PasStructStructureTreeElement.getStructElement(field);
if (structType != null) {
res.add(new PasStructStructureTreeElement(structType));
} else {
}
else {
res.add(new PasStructureViewTreeElement(field.getElement(), field));
}
} else {
}
else {
res.add(new PasStructureViewTreeElement(field.getElement(), field));
}
}
Expand All @@ -64,34 +69,35 @@ public PasField getField() {
}

@Override
@RequiredReadAction
public Image getIcon() {
if (field != null) {
if (field.fieldType == PasField.FieldType.VARIABLE) {
return PascalIcons.VARIABLE;
} else if (field.fieldType == PasField.FieldType.CONSTANT) {
return PascalIcons.CONSTANT;
} else if (field.fieldType == PasField.FieldType.TYPE) {
return PascalIcons.TYPE;
} else if (field.fieldType == PasField.FieldType.PROPERTY) {
return PascalIcons.PROPERTY;
} else if (field.fieldType == PasField.FieldType.ROUTINE) {
return PascalIcons.ROUTINE;
return PlatformIconGroup.nodesVariable();
}
else if (field.fieldType == PasField.FieldType.CONSTANT) {
return PlatformIconGroup.nodesConstant();
}
else if (field.fieldType == PasField.FieldType.TYPE) {
return PlatformIconGroup.nodesType();
}
else if (field.fieldType == PasField.FieldType.PROPERTY) {
return PlatformIconGroup.nodesProperty();
}
else if (field.fieldType == PasField.FieldType.ROUTINE) {
return PlatformIconGroup.nodesFunction();
}
}
return super.getIcon();
}

@Nullable
@Override
public String getPresentableText() {
PsiElement element = getElement();
if (element instanceof PascalNamedElement) {
return PsiUtil.getFieldName((PascalNamedElement) element);
} else if (element instanceof PsiFile) {
return ((PsiFile) element).getName();
} else {
return "-";
}
@RequiredReadAction
public LocalizeValue getPresentableText() {
return switch (getElement()) {
case PascalNamedElement namedElem -> LocalizeValue.of(PsiUtil.getFieldName(namedElem));
case PsiFile file -> LocalizeValue.of(file.getName());
case null, default -> LocalizeValue.localizeTODO("-");
};
}

}
Loading
Loading