当前位置: 首页>>代码示例>>Java>>正文


Java PsiEnumConstant类代码示例

本文整理汇总了Java中com.intellij.psi.PsiEnumConstant的典型用法代码示例。如果您正苦于以下问题:Java PsiEnumConstant类的具体用法?Java PsiEnumConstant怎么用?Java PsiEnumConstant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PsiEnumConstant类属于com.intellij.psi包,在下文中一共展示了PsiEnumConstant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitField

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@Override
public void visitField(@NotNull PsiField field) {
  super.visitField(field);
  if (field instanceof PsiEnumConstant) {
    return;
  }
  if (!field.hasModifierProperty(PsiModifier.STATIC) || !field.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  final String name = field.getName();
  if (name == null) {
    return;
  }
  final PsiType type = field.getType();
  if (onlyCheckImmutables && !ClassUtils.isImmutable(type)) {
    return;
  }
  if (isValid(name)) {
    return;
  }
  registerFieldError(field, name);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ConstantNamingConventionInspectionBase.java

示例2: getEditorText

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:GroovyEditorTextProvider.java

示例3: getEditorText

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@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.length() == 0) {
      result = element.getText();
    }
  }
  return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, result);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:GroovyEditorTextProvider.java

示例4: fun

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@Override
@NotNull
public Collection<EncapsulatableClassMember> fun(PsiClass s)
{
	if(s.getLanguage() != JavaLanguage.INSTANCE)
	{
		return Collections.emptyList();
	}
	final List<EncapsulatableClassMember> result = new ArrayList<EncapsulatableClassMember>();
	for(PsiField field : s.getFields())
	{
		if(!(field instanceof PsiEnumConstant))
		{
			result.add(new PsiFieldMember(field));
		}
	}
	return result;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:GenerateGetterSetterHandlerBase.java

示例5: testEnumConstructor

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
public void testEnumConstructor() throws Exception {
  PsiClass enumClass = myJavaFacade.findClass("pack.OurEnum", GlobalSearchScope.moduleScope(myModule));
  assertNotNull(enumClass);
  assertTrue(enumClass.isEnum());
  PsiMethod[] constructors = enumClass.getConstructors();
  assertEquals(2, constructors.length);
  PsiReference[] references0 =
    ReferencesSearch.search(constructors[0], GlobalSearchScope.moduleScope(myModule), false).toArray(new PsiReference[0]);
  assertEquals(2, references0.length);
  assertTrue(references0[0].getElement() instanceof PsiEnumConstant);
  assertTrue(references0[1].getElement() instanceof PsiEnumConstant);
  PsiReference[] references1 =
    ReferencesSearch.search(constructors[1], GlobalSearchScope.moduleScope(myModule), false).toArray(new PsiReference[0]);
  assertEquals(1, references1.length);
  assertTrue(references1[0].getElement() instanceof PsiEnumConstant);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:FindUsages15Test.java

示例6: isFieldMissingNullAnnotation

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
private boolean isFieldMissingNullAnnotation(PsiField field, PsiType type) {
    return reportFields
            && field.isPhysical()
            && !(field instanceof PsiEnumConstant)
            && !TypeConversionUtil.isPrimitiveAndNotNull(type)
            && shouldCheckField(field)
            && !hasAnnotation(field);
}
 
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:9,代码来源:NullabilityAnnotationsInspection.java

示例7: resolveCompletions

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@Override
public Stream<LookupElementBuilder> resolveCompletions(String propertyName, PsiType psiType) {
    PsiClass resolved = ((PsiClassReferenceType) psiType).resolve();
    if (resolved != null) {
        return Arrays.stream(resolved.getChildren())
                .filter(child -> child instanceof PsiEnumConstant)
                .map(child -> buildEnumLookup((PsiEnumConstant) child))
                .filter(Optional::isPresent)
                .map(Optional::get);
    }
    return Stream.empty();
}
 
开发者ID:seedstack,项目名称:intellij-plugin,代码行数:13,代码来源:EnumCompletionResolver.java

示例8: fun

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@Override
@NotNull
public Collection<EncapsulatableClassMember> fun(PsiClass s) {
  if (s.getLanguage() != StdLanguages.JAVA) return Collections.emptyList();
  final List<EncapsulatableClassMember> result = new ArrayList<EncapsulatableClassMember>();
  for (PsiField field : s.getFields()) {
    if (!(field instanceof PsiEnumConstant)) {
      result.add(new PsiFieldMember(field));
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:GenerateGetterSetterHandlerBase.java

示例9: invoke

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@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);
  }

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:ImplementMethodsFix.java

示例10: apply

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@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, ",");
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:EnumFieldFixer.java

示例11: testEnumUsage

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
public void testEnumUsage() throws IncorrectOperationException {
  LanguageLevelProjectExtension.getInstance(myJavaFacade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:FormEnumUsageTest.java

示例12: visitEnumConstant

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@Override
public void visitEnumConstant(PsiEnumConstant constant) {
  super.visitEnumConstant(constant);
  final String name = constant.getName();
  if (name == null) {
    return;
  }
  if (isValid(name)) {
    return;
  }
  registerFieldError(constant, name);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:EnumeratedConstantNamingConventionInspectionBase.java

示例13: countFields

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
private int countFields(PsiClass aClass) {
  int totalFields = 0;
  final PsiField[] fields = aClass.getFields();
  for (final PsiField field : fields) {
    if (field instanceof PsiEnumConstant) {
      if (myCountEnumConstants) {
        totalFields++;
      }
    }
    else if (m_countConstantFields || !fieldIsConstant(field)) {
      totalFields++;
    }
  }
  return totalFields;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:FieldCountInspection.java

示例14: fun

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@Override
@NotNull
public Collection<EncapsulatableClassMember> fun(PsiClass s) {
  if (!(s instanceof GrTypeDefinition)) return Collections.emptyList();
  final List<EncapsulatableClassMember> result = new ArrayList<EncapsulatableClassMember>();
  for (PsiField field : s.getFields()) {
    if (!(field instanceof PsiEnumConstant) && field instanceof GrField) {
      result.add(new GrFieldMember((GrField)field));
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:GroovyGenerateGetterSetterAction.java

示例15: fun

import com.intellij.psi.PsiEnumConstant; //导入依赖的package包/类
@NotNull
public Collection<EncapsulatableClassMember> fun(PsiClass s) {
  if (!(s instanceof GrTypeDefinition)) return Collections.emptyList();
  final List<EncapsulatableClassMember> result = new ArrayList<EncapsulatableClassMember>();
  for (PsiField field : s.getFields()) {
    if (!(field instanceof PsiEnumConstant) && field instanceof GrField) {
      result.add(new GrFieldMember((GrField)field));
    }
  }
  return result;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:12,代码来源:GroovyGenerateGetterSetterAction.java


注:本文中的com.intellij.psi.PsiEnumConstant类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。