Search in sources :

Example 1 with XmlAttribNode

use of org.ballerinalang.plugins.idea.psi.XmlAttribNode in project ballerina by ballerina-lang.

the class BallerinaParserDefinition method createElement.

@NotNull
public PsiElement createElement(ASTNode node) {
    IElementType elementType = node.getElementType();
    if (elementType instanceof TokenIElementType) {
        return new ANTLRPsiNode(node);
    }
    if (!(elementType instanceof RuleIElementType)) {
        return new ANTLRPsiNode(node);
    }
    RuleIElementType ruleElType = (RuleIElementType) elementType;
    switch(ruleElType.getRuleIndex()) {
        case BallerinaParser.RULE_functionDefinition:
            return new FunctionDefinitionNode(node);
        case BallerinaParser.RULE_callableUnitBody:
            return new CallableUnitBodyNode(node);
        case BallerinaParser.RULE_nameReference:
            return new NameReferenceNode(node);
        case BallerinaParser.RULE_variableReference:
            return new VariableReferenceNode(node);
        case BallerinaParser.RULE_variableDefinitionStatement:
            return new VariableDefinitionNode(node);
        case BallerinaParser.RULE_parameter:
            return new ParameterNode(node);
        case BallerinaParser.RULE_resourceDefinition:
            return new ResourceDefinitionNode(node);
        case BallerinaParser.RULE_packageName:
            return new PackageNameNode(node);
        case BallerinaParser.RULE_fullyQualifiedPackageName:
            return new FullyQualifiedPackageNameNode(node);
        case BallerinaParser.RULE_expressionList:
            return new ExpressionListNode(node);
        case BallerinaParser.RULE_expression:
            return new ExpressionNode(node);
        case BallerinaParser.RULE_functionInvocation:
            return new FunctionInvocationNode(node);
        case BallerinaParser.RULE_compilationUnit:
            return new CompilationUnitNode(node);
        case BallerinaParser.RULE_packageDeclaration:
            return new PackageDeclarationNode(node);
        case BallerinaParser.RULE_annotationAttachment:
            return new AnnotationAttachmentNode(node);
        case BallerinaParser.RULE_serviceBody:
            return new ServiceBodyNode(node);
        case BallerinaParser.RULE_importDeclaration:
            return new ImportDeclarationNode(node);
        case BallerinaParser.RULE_statement:
            return new StatementNode(node);
        case BallerinaParser.RULE_typeName:
            return new TypeNameNode(node);
        case BallerinaParser.RULE_constantDefinition:
            return new ConstantDefinitionNode(node);
        case BallerinaParser.RULE_structDefinition:
            return new StructDefinitionNode(node);
        case BallerinaParser.RULE_simpleLiteral:
            return new SimpleLiteralNode(node);
        case BallerinaParser.RULE_packageAlias:
            return new AliasNode(node);
        case BallerinaParser.RULE_parameterList:
            return new ParameterListNode(node);
        case BallerinaParser.RULE_fieldDefinition:
            return new FieldDefinitionNode(node);
        case BallerinaParser.RULE_parameterTypeNameList:
            return new ParameterTypeNameList(node);
        case BallerinaParser.RULE_parameterTypeName:
            return new ConnectorInitNode(node);
        case BallerinaParser.RULE_serviceDefinition:
            return new ServiceDefinitionNode(node);
        case BallerinaParser.RULE_valueTypeName:
            return new ValueTypeNameNode(node);
        case BallerinaParser.RULE_annotationDefinition:
            return new AnnotationAttributeValueNode(node);
        case BallerinaParser.RULE_structBody:
            return new StructBodyNode(node);
        case BallerinaParser.RULE_returnParameter:
            return new ReturnParameterNode(node);
        case BallerinaParser.RULE_attachmentPoint:
            return new AttachmentPointNode(node);
        case BallerinaParser.RULE_definition:
            return new DefinitionNode(node);
        case BallerinaParser.RULE_ifElseStatement:
            return new IfElseStatementNode(node);
        case BallerinaParser.RULE_assignmentStatement:
            return new AssignmentStatementNode(node);
        case BallerinaParser.RULE_variableReferenceList:
            return new VariableReferenceListNode(node);
        case BallerinaParser.RULE_recordLiteral:
            return new RecordLiteralNode(node);
        case BallerinaParser.RULE_globalVariableDefinition:
            return new GlobalVariableDefinitionNode(node);
        case BallerinaParser.RULE_recordKeyValue:
            return new RecordKeyValueNode(node);
        case BallerinaParser.RULE_forkJoinStatement:
            return new ForkJoinStatementNode(node);
        case BallerinaParser.RULE_returnStatement:
            return new ReturnStatementNode(node);
        case BallerinaParser.RULE_throwStatement:
            return new ThrowStatementNode(node);
        case BallerinaParser.RULE_transformerDefinition:
            return new TransformerDefinitionNode(node);
        case BallerinaParser.RULE_workerReply:
            return new WorkerReplyNode(node);
        case BallerinaParser.RULE_triggerWorker:
            return new TriggerWorkerNode(node);
        case BallerinaParser.RULE_workerDeclaration:
            return new WorkerDeclarationNode(node);
        case BallerinaParser.RULE_workerBody:
            return new WorkerBodyNode(node);
        case BallerinaParser.RULE_joinConditions:
            return new JoinConditionNode(node);
        case BallerinaParser.RULE_field:
            return new FieldNode(node);
        case BallerinaParser.RULE_recordKey:
            return new RecordKeyNode(node);
        case BallerinaParser.RULE_recordValue:
            return new RecordValueNode(node);
        case BallerinaParser.RULE_functionReference:
            return new FunctionReferenceNode(node);
        case BallerinaParser.RULE_codeBlockBody:
            return new CodeBlockBodyNode(node);
        case BallerinaParser.RULE_nonEmptyCodeBlockBody:
            return new NonEmptyCodeBlockBodyNode(node);
        case BallerinaParser.RULE_tryCatchStatement:
            return new TryCatchStatementNode(node);
        case BallerinaParser.RULE_catchClause:
            return new CatchClauseNode(node);
        case BallerinaParser.RULE_codeBlockParameter:
            return new CodeBlockParameterNode(node);
        case BallerinaParser.RULE_foreachStatement:
            return new ForEachStatementNode(node);
        case BallerinaParser.RULE_joinClause:
            return new JoinClauseNode(node);
        case BallerinaParser.RULE_timeoutClause:
            return new TimeoutClauseNode(node);
        case BallerinaParser.RULE_xmlAttrib:
            return new XmlAttribNode(node);
        case BallerinaParser.RULE_namespaceDeclaration:
            return new NamespaceDeclarationNode(node);
        case BallerinaParser.RULE_stringTemplateLiteral:
            return new StringTemplateLiteralNode(node);
        case BallerinaParser.RULE_stringTemplateContent:
            return new StringTemplateContentNode(node);
        case BallerinaParser.RULE_typeConversion:
            return new TypeConversionNode(node);
        case BallerinaParser.RULE_xmlContent:
            return new XmlContentNode(node);
        case BallerinaParser.RULE_invocation:
            return new InvocationNode(node);
        case BallerinaParser.RULE_enumDefinition:
            return new EnumDefinitionNode(node);
        case BallerinaParser.RULE_enumField:
            return new EnumFieldNode(node);
        case BallerinaParser.RULE_builtInReferenceTypeName:
            return new BuiltInReferenceTypeNameNode(node);
        case BallerinaParser.RULE_referenceTypeName:
            return new ReferenceTypeNameNode(node);
        case BallerinaParser.RULE_functionTypeName:
            return new FunctionTypeNameNode(node);
        case BallerinaParser.RULE_lambdaFunction:
            return new LambdaFunctionNode(node);
        case BallerinaParser.RULE_endpointDeclaration:
            return new EndpointDeclarationNode(node);
        case BallerinaParser.RULE_anonStructTypeName:
            return new AnonStructTypeNameNode(node);
        case BallerinaParser.RULE_userDefineTypeName:
            return new UserDefinedTypeName(node);
        case BallerinaParser.RULE_anyIdentifierName:
            return new AnyIdentifierNameNode(node);
        case BallerinaParser.RULE_documentationAttachment:
            return new DocumentationAttachmentNode(node);
        case BallerinaParser.RULE_documentationTemplateInlineCode:
            return new DocumentationTemplateInlineCodeNode(node);
        case BallerinaParser.RULE_singleBackTickDocInlineCode:
            return new SingleBackTickDocInlineCodeNode(node);
        case BallerinaParser.RULE_doubleBackTickDocInlineCode:
            return new DoubleBackTickInlineCodeNode(node);
        case BallerinaParser.RULE_tripleBackTickDocInlineCode:
            return new TripleBackTickInlineCodeNode(node);
        case BallerinaParser.RULE_deprecatedAttachment:
            return new DeprecatedAttachmentNode(node);
        case BallerinaParser.RULE_deprecatedText:
            return new DeprecatedTextNode(node);
        case BallerinaParser.RULE_singleBackTickDeprecatedInlineCode:
            return new SingleBackTickDeprecatedInlineCodeNode(node);
        case BallerinaParser.RULE_doubleBackTickDeprecatedInlineCode:
            return new DoubleBackTickDeprecatedInlineCodeNode(node);
        case BallerinaParser.RULE_tripleBackTickDeprecatedInlineCode:
            return new TripleBackTickDeprecatedInlineCodeNode(node);
        case BallerinaParser.RULE_documentationTemplateAttributeDescription:
            return new DocumentationTemplateAttributeDescriptionNode(node);
        case BallerinaParser.RULE_formalParameterList:
            return new FormalParameterListNode(node);
        case BallerinaParser.RULE_integerLiteral:
            return new IntegerLiteralNode(node);
        case BallerinaParser.RULE_matchPatternClause:
            return new MatchPatternClauseNode(node);
        default:
            return new ANTLRPsiNode(node);
    }
}
Also used : RecordKeyValueNode(org.ballerinalang.plugins.idea.psi.RecordKeyValueNode) ReturnStatementNode(org.ballerinalang.plugins.idea.psi.ReturnStatementNode) TransformerDefinitionNode(org.ballerinalang.plugins.idea.psi.TransformerDefinitionNode) TimeoutClauseNode(org.ballerinalang.plugins.idea.psi.TimeoutClauseNode) FunctionTypeNameNode(org.ballerinalang.plugins.idea.psi.FunctionTypeNameNode) ConstantDefinitionNode(org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode) BuiltInReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.BuiltInReferenceTypeNameNode) JoinConditionNode(org.ballerinalang.plugins.idea.psi.JoinConditionNode) AttachmentPointNode(org.ballerinalang.plugins.idea.psi.AttachmentPointNode) ThrowStatementNode(org.ballerinalang.plugins.idea.psi.ThrowStatementNode) ConnectorInitNode(org.ballerinalang.plugins.idea.psi.ConnectorInitNode) CatchClauseNode(org.ballerinalang.plugins.idea.psi.CatchClauseNode) SingleBackTickDeprecatedInlineCodeNode(org.ballerinalang.plugins.idea.psi.SingleBackTickDeprecatedInlineCodeNode) VariableReferenceNode(org.ballerinalang.plugins.idea.psi.VariableReferenceNode) XmlContentNode(org.ballerinalang.plugins.idea.psi.XmlContentNode) MatchPatternClauseNode(org.ballerinalang.plugins.idea.psi.MatchPatternClauseNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) VariableDefinitionNode(org.ballerinalang.plugins.idea.psi.VariableDefinitionNode) DocumentationAttachmentNode(org.ballerinalang.plugins.idea.psi.DocumentationAttachmentNode) ForkJoinStatementNode(org.ballerinalang.plugins.idea.psi.ForkJoinStatementNode) ForEachStatementNode(org.ballerinalang.plugins.idea.psi.ForEachStatementNode) FunctionDefinitionNode(org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode) RecordLiteralNode(org.ballerinalang.plugins.idea.psi.RecordLiteralNode) IntegerLiteralNode(org.ballerinalang.plugins.idea.psi.IntegerLiteralNode) ReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.ReferenceTypeNameNode) BuiltInReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.BuiltInReferenceTypeNameNode) TokenIElementType(org.antlr.jetbrains.adaptor.lexer.TokenIElementType) ServiceBodyNode(org.ballerinalang.plugins.idea.psi.ServiceBodyNode) ReturnParameterNode(org.ballerinalang.plugins.idea.psi.ReturnParameterNode) AliasNode(org.ballerinalang.plugins.idea.psi.AliasNode) TriggerWorkerNode(org.ballerinalang.plugins.idea.psi.TriggerWorkerNode) ExpressionListNode(org.ballerinalang.plugins.idea.psi.ExpressionListNode) WorkerDeclarationNode(org.ballerinalang.plugins.idea.psi.WorkerDeclarationNode) AssignmentStatementNode(org.ballerinalang.plugins.idea.psi.AssignmentStatementNode) FieldNode(org.ballerinalang.plugins.idea.psi.FieldNode) EnumFieldNode(org.ballerinalang.plugins.idea.psi.EnumFieldNode) SimpleLiteralNode(org.ballerinalang.plugins.idea.psi.SimpleLiteralNode) ThrowStatementNode(org.ballerinalang.plugins.idea.psi.ThrowStatementNode) ForEachStatementNode(org.ballerinalang.plugins.idea.psi.ForEachStatementNode) StatementNode(org.ballerinalang.plugins.idea.psi.StatementNode) AssignmentStatementNode(org.ballerinalang.plugins.idea.psi.AssignmentStatementNode) IfElseStatementNode(org.ballerinalang.plugins.idea.psi.IfElseStatementNode) ForkJoinStatementNode(org.ballerinalang.plugins.idea.psi.ForkJoinStatementNode) ReturnStatementNode(org.ballerinalang.plugins.idea.psi.ReturnStatementNode) TryCatchStatementNode(org.ballerinalang.plugins.idea.psi.TryCatchStatementNode) WorkerBodyNode(org.ballerinalang.plugins.idea.psi.WorkerBodyNode) TryCatchStatementNode(org.ballerinalang.plugins.idea.psi.TryCatchStatementNode) TripleBackTickInlineCodeNode(org.ballerinalang.plugins.idea.psi.TripleBackTickInlineCodeNode) FunctionInvocationNode(org.ballerinalang.plugins.idea.psi.FunctionInvocationNode) InvocationNode(org.ballerinalang.plugins.idea.psi.InvocationNode) DeprecatedAttachmentNode(org.ballerinalang.plugins.idea.psi.DeprecatedAttachmentNode) RecordKeyNode(org.ballerinalang.plugins.idea.psi.RecordKeyNode) ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) EnumFieldNode(org.ballerinalang.plugins.idea.psi.EnumFieldNode) PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) StructDefinitionNode(org.ballerinalang.plugins.idea.psi.StructDefinitionNode) DocumentationTemplateAttributeDescriptionNode(org.ballerinalang.plugins.idea.psi.DocumentationTemplateAttributeDescriptionNode) ParameterTypeNameList(org.ballerinalang.plugins.idea.psi.ParameterTypeNameList) FunctionTypeNameNode(org.ballerinalang.plugins.idea.psi.FunctionTypeNameNode) TypeNameNode(org.ballerinalang.plugins.idea.psi.TypeNameNode) ReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.ReferenceTypeNameNode) BuiltInReferenceTypeNameNode(org.ballerinalang.plugins.idea.psi.BuiltInReferenceTypeNameNode) ValueTypeNameNode(org.ballerinalang.plugins.idea.psi.ValueTypeNameNode) AnonStructTypeNameNode(org.ballerinalang.plugins.idea.psi.AnonStructTypeNameNode) SingleBackTickDocInlineCodeNode(org.ballerinalang.plugins.idea.psi.SingleBackTickDocInlineCodeNode) CallableUnitBodyNode(org.ballerinalang.plugins.idea.psi.CallableUnitBodyNode) NonEmptyCodeBlockBodyNode(org.ballerinalang.plugins.idea.psi.NonEmptyCodeBlockBodyNode) EnumDefinitionNode(org.ballerinalang.plugins.idea.psi.EnumDefinitionNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) LambdaFunctionNode(org.ballerinalang.plugins.idea.psi.LambdaFunctionNode) ImportDeclarationNode(org.ballerinalang.plugins.idea.psi.ImportDeclarationNode) NonEmptyCodeBlockBodyNode(org.ballerinalang.plugins.idea.psi.NonEmptyCodeBlockBodyNode) CodeBlockBodyNode(org.ballerinalang.plugins.idea.psi.CodeBlockBodyNode) StringTemplateLiteralNode(org.ballerinalang.plugins.idea.psi.StringTemplateLiteralNode) VariableReferenceListNode(org.ballerinalang.plugins.idea.psi.VariableReferenceListNode) CompilationUnitNode(org.ballerinalang.plugins.idea.psi.CompilationUnitNode) AnonStructTypeNameNode(org.ballerinalang.plugins.idea.psi.AnonStructTypeNameNode) DocumentationTemplateInlineCodeNode(org.ballerinalang.plugins.idea.psi.DocumentationTemplateInlineCodeNode) DoubleBackTickInlineCodeNode(org.ballerinalang.plugins.idea.psi.DoubleBackTickInlineCodeNode) StringTemplateContentNode(org.ballerinalang.plugins.idea.psi.StringTemplateContentNode) UserDefinedTypeName(org.ballerinalang.plugins.idea.psi.UserDefinedTypeName) ReturnParameterNode(org.ballerinalang.plugins.idea.psi.ReturnParameterNode) ParameterNode(org.ballerinalang.plugins.idea.psi.ParameterNode) CodeBlockParameterNode(org.ballerinalang.plugins.idea.psi.CodeBlockParameterNode) XmlAttribNode(org.ballerinalang.plugins.idea.psi.XmlAttribNode) EndpointDeclarationNode(org.ballerinalang.plugins.idea.psi.EndpointDeclarationNode) WorkerReplyNode(org.ballerinalang.plugins.idea.psi.WorkerReplyNode) JoinClauseNode(org.ballerinalang.plugins.idea.psi.JoinClauseNode) AnnotationAttachmentNode(org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode) DeprecatedTextNode(org.ballerinalang.plugins.idea.psi.DeprecatedTextNode) AnyIdentifierNameNode(org.ballerinalang.plugins.idea.psi.AnyIdentifierNameNode) RuleIElementType(org.antlr.jetbrains.adaptor.lexer.RuleIElementType) ANTLRPsiNode(org.antlr.jetbrains.adaptor.psi.ANTLRPsiNode) RecordValueNode(org.ballerinalang.plugins.idea.psi.RecordValueNode) PackageDeclarationNode(org.ballerinalang.plugins.idea.psi.PackageDeclarationNode) IfElseStatementNode(org.ballerinalang.plugins.idea.psi.IfElseStatementNode) IElementType(com.intellij.psi.tree.IElementType) RuleIElementType(org.antlr.jetbrains.adaptor.lexer.RuleIElementType) TokenIElementType(org.antlr.jetbrains.adaptor.lexer.TokenIElementType) FormalParameterListNode(org.ballerinalang.plugins.idea.psi.FormalParameterListNode) ParameterListNode(org.ballerinalang.plugins.idea.psi.ParameterListNode) ConstantDefinitionNode(org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode) GlobalVariableDefinitionNode(org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode) TransformerDefinitionNode(org.ballerinalang.plugins.idea.psi.TransformerDefinitionNode) EnumDefinitionNode(org.ballerinalang.plugins.idea.psi.EnumDefinitionNode) VariableDefinitionNode(org.ballerinalang.plugins.idea.psi.VariableDefinitionNode) FunctionDefinitionNode(org.ballerinalang.plugins.idea.psi.FunctionDefinitionNode) FieldDefinitionNode(org.ballerinalang.plugins.idea.psi.FieldDefinitionNode) ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) StructDefinitionNode(org.ballerinalang.plugins.idea.psi.StructDefinitionNode) DefinitionNode(org.ballerinalang.plugins.idea.psi.DefinitionNode) FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) ServiceDefinitionNode(org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode) NamespaceDeclarationNode(org.ballerinalang.plugins.idea.psi.NamespaceDeclarationNode) ExpressionNode(org.ballerinalang.plugins.idea.psi.ExpressionNode) DoubleBackTickDeprecatedInlineCodeNode(org.ballerinalang.plugins.idea.psi.DoubleBackTickDeprecatedInlineCodeNode) TripleBackTickDeprecatedInlineCodeNode(org.ballerinalang.plugins.idea.psi.TripleBackTickDeprecatedInlineCodeNode) TypeConversionNode(org.ballerinalang.plugins.idea.psi.TypeConversionNode) FunctionReferenceNode(org.ballerinalang.plugins.idea.psi.FunctionReferenceNode) FieldDefinitionNode(org.ballerinalang.plugins.idea.psi.FieldDefinitionNode) AnnotationAttributeValueNode(org.ballerinalang.plugins.idea.psi.AnnotationAttributeValueNode) StructBodyNode(org.ballerinalang.plugins.idea.psi.StructBodyNode) ValueTypeNameNode(org.ballerinalang.plugins.idea.psi.ValueTypeNameNode) NameReferenceNode(org.ballerinalang.plugins.idea.psi.NameReferenceNode) FunctionInvocationNode(org.ballerinalang.plugins.idea.psi.FunctionInvocationNode) CodeBlockParameterNode(org.ballerinalang.plugins.idea.psi.CodeBlockParameterNode) FormalParameterListNode(org.ballerinalang.plugins.idea.psi.FormalParameterListNode) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with XmlAttribNode

