use of com.intellij.psi.PsiIdentifier in project Main by SpartanRefactoring.
the class UtilsTest method testGetAllReferences.
public void testGetAllReferences() throws Exception {
PsiMethod m = createTestMethodFromString("int foo() { int x = 0; x++; x--; return x;}");
PsiIdentifier id = createTestIdentifierFromString("x");
assertEquals(Utils.getAllReferences(m, id).size(), 4);
id = createTestIdentifierFromString("id");
PsiIdentifier nonExistent = createTestIdentifierFromString("banana");
String m1String = "void foo(){ int k=5; }";
PsiMethod m1 = createTestMethodFromString(m1String);
String m2String = "int id() { int id=7; return 8;}";
PsiMethod m2 = createTestMethodFromString(m2String);
String m3String = "int id() { int id=7; return id;}";
PsiMethod m3 = createTestMethodFromString(m3String);
assert Utils.getAllReferences(null, null).isEmpty();
assert Utils.getAllReferences(null, id).isEmpty();
assert Utils.getAllReferences(m1, id).isEmpty();
assert Utils.getAllReferences(m2, id).size() == 1;
assert Utils.getAllReferences(m2, nonExistent).isEmpty();
assert Utils.getAllReferences(m3, id).size() == 2;
}
use of com.intellij.psi.PsiIdentifier in project intellij-community by JetBrains.
the class ClassIndependentOfModuleInspection method checkElement.
@Nullable
@Override
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext) {
if (!(refEntity instanceof RefClass)) {
return null;
}
final RefClass refClass = (RefClass) refEntity;
final RefEntity owner = refClass.getOwner();
if (!(owner instanceof RefPackage)) {
return null;
}
final Set<RefClass> dependencies = DependencyUtils.calculateDependenciesForClass(refClass);
for (RefClass dependency : dependencies) {
if (inSameModule(refClass, dependency)) {
return null;
}
}
final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
for (RefClass dependent : dependents) {
if (inSameModule(refClass, dependent)) {
return null;
}
}
final PsiClass aClass = refClass.getElement();
final PsiIdentifier identifier = aClass.getNameIdentifier();
if (identifier == null) {
return null;
}
return new CommonProblemDescriptor[] { manager.createProblemDescriptor(identifier, InspectionGadgetsBundle.message("class.independent.of.module.problem.descriptor"), true, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
use of com.intellij.psi.PsiIdentifier in project intellij-community by JetBrains.
the class ClassUnconnectedToPackageInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalInspectionContext) {
if (!(refEntity instanceof RefClass)) {
return null;
}
final RefClass refClass = (RefClass) refEntity;
final RefEntity owner = refClass.getOwner();
if (!(owner instanceof RefPackage)) {
return null;
}
final Set<RefClass> dependencies = DependencyUtils.calculateDependenciesForClass(refClass);
for (RefClass dependency : dependencies) {
if (inSamePackage(refClass, dependency)) {
return null;
}
}
final Set<RefClass> dependents = DependencyUtils.calculateDependentsForClass(refClass);
for (RefClass dependent : dependents) {
if (inSamePackage(refClass, dependent)) {
return null;
}
}
final PsiClass aClass = refClass.getElement();
final PsiIdentifier identifier = aClass.getNameIdentifier();
if (identifier == null) {
return null;
}
return new CommonProblemDescriptor[] { manager.createProblemDescriptor(identifier, InspectionGadgetsBundle.message("class.unconnected.to.package.problem.descriptor"), true, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) };
}
use of com.intellij.psi.PsiIdentifier in project intellij-community by JetBrains.
the class RegisterExtensionFixProvider method getQuickFixes.
@NotNull
@Override
public IntentionAction[] getQuickFixes(@NotNull PsiElement element) {
if (!(element instanceof PsiIdentifier))
return IntentionAction.EMPTY_ARRAY;
PsiElement parent = element.getParent();
if (!(parent instanceof PsiClass))
return IntentionAction.EMPTY_ARRAY;
PsiClass psiClass = (PsiClass) parent;
if (InheritanceUtil.isInheritor(psiClass, LocalInspectionTool.class.getName())) {
return new IntentionAction[] { new RegisterInspectionFix(psiClass, LocalInspectionEP.LOCAL_INSPECTION) };
}
if (InheritanceUtil.isInheritor(psiClass, GlobalInspectionTool.class.getName())) {
return new IntentionAction[] { new RegisterInspectionFix(psiClass, InspectionEP.GLOBAL_INSPECTION) };
}
ExtensionPointLocator extensionPointLocator = new ExtensionPointLocator(psiClass);
List<ExtensionPointCandidate> candidateList = extensionPointLocator.findSuperCandidates();
if (!candidateList.isEmpty()) {
return new IntentionAction[] { new RegisterExtensionFix(psiClass, candidateList) };
}
return IntentionAction.EMPTY_ARRAY;
}
use of com.intellij.psi.PsiIdentifier in project android by JetBrains.
the class ParcelableQuickFixTest method testIsApplicable.
public void testIsApplicable() throws Exception {
ParcelableQuickFix fix = new ParcelableQuickFix("Fix Parcelable", IMPLEMENT);
PsiFile file = myFixture.addFileToProject("src/com/example/Simple.java", SIMPLE_SOURCE);
PsiIdentifier identifier = findClassIdentifier(file, "Simple");
assertTrue(fix.isApplicable(identifier, identifier, AndroidQuickfixContexts.DesignerContext.TYPE));
file = myFixture.addFileToProject("src/com/expected/Simple.java", SIMPLE_EXPECTED);
identifier = findClassIdentifier(file, "Simple");
assertFalse(fix.isApplicable(identifier, identifier, AndroidQuickfixContexts.DesignerContext.TYPE));
}
Aggregations