pure_ide.findUsage.pure Maven / Gradle / Ivy
// Copyright 2020 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
###Pure
import meta::pure::ide::findusages::*;
function meta::pure::ide::findusages::findUsagesForMultiplePaths(paths:String[1]):Pair>[*]
{
$paths->split(',')->map(path|$path->pair($path->findUsagesForPath()->list()));
}
function meta::pure::ide::findusages::findUsagesForPath(path:String[1]):SourceInformation[*]
{
$path->pathToElement()->meta::pure::ide::findusages::findUsages();
}
function meta::pure::ide::findusages::findUsagesForProperty(ownerPath:String[1], propertyName:String[1]):SourceInformation[*]
{
$ownerPath->pathToElement()->match([
c:Class[1] | $c->findClassProperty($propertyName)->findUsages(),
a:Association[1] | $a.properties->get($propertyName)->toOne()->findUsages()
]);
}
function meta::pure::ide::findusages::findUsages(element:Any[1]):SourceInformation[*]
{
$element->match([
f:Function[1] | $f.applications->evaluateAndDeactivate()->concatenate($f.referenceUsages.owner->evaluateAndDeactivate())->add($element),
a:PackageableElement[1] | $a.referenceUsages->map(e|if($e->sourceInformation()->isEmpty(),|$e.owner,|$e))->add($element)
])->map(e | $e->sourceInformation())->removeDuplicates()->sortBy(s | $s.source + $s.line->toString());
}
function meta::pure::ide::findusages::findClassProperty(class:Class[1], propertyName:String[1]):AbstractProperty[1]
{
let property = $class.properties->concatenate($class.propertiesFromAssociations)->get($propertyName);
if
(
$property->isEmpty(),
| $class.qualifiedProperties->concatenate($class.qualifiedPropertiesFromAssociations)->get($propertyName),
| $property
)->toOne();
}
function meta::pure::ide::findusages::findUsagesForEnum(ownerPath:String[1], enumName:String[1]):SourceInformation[*]
{
$ownerPath->pathToElement().referenceUsages.owner
->map(x | $x->match([
iv:InstanceValue[1] | $iv->evaluateAndDeactivate().usageContext
->match([
pvsc:ParameterValueSpecificationContext[1] | $pvsc.functionExpression->match([
sfe:SimpleFunctionExpression[1] | $sfe
])
]),
any:Any[1] | []
]))
->filter(x | $x->evaluateAndDeactivate().parametersValues->at(1)->match([
iv:InstanceValue[1] | $iv.values == $enumName
]))
->map(x | $x->sourceInformation())
->removeDuplicates()->sortBy(s | $s.source + $s.line->toString());
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy