public final boolean value( PsiFile psiFile ) { final boolean[] hasPolygeneImportPackage = new boolean[]{ false }; psiFile.accept( new JavaElementVisitor() { @Override public final void visitImportStatement( PsiImportStatement statement ) { String packageName = statement.getQualifiedName(); if( packageName != null && packageName.startsWith( "org.apache.polygene" ) ) { hasPolygeneImportPackage[ 0 ] = true; } } @Override public void visitReferenceExpression( PsiReferenceExpression expression ) { // Ignore } } ); return hasPolygeneImportPackage[ 0 ]; }
private static ThreeState isReferenceToAnnotation(final PsiElement psiElement) { if(psiElement.getLanguage() == JavaLanguage.INSTANCE && !PsiUtil.isLanguageLevel5OrHigher(psiElement)) { return ThreeState.NO; } if(PsiTreeUtil.getParentOfType(psiElement, PsiAnnotation.class) != null) { return ThreeState.YES; } if(PsiTreeUtil.getParentOfType(psiElement, PsiImportStatement.class) != null) { return ThreeState.UNSURE; } return ThreeState.NO; }
@Override public void visitClass(@NotNull PsiClass aClass) { // no call to super, so it doesn't drill down if (!(aClass.getParent() instanceof PsiJavaFile)) { return; } if (FileTypeUtils.isInJsp(aClass.getContainingFile())) { return; } final PsiJavaFile file = (PsiJavaFile)aClass.getParent(); if (file == null) { return; } if (!file.getClasses()[0].equals(aClass)) { return; } final PsiImportList importList = file.getImportList(); if (importList == null) { return; } final PsiImportStatement[] importStatements = importList.getImportStatements(); for (final PsiImportStatement importStatement : importStatements) { if (!importStatement.isOnDemand()) { registerError(importStatement); } } }
@Override public void visitImportStatement(PsiImportStatement statement) { mVisitor.report("PsiImportStatement", statement.getText(), statement); super.visitElement(statement); }
public CollidingClassImportUsageInfo(PsiImportStatement element, PsiElement referencedElement) { super(element, referencedElement); myImportStatement = element; }
public PsiImportStatement getImportStatement() { return myImportStatement; }
public RemoveImportUsageInfo(PsiImportStatement importStatement) { super(importStatement); myImportStatement = importStatement; }
private static void ensureBoundModelIsValid(ProblemsHolder holder, PsiAnnotation annotation) { final BoundMetaData boundMetaData = DataBindUtil.getBoundMetaData(annotation); if (!boundMetaData.getBindingMetaData().isValidBindableModel()) { final PsiClass boundClass = boundMetaData.getBindingMetaData().getBoundClass(); if (boundClass != null) { final PsiVariable var = (PsiVariable) Util.getImmediateOwnerElement(annotation); if (var == null) { return; } final PsiTypeElement typeElement = var.getTypeElement(); if (typeElement == null) { return; } holder.registerProblem(typeElement, "The model type (" + boundClass.getQualifiedName() + ") is not bindable."); } else { final Collection<AnnotationSearchResult> autoBoundAnnotations = boundMetaData.getBindingMetaData().getModelAnnotations(); if (autoBoundAnnotations.size() > 1) { holder.registerProblem(annotation, "Multiple model binding annotations found"); } } } else { final PsiElement element = Util.getMethodOrField(annotation); if (!Util.elementIsAnnotated(element, Types.JAVAX_INJECT)) { holder.registerProblem(annotation, "Model specifier is not injected", new LocalQuickFix() { @NotNull @Override public String getName() { return "Add @Inject to class member"; } @NotNull @Override public String getFamilyName() { return GroupNames.BUGS_GROUP_NAME; } @Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final JavaPsiFacade instance = JavaPsiFacade.getInstance(project); final PsiElementFactory elementFactory = instance.getElementFactory(); final PsiImportStatement importJavaxInject = instance.getElementFactory() .createImportStatement( instance.findClass(Types.JAVAX_INJECT, ProjectScope.getAllScope(project)) ); final PsiImportList importList = ((PsiJavaFile) PsiUtil.getTopLevelClass(element).getParent()).getImportList(); importList.add(importJavaxInject); ((PsiModifierListOwner) element).getModifierList().addAnnotation("Inject"); } }); } } }