use of com.perl5.lang.perl.psi.utils.PerlSubArgument in project Perl5-IDEA by Camelcade.
the class PerlSubDefinitionMixin method processSignatureElement.
@Override
protected boolean processSignatureElement(PsiElement signatureElement, List<PerlSubArgument> arguments) {
if (!super.processSignatureElement(signatureElement, arguments)) {
if (signatureElement instanceof PsiPerlSubSignatureElementIgnore) {
PerlSubArgument newArgument = PerlSubArgument.empty();
// has elements inside, means optional
newArgument.setOptional(signatureElement.getFirstChild() != signatureElement.getLastChild());
arguments.add(newArgument);
} else if (signatureElement.getNode().getElementType() == PerlElementTypes.OPERATOR_ASSIGN && arguments.size() > 0) {
// setting last element as optional
arguments.get(arguments.size() - 1).setOptional(true);
} else {
return false;
}
}
return true;
}
use of com.perl5.lang.perl.psi.utils.PerlSubArgument in project Perl5-IDEA by Camelcade.
the class PerlSubDefinitionElementType method deserialize.
@NotNull
@Override
public PerlSubDefinitionStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
// noinspection ConstantConditions
String packageName = dataStream.readName().getString();
// noinspection ConstantConditions
String functionName = dataStream.readName().getString();
List<PerlSubArgument> arguments = PerlSubArgument.deserializeList(dataStream);
PerlSubAnnotations annotations = null;
if (dataStream.readBoolean()) {
annotations = PerlSubAnnotations.deserialize(dataStream);
}
return createStubElement(parentStub, packageName, functionName, arguments, annotations);
}
use of com.perl5.lang.perl.psi.utils.PerlSubArgument in project Perl5-IDEA by Camelcade.
the class PerlBuiltInSubsService method readArguments.
@NotNull
private List<PerlSubArgument> readArguments(@Nullable Element argumentsElement, @NotNull String subName) {
if (argumentsElement == null) {
return Collections.emptyList();
}
List<Element> mandatoryElements = argumentsElement.getChildren(ARGUMENT_ELEMENT);
List<Element> optionalElements;
Element optionalElement = argumentsElement.getChild(OPTIONAL_ELEMENT);
if (optionalElement == null) {
optionalElements = Collections.emptyList();
} else {
optionalElements = optionalElement.getChildren(ARGUMENT_ELEMENT);
}
if (mandatoryElements.isEmpty() && optionalElements.isEmpty()) {
return Collections.emptyList();
}
List<PerlSubArgument> result = new ArrayList<>();
mandatoryElements.stream().map(element -> readArgument(element, false, subName)).filter(Objects::nonNull).forEach(result::add);
optionalElements.stream().map(element -> readArgument(element, true, subName)).filter(Objects::nonNull).forEach(result::add);
return result;
}
use of com.perl5.lang.perl.psi.utils.PerlSubArgument in project Perl5-IDEA by Camelcade.
the class PerlExceptionClassWrapper method processExceptionElement.
private void processExceptionElement(@NotNull List<PsiElement> listElements, int currentIndex, @NotNull List<PerlDelegatingLightNamedElement> result) {
PsiElement listElement = listElements.get(currentIndex);
if (!isAcceptableIdentifierElement(listElement)) {
return;
}
String namespaceName = ElementManipulators.getValueText(listElement);
if (StringUtil.isEmpty(namespaceName)) {
return;
}
Map<String, PerlHashEntry> exceptionSettings = listElements.size() > currentIndex + 1 ? PerlHashUtil.collectHashMap(listElements.get(currentIndex + 1)) : Collections.emptyMap();
// Building fields
Set<PerlSubArgument> throwArguments = Collections.emptySet();
PerlHashEntry fieldsEntry = exceptionSettings.get("fields");
if (fieldsEntry != null && fieldsEntry.isComplete()) {
PsiElement fieldsContainer = fieldsEntry.getNonNullValueElement();
if (fieldsContainer instanceof PsiPerlAnonArray) {
fieldsContainer = ((PsiPerlAnonArray) fieldsContainer).getExpr();
}
List<PsiElement> elements = PerlArrayUtil.collectListElements(fieldsContainer);
if (!elements.isEmpty()) {
// Fields method
result.add(new PerlLightMethodDefinitionElement<>(this, FIELDS_METHOD_NAME, LIGHT_METHOD_DEFINITION, fieldsEntry.keyElement, namespaceName, Collections.emptyList(), null));
// fields themselves
throwArguments = new LinkedHashSet<>();
for (PsiElement fieldElement : elements) {
if (isAcceptableIdentifierElement(fieldElement)) {
String fieldName = PerlScalarUtil.getStringContent(fieldElement);
if (StringUtil.isNotEmpty(fieldName)) {
throwArguments.add(PerlSubArgument.mandatoryScalar(fieldName));
result.add(new PerlLightMethodDefinitionElement<>(this, fieldName, LIGHT_METHOD_DEFINITION, fieldElement, namespaceName, Collections.emptyList(), null));
}
}
}
}
}
// making exception class
PerlHashEntry isaEntry = exceptionSettings.get("isa");
String parentClass = "Exception::Class::Base";
if (isaEntry != null && isaEntry.isComplete()) {
String manualIsa = isaEntry.getValueString();
if (manualIsa != null) {
parentClass = manualIsa;
}
}
result.add(new PerlLightExceptionClassDefinition(this, namespaceName, LIGHT_NAMESPACE_DEFINITION, listElement, PerlMroType.DFS, Collections.singletonList(parentClass), PerlNamespaceAnnotations.tryToFindAnnotations(listElement, getParent()), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap()));
// making alias
PerlHashEntry aliasEntry = exceptionSettings.get("alias");
if (aliasEntry != null && aliasEntry.isComplete()) {
if (isAcceptableIdentifierElement(aliasEntry.valueElement)) {
String aliasName = aliasEntry.getValueString();
if (StringUtils.isNotEmpty(aliasName)) {
result.add(new PerlLightSubDefinitionElement<>(this, aliasName, LIGHT_SUB_DEFINITION, aliasEntry.getNonNullValueElement(), PerlPackageUtil.getContextPackageName(this), new ArrayList<>(throwArguments), PerlSubAnnotations.tryToFindAnnotations(aliasEntry.keyElement, aliasEntry.valueElement)));
}
}
}
}
use of com.perl5.lang.perl.psi.utils.PerlSubArgument in project Perl5-IDEA by Camelcade.
the class HTMLMasonArgsBlockImpl method getArgumentsListHeavy.
@NotNull
protected List<PerlSubArgument> getArgumentsListHeavy() {
List<PerlSubArgument> result = new ArrayList<>();
PsiElement run = getFirstChild();
while (run != null) {
if (run instanceof PerlVariableDeclarationElement) {
PerlVariable variable = ((PerlVariableDeclarationElement) run).getVariable();
if (variable != null) {
PsiElement nextSibling = PerlPsiUtil.getNextSignificantSibling(run);
result.add(PerlSubArgument.create(variable.getActualType(), variable.getName(), nextSibling != null && nextSibling.getNode().getElementType() == FAT_COMMA));
}
}
run = run.getNextSibling();
}
return result;
}
Aggregations