use of com.intellij.psi.PsiEnumConstant in project intellij-community by JetBrains.
the class GroovyEditorTextProvider method getEditorText.
@Override
public TextWithImports getEditorText(PsiElement elementAtCaret) {
String result = "";
PsiElement element = findExpressionInner(elementAtCaret, true);
if (element != null) {
if (element instanceof GrReferenceExpression) {
final GrReferenceExpression reference = (GrReferenceExpression) element;
if (reference.getQualifier() == null) {
final PsiElement resolved = reference.resolve();
if (resolved instanceof PsiEnumConstant) {
final PsiEnumConstant enumConstant = (PsiEnumConstant) resolved;
final PsiClass enumClass = enumConstant.getContainingClass();
if (enumClass != null) {
result = enumClass.getName() + "." + enumConstant.getName();
}
}
}
}
if (result.isEmpty()) {
result = element.getText();
}
}
return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, result);
}
use of com.intellij.psi.PsiEnumConstant in project intellij-community by JetBrains.
the class FormEnumUsageTest method testEnumUsage.
public void testEnumUsage() throws IncorrectOperationException {
LanguageLevelProjectExtension.getInstance(myJavaFacade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
CommandProcessor.getInstance().executeCommand(myProject, () -> {
try {
createFile(myModule, myTestProjectRoot, "PropEnum.java", "public enum PropEnum { valueA, valueB }");
createFile(myModule, myTestProjectRoot, "CustomComponent.java", "public class CustomComponent extends JLabel { private PropEnum e; public PropEnum getE() { return e; } public void setE(E newE) { e = newE; } }");
} catch (Exception e) {
fail(e.getMessage());
}
}, "", null);
PsiClass enumClass = myJavaFacade.findClass("PropEnum", ProjectScope.getAllScope(myProject));
PsiField valueBField = enumClass.findFieldByName("valueB", false);
assertNotNull(valueBField);
assertTrue(valueBField instanceof PsiEnumConstant);
final PsiClass componentClass = myJavaFacade.findClass("CustomComponent", ProjectScope.getAllScope(myProject));
assertNotNull(componentClass);
assertEquals(1, ReferencesSearch.search(componentClass).findAll().size());
assertEquals(1, ReferencesSearch.search(valueBField).findAll().size());
}
use of com.intellij.psi.PsiEnumConstant in project kotlin by JetBrains.
the class KtEnumEntry method isEquivalentTo.
@Override
public boolean isEquivalentTo(@Nullable PsiElement another) {
if (another instanceof PsiEnumConstant) {
PsiEnumConstant enumConstant = (PsiEnumConstant) another;
PsiClass containingClass = enumConstant.getContainingClass();
if (containingClass != null) {
String containingClassQName = containingClass.getQualifiedName();
if (containingClassQName != null && enumConstant.getName() != null) {
String theirFQName = containingClassQName + "." + enumConstant.getName();
if (theirFQName.equals(getQualifiedName())) {
return true;
}
}
}
}
return super.isEquivalentTo(another);
}
use of com.intellij.psi.PsiEnumConstant in project intellij-community by JetBrains.
the class ImplementMethodsFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") final Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
final PsiElement myPsiElement = startElement;
if (editor == null || !FileModificationService.getInstance().prepareFileForWrite(myPsiElement.getContainingFile()))
return;
if (myPsiElement instanceof PsiEnumConstant) {
final boolean hasClassInitializer = ((PsiEnumConstant) myPsiElement).getInitializingClass() != null;
final MemberChooser<PsiMethodMember> chooser = chooseMethodsToImplement(editor, startElement, ((PsiEnumConstant) myPsiElement).getContainingClass(), hasClassInitializer);
if (chooser == null)
return;
final List<PsiMethodMember> selectedElements = chooser.getSelectedElements();
if (selectedElements == null || selectedElements.isEmpty())
return;
new WriteCommandAction(project, file) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
final PsiClass psiClass = ((PsiEnumConstant) myPsiElement).getOrCreateInitializingClass();
OverrideImplementUtil.overrideOrImplementMethodsInRightPlace(editor, psiClass, selectedElements, chooser.isCopyJavadoc(), chooser.isInsertOverrideAnnotation());
}
}.execute();
} else {
OverrideImplementUtil.chooseAndImplementMethods(project, editor, (PsiClass) myPsiElement);
}
}
use of com.intellij.psi.PsiEnumConstant in project intellij-community by JetBrains.
the class EnumFieldFixer method apply.
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
if (psiElement instanceof PsiEnumConstant) {
int insertionOffset = psiElement.getTextRange().getEndOffset();
Document doc = editor.getDocument();
final CharSequence text = doc.getCharsSequence();
final int probableCommaOffset = CharArrayUtil.shiftForward(text, insertionOffset, " \t");
if (probableCommaOffset >= text.length() || text.charAt(probableCommaOffset) != ',') {
doc.insertString(insertionOffset, ",");
}
}
}
Aggregations