use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.
the class PodSubReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PsiElement element = getElement();
if (element != null) {
final Project project = element.getProject();
String subName = element.getText();
if (StringUtil.isNotEmpty(subName)) {
final PsiFile containingFile = element.getContainingFile();
String packageName = PodFileUtil.getPackageName(containingFile);
List<ResolveResult> results = new ArrayList<>();
if (StringUtil.isNotEmpty(packageName)) {
String canonicalName = packageName + PerlPackageUtil.PACKAGE_SEPARATOR + subName;
for (PerlSubDefinitionElement target : PerlSubUtil.getSubDefinitions(project, canonicalName)) {
results.add(new PsiElementResolveResult(target));
}
for (PerlSubDeclarationElement target : PerlSubUtil.getSubDeclarations(project, canonicalName)) {
results.add(new PsiElementResolveResult(target));
}
}
if (results.isEmpty()) {
final PsiFile perlFile = containingFile.getViewProvider().getStubBindingRoot();
for (PerlSubElement subBase : PsiTreeUtil.findChildrenOfType(perlFile, PerlSubElement.class)) {
String subBaseName = subBase.getName();
if (subBaseName != null && StringUtil.equals(subBaseName, subName)) {
results.add(new PsiElementResolveResult(subBase));
}
}
}
return results.toArray(new ResolveResult[results.size()]);
}
}
return ResolveResult.EMPTY_ARRAY;
}
use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.
the class PerlLightTestCase method serializePsiElement.
protected String serializePsiElement(@Nullable PsiElement element) {
if (element == null) {
return "null";
}
StringBuilder sb = new StringBuilder();
sb.append(element);
if (element instanceof PerlSubDefinitionElement) {
String argumentsList = ((PerlSubDefinitionElement) element).getSubArgumentsList().stream().map(argument -> {
if (argument.isOptional()) {
return "[" + argument.toStringLong() + "]";
} else {
return argument.toStringLong();
}
}).collect(Collectors.joining(", "));
if (StringUtil.isNotEmpty(argumentsList)) {
sb.append("(").append(argumentsList).append(")");
}
}
ASTNode node = element.getNode();
if (node != null) {
sb.append(" at ").append(node.getStartOffset()).append(" in ").append(element.getContainingFile().getName());
}
PsiElement navigationElement = element.getNavigationElement();
if (navigationElement == null) {
sb.append("; no navigation element;");
} else if (navigationElement != element) {
sb.append("; navigated to: ").append(serializePsiElement(navigationElement));
}
return sb.toString();
}
use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.
the class MethodsDetectionTest method doTest.
public void doTest(boolean result) {
initWithFileSmart(getTestName(false).toLowerCase());
PsiFile file = myFixture.getFile();
assertNotNull(file);
PerlSubDefinitionElement subDefinition = PsiTreeUtil.findChildOfType(file, PerlSubDefinitionElement.class);
assertNotNull(subDefinition);
if (result) {
assertTrue(subDefinition.isMethod());
} else {
assertFalse(subDefinition.isMethod());
}
}
use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.
the class PerlArgsExtractionTest method doTest.
protected void doTest(String fileName, String argsString) {
initWithFileSmart(fileName);
PsiElement elementAtCaret = myFixture.getElementAtCaret();
assertNotNull(elementAtCaret);
PerlSubDefinitionElement subBase = PsiTreeUtil.getParentOfType(elementAtCaret, PerlSubDefinitionElement.class, false);
assertNotNull(subBase);
assertEquals(argsString, subBase.getSubArgumentsListAsString());
}
use of com.perl5.lang.perl.psi.PerlSubDefinitionElement in project Perl5-IDEA by Camelcade.
the class PerlPackageUtil method processNotOverridedMethods.
public static void processNotOverridedMethods(final PerlNamespaceDefinitionElement namespaceDefinition, Processor<PerlSubElement> processor) {
if (namespaceDefinition != null) {
PsiFile containingFile = namespaceDefinition.getContainingFile();
String packageName = namespaceDefinition.getPackageName();
if (packageName == null) {
return;
}
Set<String> namesSet = new THashSet<>();
// collecting overrided
for (PerlSubDefinitionElement subDefinitionBase : PsiTreeUtil.findChildrenOfType(containingFile, PerlSubDefinitionElement.class)) {
if (subDefinitionBase.isValid() && StringUtil.equals(packageName, subDefinitionBase.getPackageName())) {
namesSet.add(subDefinitionBase.getSubName());
}
}
processParentClassesSubs(namespaceDefinition, namesSet, new THashSet<>(), processor);
}
}
Aggregations