PSIFile.findElementAt(offset) returns HaxeFile(which extends PsiFileBase) instead of PsiElement instance

Hi,

I am maintaining Haxe plugin and I attempting to implement Refactoring->Pull up members... functionality

I took implementation from
https://github.com/JetBrains/intellij-community/blob/master/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHandler.java#L63

PsiFile.findElementAt(offset)
//returns HaxeFile(which extends PsiFileBase) instead of PsiElement instance 

https://github.com/JetBrains/intellij-haxe/blob/master/src/com/intellij/plugins/haxe/lang/psi/HaxeFile.java

Do I need to add some changes to HaxeFile class, for example implement processDeclaration method, like it's done in Dart plugin,
https://github.com/JetBrains/intellij-plugins/blob/master/Dart/src/com/jetbrains/lang/dart/psi/DartFile.java#L35

Thanks, sorry if this is common knowledge

Best regards,
Boyan

4 comments
Comment actions Permalink
//implementation for Java https://github.com/JetBrains/intellij-community/blob/master/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHandler.java

if (elements.length != 1) return;
    myProject = project;
    PsiElement element = elements[0];
    PsiClass aClass;
    PsiElement aMember = null;
    if (element instanceof PsiClass) {
      aClass = (PsiClass)element;
    }
    else if (element instanceof PsiMethod) {
      aClass = ((PsiMethod)element).getContainingClass();
      aMember = element;
    }
    else if (element instanceof PsiField) {
      aClass = ((PsiField)element).getContainingClass();
      aMember = element;
    }
    else {
      return;
    }


Mine, based on Java

if (elements.length != 1) return;
    myProject = project;
    PsiElement element = elements[0];
    PsiClass aClass;
    PsiElement aMember = null;
    if (element instanceof HaxeClassDeclaration) {
      aClass = (PsiClass)element;
    }
    else if (element instanceof HaxeFunctionDeclarationWithAttributes) {
      aClass = ((PsiMethod)element).getContainingClass();
      aMember = element;
    }
    else if (element instanceof HaxeVarDeclaration) {
      aClass = ((PsiField)element).getContainingClass();
      aMember = element;
    }
    else {
      return;
    }

Not sure about PsiField and other things...

0
Comment actions Permalink

So if I got it right, then

for Java, PsiClass, PsiField and PsiMethod are valid objects to work with, for Haxe it would be custom classes... like HaxeClassDeclaration, HaxeVarDeclaration and HaxeFunctionWithAttributesDeclaration If I got it right

0
Comment actions Permalink

PsiClass, PsiField and PsiMethod are historically bad class names, they come from early IntelliJ IDEA ages when it supported Java language only. You probably noticed that these classes are located in technology-specific module 'java-psi-api'. Better names would be JavaClass, JavaField and JavaMethod. In Haxe plugin you work with Haxe-specific PSI classes.
Classes like PsiFile, PsiElement, PsiNamedElement, etc. are in 'core-api' module, so they work for all languages.

0
Comment actions Permalink

Thanks for clearing this out

0

Please sign in to leave a comment.