use of com.intellij.psi.PsiClass in project buck by facebook.
the class BuckAutoDepsContributor method getVirtualFileFromClassname.
@Nullable
public VirtualFile getVirtualFileFromClassname(String classname) {
GlobalSearchScope scope = GlobalSearchScope.allScope(mProject);
PsiClass psiClass = JavaPsiFacade.getInstance(mProject).findClass(classname, scope);
if (psiClass == null) {
return null;
}
PsiFile psiFile = psiClass.getContainingFile();
if (psiFile == null) {
return null;
}
return psiFile.getVirtualFile();
}
use of com.intellij.psi.PsiClass in project buck by facebook.
the class BuckCopyPasteProcessor method referenceNameToBuckFile.
private VirtualFile referenceNameToBuckFile(Project project, String reference) {
// First test if it is a absolute path of a file.
File tryFile = new File(reference);
if (tryFile != null) {
VirtualFile file = VfsUtil.findFileByIoFile(tryFile, true);
if (file != null) {
return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
}
}
// Try class firstly.
PsiClass classElement = JavaPsiFacade.getInstance(project).findClass(reference, GlobalSearchScope.allScope(project));
if (classElement != null) {
VirtualFile file = PsiUtilCore.getVirtualFile(classElement);
return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
}
// Then try package.
PsiPackage packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
if (packageElement != null) {
PsiDirectory directory = packageElement.getDirectories()[0];
return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
}
// Extract the package from the reference.
int index = reference.lastIndexOf(".");
if (index == -1) {
return null;
}
reference = reference.substring(0, index);
// Try to find the package again.
packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
if (packageElement != null) {
PsiDirectory directory = packageElement.getDirectories()[0];
return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
}
return null;
}
use of com.intellij.psi.PsiClass in project qi4j-sdk by Qi4j.
the class CreateConcernOfInPackageAction method isAvailable.
@Override
protected final boolean isAvailable(DataContext dataContext) {
boolean isAvailable = super.isAvailable(dataContext);
if (!isAvailable) {
return false;
}
PsiElement psiElement = PSI_ELEMENT.getData(dataContext);
if (psiElement == null) {
return false;
}
GlobalSearchScope searchScope = determineSearchScope(psiElement);
if (searchScope == null) {
return false;
}
Project project = PROJECT.getData(dataContext);
PsiClass psiClass = getConcernOfClass(project, searchScope);
return psiClass != null;
}
use of com.intellij.psi.PsiClass in project qi4j-sdk by Qi4j.
the class ConcernsAnnotationDeclaredCorrectlyInspection method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If class does not have @Concerns, ignore
PsiAnnotation concernsAnnotation = getConcernsAnnotation(psiClass);
if (concernsAnnotation == null) {
return null;
}
// If @Concerns declared in class, suggest remove @Concerns annotation
if (!psiClass.isInterface()) {
String message = message("concerns.annotation.declared.correctly.error.annotation.declared.in.class");
RemoveConcernsAnnotationFix fix = new RemoveConcernsAnnotationFix(concernsAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(concernsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
// If @Concerns annotation is empty, ignore
List<PsiAnnotationMemberValue> concernsAnnotationValue = getConcernsAnnotationValue(concernsAnnotation);
if (concernsAnnotationValue.isEmpty()) {
return null;
}
// If ConcernOfClass is not resolved, ignore
Project project = psiClass.getProject();
GlobalSearchScope searchScope = determineSearchScope(psiClass);
PsiClass concernOfClass = getConcernOfClass(project, searchScope);
if (concernOfClass == null) {
return null;
}
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue concernClassAnnotationValue : concernsAnnotationValue) {
PsiJavaCodeReferenceElement concernClassReference = getConcernClassReference(concernClassAnnotationValue);
// If it's not a class reference, ignore
if (concernClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass concernClass = (PsiClass) concernClassReference.resolve();
if (concernClass == null) {
continue;
}
// If concern class does not inherit concern class, suggest remove that reference.
if (!concernClass.isInheritor(concernOfClass, true)) {
String message = Qi4jResourceBundle.message("concerns.annotation.declared.correctly.error.concern.class.does.not.extend.ConcernOf", concernClass.getQualifiedName());
RemoveInvalidConcernClassReferenceFix fix = new RemoveInvalidConcernClassReferenceFix(concernClassAnnotationValue, concernClassReference);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(concernClassAnnotationValue, message, fix, GENERIC_ERROR_OR_WARNING);
problems.add(problemDescriptor);
} else {
// TODO: Test whether it is a generic concern
// TODO: Test whether it is a specific concern
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.psi.PsiClass in project qi4j-sdk by Qi4j.
the class SideEffectsAnnotationDeclaredCorrectlyInspection method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If class does not have @SideEffects, ignore
PsiAnnotation sideEffectsAnnotation = getSideEffectsAnnotation(psiClass);
if (sideEffectsAnnotation == null) {
return null;
}
// If @SideEffects declared in class, suggest remove @SideEffects annotation
if (!psiClass.isInterface()) {
String message = message("side.effects.annotation.declared.correctly.error.annotation.declared.in.class");
RemoveSideEffectsAnnotationFix fix = new RemoveSideEffectsAnnotationFix(sideEffectsAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
// If @SideEffects annotation is empty, ignore
List<PsiAnnotationMemberValue> sideEffectsAnnotationValue = getSideEffectsAnnotationValue(sideEffectsAnnotation);
if (sideEffectsAnnotationValue.isEmpty()) {
return null;
}
// If SideEffectOf is not resolved, ignore
Project project = psiClass.getProject();
GlobalSearchScope searchScope = determineSearchScope(psiClass);
PsiClass sideEffectOfClass = Qi4jSideEffectUtil.getGenericSideEffectClass(project, searchScope);
if (sideEffectOfClass == null) {
return null;
}
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue sideEffectClassReferenceWrapper : sideEffectsAnnotationValue) {
PsiJavaCodeReferenceElement sideEffectClassReference = getSideEffectClassReference(sideEffectClassReferenceWrapper);
// If it's not a class reference, ignore
if (sideEffectClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass sideEffectClass = (PsiClass) sideEffectClassReference.resolve();
if (sideEffectClass == null) {
continue;
}
// If side effect class does not inherit SideEffectOf class, suggest remove that reference.
if (!sideEffectClass.isInheritor(sideEffectOfClass, true)) {
String message = Qi4jResourceBundle.message("side.effects.annotation.declared.correctly.error.side.effect.does.not.extend.side.effect.of", sideEffectClass.getQualifiedName());
RemoveAnnotationValueFix fix = new RemoveAnnotationValueFix(sideEffectClassReferenceWrapper, sideEffectClassReference);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectClassReferenceWrapper, message, fix, GENERIC_ERROR_OR_WARNING);
problems.add(problemDescriptor);
} else {
// TODO: Test whether it is a generic side effect
// TODO: Test whether it is a specific side effect
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
Aggregations