Java Code Examples for com.intellij.psi.PsiClass#isInterface()
The following examples show how to use
com.intellij.psi.PsiClass#isInterface() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddConcernOnType.java From attic-polygene-java with Apache License 2.0 | 6 votes |
protected boolean isIntentionValidFor( PsiElement element ) { if( !( element instanceof PsiClass ) ) { return false; } // If it's not interface, ignore it PsiClass psiClass = (PsiClass) element; if( !psiClass.isInterface() ) { return false; } // Is @Concerns accesible within module GlobalSearchScope searchScope = determineSearchScope( psiClass ); PsiClass concernOfClass = getConcernOfClass( psiClass.getProject(), searchScope ); return concernOfClass != null; }
Example 2
Source File: MixinsAnnotationDeclaredOnMixinType.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public ProblemDescriptor[] checkClass( @NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly ) { PsiAnnotation mixinsAnnotation = getMixinsAnnotation( psiClass ); if( mixinsAnnotation == null ) { return null; } if( psiClass.isInterface() ) { return null; } String message = message( "mixins.annotation.declared.on.mixin.type.error.declared.on.class" ); RemoveInvalidMixinClassReferenceFix fix = new RemoveInvalidMixinClassReferenceFix( mixinsAnnotation ); ProblemDescriptor problemDescriptor = manager.createProblemDescriptor( mixinsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING ); return new ProblemDescriptor[]{ problemDescriptor }; }
Example 3
Source File: HaxeSubtypesHierarchyTreeStructure.java From intellij-haxe with Apache License 2.0 | 6 votes |
private static ArrayList<PsiClass> getSuperTypesAsList(PsiClass theClass) { final ArrayList<PsiClass> allSuperClasses = new ArrayList<PsiClass>(); while (true) { final PsiClass aClass1 = theClass; final PsiClass[] superTypes = aClass1.getSupers(); PsiClass superType = null; for (int i = 0; i < superTypes.length; i++) { final PsiClass type = superTypes[i]; if (!type.isInterface()) { superType = type; break; } } if (superType == null) break; if (allSuperClasses.contains(superType)) break; allSuperClasses.add(superType); theClass = superType; } return allSuperClasses; }
Example 4
Source File: MicroProfileHealthDiagnosticsParticipant.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
private static void collectDiagnostics(PsiElement[] elements, List<Diagnostic> diagnostics, JavaDiagnosticsContext context) { for (PsiElement element : elements) { if (element instanceof PsiClass) { PsiClass type = (PsiClass) element; if (!type.isInterface()) { validateClassType(type, diagnostics, context); } continue; } } }
Example 5
Source File: MicroProfileRestClientDiagnosticsParticipant.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
private static void collectDiagnostics(PsiElement[] elements, List<Diagnostic> diagnostics, JavaDiagnosticsContext context) { for (PsiElement element : elements) { if (element instanceof PsiClass) { PsiClass type = (PsiClass) element; if (type.isInterface()) { validateInterfaceType(type, diagnostics, context); } else { validateClassType(type, diagnostics, context); } continue; } } }
Example 6
Source File: AbstractFieldNameConstantsProcessor.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean validateAnnotationOnRightType(@NotNull PsiClass psiClass, @NotNull ProblemBuilder builder) { if (psiClass.isAnnotationType() || psiClass.isInterface()) { builder.addError("'@FieldNameConstants' is only supported on a class or enum"); return false; } return true; }
Example 7
Source File: LombokAugmentProvider.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull @Override public <Psi extends PsiElement> List<Psi> getAugments(@NotNull PsiElement element, @NotNull final Class<Psi> type) { final List<Psi> emptyResult = Collections.emptyList(); if ((type != PsiClass.class && type != PsiField.class && type != PsiMethod.class) || !(element instanceof PsiExtensibleClass)) { return emptyResult; } // Don't filter !isPhysical elements or code auto completion will not work if (!element.isValid()) { return emptyResult; } final PsiClass psiClass = (PsiClass) element; // Skip processing of Annotations and Interfaces if (psiClass.isAnnotationType() || psiClass.isInterface()) { return emptyResult; } // skip processing if plugin is disabled final Project project = element.getProject(); if (!ProjectSettings.isLombokEnabledInProject(project)) { return emptyResult; } final List<Psi> cachedValue; if (type == PsiField.class) { cachedValue = CachedValuesManager.getCachedValue(element, new FieldLombokCachedValueProvider<>(type, psiClass)); } else if (type == PsiMethod.class) { cachedValue = CachedValuesManager.getCachedValue(element, new MethodLombokCachedValueProvider<>(type, psiClass)); } else { cachedValue = CachedValuesManager.getCachedValue(element, new ClassLombokCachedValueProvider<>(type, psiClass)); } return null != cachedValue ? cachedValue : emptyResult; }
Example 8
Source File: AbstractDelombokAction.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean isValidForClass(@NotNull PsiClass psiClass) { if (psiClass.isInterface()) { return false; } Collection<PsiAnnotation> psiAnnotations = getHandler().collectProcessableAnnotations(psiClass); if (!psiAnnotations.isEmpty()) { return true; } final Collection<PsiClass> classesIntern = PsiClassUtil.collectInnerClassesIntern(psiClass); return classesIntern.stream().anyMatch(this::isValidForClass); }
Example 9
Source File: QuarkusConfigPropertiesProvider.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
private void processConfigProperties(PsiModifierListOwner psiElement, PsiAnnotation configPropertiesAnnotation, ConfigPropertiesContext configPropertiesContext, IPropertiesCollector collector) { if (!(psiElement instanceof PsiClass)) { return; } PsiClass configPropertiesType = (PsiClass) psiElement; // Location (JAR, src) VirtualFile packageRoot = PsiTypeUtils.getRootDirectory(psiElement); String location = PsiTypeUtils.getLocation(psiElement.getProject(), packageRoot); // Quarkus Extension name String extensionName = PsiQuarkusUtils.getExtensionName(location); String prefix = determinePrefix(configPropertiesType, configPropertiesAnnotation); if (configPropertiesType.isInterface()) { // See // https://github.com/quarkusio/quarkus/blob/0796d712d9a3cf8251d9d8808b705f1a04032ee2/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/InterfaceConfigPropertiesUtil.java#L89 List<PsiClass> allInterfaces = new ArrayList(Arrays.asList(findInterfaces(configPropertiesType))); allInterfaces.add(0, configPropertiesType); for (PsiClass configPropertiesInterface : allInterfaces) { // Loop for each methods. PsiElement[] elements = configPropertiesInterface.getChildren(); // Loop for each fields. for (PsiElement child : elements) { if (child instanceof PsiMethod) { PsiMethod method = (PsiMethod) child; if (method.getModifierList().hasExplicitModifier(PsiModifier.DEFAULT)) { // don't do anything with default methods continue; } if (method.hasParameters()) { LOGGER.info("Method " + method.getName() + " of interface " + method.getContainingClass().getQualifiedName() + " is not a getter method since it defined parameters"); continue; } if (PsiType.VOID.equals(method.getReturnType())) { LOGGER.info("Method " + method.getName() + " of interface " + method.getContainingClass().getQualifiedName() + " is not a getter method since it returns void"); continue; } String name = null; String defaultValue = null; PsiAnnotation configPropertyAnnotation = AnnotationUtils.getAnnotation(method, QuarkusConstants.CONFIG_PROPERTY_ANNOTATION); if (configPropertyAnnotation != null) { name = getAnnotationMemberValue(configPropertyAnnotation, QuarkusConstants.CONFIG_PROPERTY_ANNOTATION_NAME); defaultValue = getAnnotationMemberValue(configPropertyAnnotation, QuarkusConstants.CONFIG_PROPERTY_ANNOTATION_DEFAULT_VALUE); } if (name == null) { name = getPropertyNameFromMethodName(method); } if (name == null) { continue; } String propertyName = prefix + "." + convertName(name, method, configPropertiesAnnotation, configPropertiesContext); String methodResultTypeName = PsiTypeUtils.getResolvedResultTypeName(method); PsiClass returnType = PsiTypeUtils.findType(method.getManager(), methodResultTypeName); // Method result type String type = PsiTypeUtils.getPropertyType(returnType, methodResultTypeName); // TODO: extract Javadoc from Java sources String description = null; // Method source String sourceType = PsiTypeUtils.getSourceType(method); String sourceMethod = PsiTypeUtils.getSourceMethod(method); // Enumerations super.updateHint(collector, returnType); if (PsiTypeUtils.isSimpleFieldType(returnType, methodResultTypeName)) { ItemMetadata metadata = super.addItemMetadata(collector, propertyName, type, description, sourceType, null, sourceMethod, defaultValue, extensionName, PsiTypeUtils.isBinary(method)); PsiQuarkusUtils.updateConverterKinds(metadata, method, returnType); } else { populateConfigObject(returnType, propertyName, extensionName, new HashSet(), configPropertiesAnnotation, configPropertiesContext, collector); } } } } } else { // See // https://github.com/quarkusio/quarkus/blob/e8606513e1bd14f0b1aaab7f9969899bd27c55a3/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ClassConfigPropertiesUtil.java#L117 // TODO : validation populateConfigObject(configPropertiesType, prefix, extensionName, new HashSet<>(), configPropertiesAnnotation, configPropertiesContext, collector); } }
Example 10
Source File: MixinImplementsMixinType.java From attic-polygene-java with Apache License 2.0 | 4 votes |
@Override public final ProblemDescriptor[] checkClass( @NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly ) { // If psiClass is not an interface, ignore if( !psiClass.isInterface() ) { return null; } // If @Mixins annotation is empty, ignore List<PsiAnnotationMemberValue> mixinAnnotationValues = getMixinsAnnotationValue( psiClass ); if( mixinAnnotationValues.isEmpty() ) { return null; } // Get all valid mixin type Set<PsiClass> validMixinsType = getAllValidMixinTypes( psiClass ); if( validMixinsType.isEmpty() ) { return null; } // For each mixin List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>(); for( PsiAnnotationMemberValue mixinAnnotationValue : mixinAnnotationValues ) { PsiJavaCodeReferenceElement mixinClassReference = getMixinClassReference( mixinAnnotationValue ); // If it's not a class reference, ignore if( mixinClassReference == null ) { continue; } // If class reference can't be resolved, ignore PsiClass mixinClass = (PsiClass) mixinClassReference.resolve(); if( mixinClass == null ) { continue; } String mixinQualifiedName = mixinClass.getQualifiedName(); boolean isMixinsDeclarationValid = false; String message = ""; if( mixinClass.isInterface() ) { // Mixin can't be an interface message = message( "mixin.implements.mixin.type.error.mixin.is.an.interface", mixinQualifiedName ); } else if( isAConcern( mixinClass ) ) { // Mixin can't be a concern message = message( "mixin.implements.mixin.type.error.mixin.is.a.concern", mixinQualifiedName ); } else if( isASideEffect( mixinClass ) ) { // Mixin can't be a side effect message = message( "mixin.implements.mixin.type.error.mixin.is.a.side.effect", mixinQualifiedName ); } else { // If doesn't implement any mixin type, it's a problem if( !isImplementValidMixinType( mixinClass, validMixinsType ) ) { message = message( "mixin.implements.mixin.type.error.does.not.implement.any.mixin.type", mixinQualifiedName, psiClass.getQualifiedName() ); } else { isMixinsDeclarationValid = true; } } if( !isMixinsDeclarationValid ) { ProblemDescriptor problemDescriptor = createProblemDescriptor( manager, mixinAnnotationValue, mixinClassReference, message ); problems.add( problemDescriptor ); } } return problems.toArray( new ProblemDescriptor[problems.size()] ); }
Example 11
Source File: OverrideImplementMethodFix.java From intellij-haxe with Apache License 2.0 | 4 votes |
@Override protected String buildFunctionsText(HaxeNamedComponent element) { final HaxeComponentType componentType = HaxeComponentType.typeOf(element); final StringBuilder result = new StringBuilder(); final PsiClass containingClass = element instanceof PsiMember ? ((PsiMember)element).getContainingClass() : null; final boolean isInterfaceElement = containingClass != null && containingClass.isInterface(); boolean addOverride = !isInterfaceElement && override && !element.isOverride(); if (addOverride) { result.append("override "); } final HaxePsiModifier[] declarationAttributeList = PsiTreeUtil.getChildrenOfType(element, HaxePsiModifier.class); if (declarationAttributeList != null) { result.append(StringUtil.join(declarationAttributeList, new Function<HaxePsiModifier, String>() { @Override public String fun(HaxePsiModifier attribute) { return attribute.getText(); } }, " ")); result.append(" "); } if (isInterfaceElement && !result.toString().contains("public")) { result.insert(0, "public "); } if (componentType == HaxeComponentType.FIELD) { result.append("var "); result.append(element.getName()); } else { result.append("function "); appendMethodNameAndParameters(result, element, true); } final HaxeTypeTag typeTag = PsiTreeUtil.getChildOfType(element, HaxeTypeTag.class); String type = null; if (typeTag != null && typeTag.getTypeOrAnonymous() != null) { result.append(":"); type = HaxePresentableUtil.buildTypeText(element, typeTag.getTypeOrAnonymous().getType(), specializations); result.append(type); } if(componentType == HaxeComponentType.FIELD) { result.append(";"); } else { result.append("{\n"); if(addOverride || element.isOverride()) { if(type != null && !type.equals("Void")) { result.append("return "); } result.append("super."); appendMethodNameAndParameters(result, element, false); result.append(";\n"); } result.append("}"); } return result.toString(); }
Example 12
Source File: UtilityClassProcessor.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static boolean checkWrongType(PsiClass psiClass) { return psiClass != null && (psiClass.isInterface() || psiClass.isEnum() || psiClass.isAnnotationType()); }