use of org.ballerinalang.plugins.idea.psi.XmlAttribNode in project ballerina by ballerina-lang.

the class BallerinaUnresolvedReferenceInspection method checkFile.

@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    // does not work in tests since CodeInsightTestCase copies file into temporary location
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return new ProblemDescriptor[0];
    }
    if (!(file instanceof BallerinaFile)) {
        return new ProblemDescriptor[0];
    }
    List<ProblemDescriptor> problemDescriptors = new LinkedList<>();
    Collection<PackageNameNode> packageNameNodes = PsiTreeUtil.findChildrenOfType(file, PackageNameNode.class);
    for (PackageNameNode packageNameNode : packageNameNodes) {
        ProgressManager.checkCanceled();
        if (packageNameNode == null) {
            continue;
        }
        AliasNode aliasNode = PsiTreeUtil.getParentOfType(packageNameNode, AliasNode.class);
        if (aliasNode != null) {
            continue;
        }
        PackageDeclarationNode packageDeclarationNode = PsiTreeUtil.getParentOfType(packageNameNode, PackageDeclarationNode.class);
        if (packageDeclarationNode != null) {
            continue;
        }
        XmlAttribNode xmlAttribNode = PsiTreeUtil.getParentOfType(packageNameNode, XmlAttribNode.class);
        if (xmlAttribNode != null) {
            continue;
        }
        LocalQuickFix[] availableFixes;
        ImportDeclarationNode importDeclarationNode = PsiTreeUtil.getParentOfType(packageNameNode, ImportDeclarationNode.class);
        if (importDeclarationNode != null) {
            availableFixes = new LocalQuickFix[0];
        } else {
            BallerinaImportPackageQuickFix quickFix = new BallerinaImportPackageQuickFix(packageNameNode);
            availableFixes = new LocalQuickFix[] { quickFix };
        }
        PsiElement nameIdentifier = packageNameNode.getNameIdentifier();
        if (nameIdentifier == null) {
            continue;
        }
        PsiReference reference = nameIdentifier.getReference();
        if (reference == null || reference.resolve() == null) {
            if (reference instanceof PackageNameReference) {
                ResolveResult[] resolveResults = ((PackageNameReference) reference).multiResolve(false);
                if (resolveResults.length > 0) {
                    continue;
                }
            }
            problemDescriptors.add(createProblemDescriptor(manager, packageNameNode, isOnTheFly, availableFixes));
        }
    }
    // Todo - Add new quick fixes.
    LocalQuickFix[] availableFixes = new LocalQuickFix[0];
    Collection<NameReferenceNode> nameReferenceNodes = PsiTreeUtil.findChildrenOfType(file, NameReferenceNode.class);
    problemDescriptors.addAll(getUnresolvedNameReferenceDescriptors(manager, isOnTheFly, availableFixes, nameReferenceNodes));
    Collection<AnnotationAttributeNode> annotationAttributeNodes = PsiTreeUtil.findChildrenOfType(file, AnnotationAttributeNode.class);
    problemDescriptors.addAll(getUnresolvedReferenceDescriptors(manager, isOnTheFly, availableFixes, annotationAttributeNodes));
    Collection<ConnectorReferenceNode> connectorReferenceNodes = PsiTreeUtil.findChildrenOfType(file, ConnectorReferenceNode.class);
    problemDescriptors.addAll(getUnresolvedReferenceDescriptors(manager, isOnTheFly, availableFixes, connectorReferenceNodes));
    Collection<ActionInvocationNode> actionInvocationNodes = PsiTreeUtil.findChildrenOfType(file, ActionInvocationNode.class);
    problemDescriptors.addAll(getUnresolvedReferenceDescriptors(manager, isOnTheFly, availableFixes, actionInvocationNodes));
    Collection<FunctionReferenceNode> functionReferenceNodes = PsiTreeUtil.findChildrenOfType(file, FunctionReferenceNode.class);
    problemDescriptors.addAll(getUnresolvedReferenceDescriptors(manager, isOnTheFly, availableFixes, functionReferenceNodes));
    return problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]);
}
Also used : BallerinaFile(org.ballerinalang.plugins.idea.psi.BallerinaFile) ImportDeclarationNode(org.ballerinalang.plugins.idea.psi.ImportDeclarationNode) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PackageNameReference(org.ballerinalang.plugins.idea.psi.references.PackageNameReference) AnnotationAttributeNode(org.ballerinalang.plugins.idea.psi.AnnotationAttributeNode) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) XmlAttribNode(org.ballerinalang.plugins.idea.psi.XmlAttribNode) ConnectorReferenceNode(org.ballerinalang.plugins.idea.psi.ConnectorReferenceNode) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) AliasNode(org.ballerinalang.plugins.idea.psi.AliasNode) ActionInvocationNode(org.ballerinalang.plugins.idea.psi.ActionInvocationNode) PsiReference(com.intellij.psi.PsiReference) PackageDeclarationNode(org.ballerinalang.plugins.idea.psi.PackageDeclarationNode) LinkedList(java.util.LinkedList) PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) FunctionReferenceNode(org.ballerinalang.plugins.idea.psi.FunctionReferenceNode) NameReferenceNode(org.ballerinalang.plugins.idea.psi.NameReferenceNode) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with XmlAttribNode

use of org.ballerinalang.plugins.idea.psi.XmlAttribNode in project ballerina by ballerina-lang.

the class UnusedImportInspection method checkFile.

@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    // does not work in tests since CodeInsightTestCase copies file into temporary location
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return new ProblemDescriptor[0];
    }
    if (!(file instanceof BallerinaFile)) {
        return new ProblemDescriptor[0];
    }
    // This is used to track all packages used in the file.
    List<String> usedPackages = new LinkedList<>();
    LocalQuickFix[] availableFixes = new LocalQuickFix[0];
    List<ProblemDescriptor> problemDescriptors = new LinkedList<>();
    Collection<PackageNameNode> packageNameNodes = PsiTreeUtil.findChildrenOfType(file, PackageNameNode.class);
    for (PackageNameNode packageNameNode : packageNameNodes) {
        ProgressManager.checkCanceled();
        if (packageNameNode == null) {
            continue;
        }
        PackageDeclarationNode packageDeclarationNode = PsiTreeUtil.getParentOfType(packageNameNode, PackageDeclarationNode.class);
        if (packageDeclarationNode != null) {
            continue;
        }
        ImportDeclarationNode importDeclarationNode = PsiTreeUtil.getParentOfType(packageNameNode, ImportDeclarationNode.class);
        if (importDeclarationNode != null) {
            continue;
        }
        XmlAttribNode xmlAttribNode = PsiTreeUtil.getParentOfType(packageNameNode, XmlAttribNode.class);
        if (xmlAttribNode != null) {
            continue;
        }
        PsiElement nameIdentifier = packageNameNode.getNameIdentifier();
        if (nameIdentifier == null) {
            continue;
        }
        usedPackages.add(nameIdentifier.getText());
    }
    // This is used to keep track of fully qualified imported packages. This will be used to identify redeclared
    // import statements.
    List<String> fullyQualifiedImportedPackages = new LinkedList<>();
    // This is used to keep track of last package in import declaration. This will be used to identify importing
    // multiple packages which ends with same name.
    List<String> importedPackages = new LinkedList<>();
    Collection<ImportDeclarationNode> importDeclarationNodes = PsiTreeUtil.findChildrenOfType(file, ImportDeclarationNode.class);
    for (ImportDeclarationNode importDeclarationNode : importDeclarationNodes) {
        ProgressManager.checkCanceled();
        if (importDeclarationNode == null) {
            continue;
        }
        // Check unused imports. No need to check for fully qualified path since we cant import packages of same
        // name.
        List<PackageNameNode> packageNames = new ArrayList<>(PsiTreeUtil.findChildrenOfType(importDeclarationNode, PackageNameNode.class));
        PackageNameNode lastPackage = ContainerUtil.getLastItem(packageNames);
        if (lastPackage == null) {
            continue;
        }
        String lastPackageName = lastPackage.getText();
        if (!usedPackages.contains(lastPackageName)) {
            problemDescriptors.add(createProblemDescriptor(manager, "Unused import", isOnTheFly, importDeclarationNode, availableFixes, ProblemHighlightType.LIKE_UNUSED_SYMBOL));
        }
        // Check conflicting imports (which ends with same package name).
        if (importedPackages.contains(lastPackageName)) {
            problemDescriptors.add(createProblemDescriptor(manager, "Conflicting import", isOnTheFly, importDeclarationNode, availableFixes, ProblemHighlightType.GENERIC_ERROR));
        }
        importedPackages.add(lastPackageName);
        // Check redeclared imports.
        FullyQualifiedPackageNameNode fullyQualifiedPackageName = PsiTreeUtil.getChildOfType(importDeclarationNode, FullyQualifiedPackageNameNode.class);
        if (fullyQualifiedPackageName == null) {
            continue;
        }
        if (fullyQualifiedImportedPackages.contains(fullyQualifiedPackageName.getText())) {
            problemDescriptors.add(createProblemDescriptor(manager, "Redeclared import", isOnTheFly, importDeclarationNode, availableFixes, ProblemHighlightType.GENERIC_ERROR));
        }
        fullyQualifiedImportedPackages.add(fullyQualifiedPackageName.getText());
    }
    return problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]);
}
Also used : BallerinaFile(org.ballerinalang.plugins.idea.psi.BallerinaFile) ImportDeclarationNode(org.ballerinalang.plugins.idea.psi.ImportDeclarationNode) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) ArrayList(java.util.ArrayList) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PackageDeclarationNode(org.ballerinalang.plugins.idea.psi.PackageDeclarationNode) LinkedList(java.util.LinkedList) FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) XmlAttribNode(org.ballerinalang.plugins.idea.psi.XmlAttribNode) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with XmlAttribNode

