use of com.intellij.psi.PsiClass 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.PsiClass in project kotlin by JetBrains.
the class LightClassAnnotationsTest method doTest.
private void doTest(@NotNull String fqName) {
PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject()));
if (!(psiClass instanceof KtLightClass)) {
throw new IllegalStateException("Not a light class: " + psiClass + " (" + fqName + ")");
}
PsiModifierList modifierList = psiClass.getModifierList();
assert modifierList != null : "No modifier list for " + psiClass.getText();
StringBuilder sb = new StringBuilder();
for (PsiAnnotation annotation : modifierList.getAnnotations()) {
sb.append(annotation.getText()).append("\n");
}
KotlinTestUtils.assertEqualsToFile(new File(testDir, getTestName(false) + ".annotations.txt"), sb.toString());
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class ConvertSimpleGetterToPropertyIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
GrMethod method = (GrMethod) element.getParent();
GrOpenBlock block = method.getBlock();
if (block == null)
return;
GrStatement statement = block.getStatements()[0];
GrExpression value;
if (statement instanceof GrReturnStatement) {
value = ((GrReturnStatement) statement).getReturnValue();
} else {
value = (GrExpression) statement;
}
String fieldName = GroovyPropertyUtils.getPropertyNameByGetter(method);
if (fieldName == null)
return;
PsiClass aClass = method.getContainingClass();
if (aClass == null)
return;
List<String> modifiers = ContainerUtil.newArrayList();
for (String modifier : MODIFIERS_TO_CHECK) {
if (method.hasModifierProperty(modifier))
modifiers.add(modifier);
}
modifiers.add(PsiModifier.FINAL);
GrTypeElement returnTypeElement = method.getReturnTypeElementGroovy();
PsiType returnType = returnTypeElement == null ? null : returnTypeElement.getType();
GrVariableDeclaration declaration = GroovyPsiElementFactory.getInstance(project).createFieldDeclaration(ArrayUtil.toStringArray(modifiers), fieldName, value, returnType);
PsiElement replaced = method.replace(declaration);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(replaced);
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class ConvertJunitAssertionToAssertStatementIntention method getReplacementStatement.
@Nullable
private static String getReplacementStatement(@NotNull PsiMethod method, @NotNull GrMethodCall methodCall) {
PsiClass containingClass = method.getContainingClass();
if (containingClass == null)
return null;
String qualifiedName = containingClass.getQualifiedName();
if (!"junit.framework.Assert".equals(qualifiedName) && !"groovy.util.GroovyTestCase".equals(qualifiedName))
return null;
String[] replacementStatements = ourStatementMap.get(method.getName());
if (replacementStatements == null)
return null;
GrArgumentList argumentList = methodCall.getArgumentList();
if (argumentList.getNamedArguments().length > 0)
return null;
GrExpression[] arguments = argumentList.getExpressionArguments();
if (arguments.length >= replacementStatements.length)
return null;
return replacementStatements[arguments.length];
}
use of com.intellij.psi.PsiClass 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);
}
Aggregations