aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/queries/PQueryHeader.java
blob: f367193479987b6e051ed69fa3ac04bc3a601879 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*******************************************************************************
 * Copyright (c) 2010-2015, Bergmann Gabor, Istvan Rath and Daniel Varro
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-v20.html.
 * 
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package tools.refinery.viatra.runtime.matchers.psystem.queries;

import java.util.List;
import java.util.Optional;

import tools.refinery.viatra.runtime.matchers.psystem.annotations.PAnnotation;

/**
 * Represents header information (metainfo) about a query. 
 * <p> To be implemented both by IQuerySpecifications intended for end users, 
 * and the internal query representation {@link PQuery}.
 * 
 * 
 * @author Bergmann Gabor
 * @since 0.9
 */
public interface PQueryHeader {

    /**
     * Identifies the pattern for which matchers can be instantiated.
     */
    public String getFullyQualifiedName();

    /**
     * Return the list of parameter names
     * 
     * @return a non-null, but possibly empty list of parameter names
     */
    public List<String> getParameterNames();

    /**
     * Returns a list of parameter descriptions
     * 
     * @return a non-null, but possibly empty list of parameter descriptions
     */
    public List<PParameter> getParameters();

    /**
     * Returns the index of a named parameter
     * 
     * @param parameterName
     * @return the index, or null of no such parameter is available
     */
    public Integer getPositionOfParameter(String parameterName);

    /**
     * Returns a parameter by name if exists
     * @since 2.1
     */
    default Optional<PParameter> getParameter(String parameterName) {
        return Optional.ofNullable(getPositionOfParameter(parameterName))
            .map(getParameters()::get);
    }
    
    /**
     * Returns the list of annotations specified for this query
     * 
     * @return a non-null, but possibly empty list of annotations
     */
    public List<PAnnotation> getAllAnnotations();

    /**
     * Returns the list of annotations with a specified name
     * 
     * @param annotationName
     * @return a non-null, but possibly empty list of annotations
     */
    public List<PAnnotation> getAnnotationsByName(String annotationName);

    /**
     * Returns the first annotation with a specified name
     * 
     * @since 2.0
     */
    public Optional<PAnnotation> getFirstAnnotationByName(String annotationName);
    
    /**
     * Returns the visibility information about the query.
     * @since 2.0
     */
    public PVisibility getVisibility();
    
    /**
     * Returns the non-qualified name of the query. By default this means returning the qualified name after the last
     * '.' character.
     * 
     * @since 2.0
     */
    public default String getSimpleName() {
        return PQueries.calculateSimpleName(getFullyQualifiedName());
    }

}