use of org.ballerinalang.plugins.idea.psi.XmlAttribNode in project ballerina by ballerina-lang.

the class BallerinaAnnotator method annotatePackageNameNodes.

private void annotatePackageNameNodes(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    PsiElement parent = element.getParent();
    if (parent != null) {
        PsiElement superParent = parent.getParent();
        if (superParent != null && superParent instanceof AnnotationAttachmentNode) {
            Annotation annotation = holder.createInfoAnnotation(element, null);
            annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.ANNOTATION);
            return;
        }
    }
    ImportDeclarationNode importDeclarationNode = PsiTreeUtil.getParentOfType(element, ImportDeclarationNode.class);
    if (importDeclarationNode != null) {
        return;
    }
    PackageDeclarationNode packageDeclarationNode = PsiTreeUtil.getParentOfType(element, PackageDeclarationNode.class);
    if (packageDeclarationNode != null) {
        return;
    }
    AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getParentOfType(element, AnnotationAttachmentNode.class);
    if (annotationAttachmentNode != null) {
        return;
    }
    XmlAttribNode xmlAttribNode = PsiTreeUtil.getParentOfType(element, XmlAttribNode.class);
    if (xmlAttribNode != null) {
        return;
    }
    // Create the annotation.
    Annotation annotation = holder.createInfoAnnotation(element.getTextRange(), null);
    annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.PACKAGE);
}
Also used : ImportDeclarationNode(org.ballerinalang.plugins.idea.psi.ImportDeclarationNode) XmlAttribNode(org.ballerinalang.plugins.idea.psi.XmlAttribNode) PackageDeclarationNode(org.ballerinalang.plugins.idea.psi.PackageDeclarationNode) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Annotation(com.intellij.lang.annotation.Annotation) AnnotationAttachmentNode(org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode)

