本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
}
示例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, ",");
}
}
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}