Example 5 with XmlAttribNode

use of org.ballerinalang.plugins.idea.psi.XmlAttribNode in project ballerina by ballerina-lang.

the class BallerinaImportOptimizer method getUsedImportDeclarations.

/**
 * Used to get used imports in a file.
 *
 * @param file a {@link PsiFile} element
 * @return list of used {@link ImportDeclarationNode} in the file.
 */
private List<ImportDeclarationNode> getUsedImportDeclarations(@NotNull PsiFile file) {
    // This is used to track all packages used in the file.
    List<String> usedPackages = new LinkedList<>();
    Collection<PackageNameNode> packageNameNodes = PsiTreeUtil.findChildrenOfType(file, PackageNameNode.class);
    for (PackageNameNode packageNameNode : packageNameNodes) {
        ProgressManager.checkCanceled();
        if (packageNameNode == null) {
            continue;
        }
        PackageDeclarationNode packageDeclarationNode = PsiTreeUtil.getParentOfType(packageNameNode, PackageDeclarationNode.class);
        if (packageDeclarationNode != null) {
            continue;
        }
        ImportDeclarationNode importDeclarationNode = PsiTreeUtil.getParentOfType(packageNameNode, ImportDeclarationNode.class);
        if (importDeclarationNode != null) {
            continue;
        }
        XmlAttribNode xmlAttribNode = PsiTreeUtil.getParentOfType(packageNameNode, XmlAttribNode.class);
        if (xmlAttribNode != null) {
            continue;
        }
        PsiElement nameIdentifier = packageNameNode.getNameIdentifier();
        if (nameIdentifier == null) {
            continue;
        }
        usedPackages.add(nameIdentifier.getText());
    }
    List<ImportDeclarationNode> usedImportDeclarations = new LinkedList<>();
    List<String> fullyQualifiedImportedPackages = new LinkedList<>();
    List<String> importedPackages = new LinkedList<>();
    Collection<ImportDeclarationNode> importDeclarationNodes = PsiTreeUtil.findChildrenOfType(file, ImportDeclarationNode.class);
    for (ImportDeclarationNode importDeclarationNode : importDeclarationNodes) {
        ProgressManager.checkCanceled();
        if (importDeclarationNode == null) {
            continue;
        }
        // Check unused imports. No need to check for fully qualified path since we cant import packages of same
        // name.
        List<PackageNameNode> packageNames = new ArrayList<>(PsiTreeUtil.findChildrenOfType(importDeclarationNode, PackageNameNode.class));
        PackageNameNode lastPackage = ContainerUtil.getLastItem(packageNames);
        if (lastPackage == null) {
            continue;
        }
        String lastPackageName = lastPackage.getText();
        if (!usedPackages.contains(lastPackageName)) {
            continue;
        }
        // Check conflicting imports (which ends with same package name).
        if (importedPackages.contains(lastPackageName)) {
            continue;
        }
        importedPackages.add(lastPackageName);
        // Check redeclared imports.
        FullyQualifiedPackageNameNode fullyQualifiedPackageName = PsiTreeUtil.getChildOfType(importDeclarationNode, FullyQualifiedPackageNameNode.class);
        if (fullyQualifiedPackageName == null) {
            continue;
        }
        if (fullyQualifiedImportedPackages.contains(fullyQualifiedPackageName.getText())) {
            continue;
        }
        fullyQualifiedImportedPackages.add(fullyQualifiedPackageName.getText());
        usedImportDeclarations.add(importDeclarationNode);
    }
    return usedImportDeclarations;
}
Also used : ImportDeclarationNode(org.ballerinalang.plugins.idea.psi.ImportDeclarationNode) ArrayList(java.util.ArrayList) PackageDeclarationNode(org.ballerinalang.plugins.idea.psi.PackageDeclarationNode) LinkedList(java.util.LinkedList) FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) XmlAttribNode(org.ballerinalang.plugins.idea.psi.XmlAttribNode) PsiElement(com.intellij.psi.PsiElement)

Aggregations

ImportDeclarationNode (org.ballerinalang.plugins.idea.psi.ImportDeclarationNode)5 PackageDeclarationNode (org.ballerinalang.plugins.idea.psi.PackageDeclarationNode)5 XmlAttribNode (org.ballerinalang.plugins.idea.psi.XmlAttribNode)5 PsiElement (com.intellij.psi.PsiElement)4 PackageNameNode (org.ballerinalang.plugins.idea.psi.PackageNameNode)4 LinkedList (java.util.LinkedList)3 FullyQualifiedPackageNameNode (org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode)3 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)2 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)2 ArrayList (java.util.ArrayList)2 AliasNode (org.ballerinalang.plugins.idea.psi.AliasNode)2 AnnotationAttachmentNode (org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode)2 BallerinaFile (org.ballerinalang.plugins.idea.psi.BallerinaFile)2 FunctionReferenceNode (org.ballerinalang.plugins.idea.psi.FunctionReferenceNode)2 NameReferenceNode (org.ballerinalang.plugins.idea.psi.NameReferenceNode)2 Nullable (org.jetbrains.annotations.Nullable)2 Annotation (com.intellij.lang.annotation.Annotation)1 PsiReference (com.intellij.psi.PsiReference)1 ResolveResult (com.intellij.psi.ResolveResult)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1