use of com.perl5.lang.perl.psi.PerlString in project Perl5-IDEA by Camelcade.
the class PerlElementFactory method createBareString.
public static PerlString createBareString(Project project, String content) {
PerlFileImpl file = createFile(project, content + " => 42;");
PerlString string = PsiTreeUtil.findChildOfType(file, PerlString.class);
assert string != null : "While creating bare string from: " + content;
return string;
}
use of com.perl5.lang.perl.psi.PerlString in project Perl5-IDEA by Camelcade.
the class PerlMooseExtendsStatementImpl method getParentsList.
@NotNull
protected List<String> getParentsList() {
List<String> result = new ArrayList<>();
PsiElement expr = getExpr();
if (expr != null) {
if (expr instanceof PerlString) {
String content = ElementManipulators.getValueText(expr);
if (!content.isEmpty()) {
result.add(content);
}
} else if (expr instanceof PsiPerlCommaSequenceExpr) {
PsiElement element = expr.getFirstChild();
while (element != null) {
if (element instanceof PerlString) {
String content = ElementManipulators.getValueText(element);
if (!content.isEmpty()) {
result.add(content);
}
}
element = element.getNextSibling();
}
} else if (expr instanceof PsiPerlStringList) {
for (PsiElement element : PerlPsiUtil.collectStringElements(expr.getFirstChild())) {
String content = element.getText();
if (!content.isEmpty()) {
result.add(content);
}
}
} else {
// todo we need to somehow mark statement as bad
}
}
return result;
}
use of com.perl5.lang.perl.psi.PerlString in project Perl5-IDEA by Camelcade.
the class HTMLMasonComponentCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement position = parameters.getPosition();
PsiElement parent = position.getParent();
PsiFile file = position.getContainingFile();
if (parent instanceof PerlString && file instanceof HTMLMasonFileImpl) {
PsiReference[] references = parent.getReferences();
for (PsiReference reference : references) {
TextRange refRange = reference.getRangeInElement();
if (refRange.contains(position.getStartOffsetInParent())) {
Project project = position.getProject();
String fullPrefix = refRange.substring(parent.getText()).replace(CompletionInitializationContext.DUMMY_IDENTIFIER, "").replace(CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED, "");
final CompletionResultSet finalResultSet = result.withPrefixMatcher(fullPrefix);
;
if (reference instanceof HTMLMasonMethodReference) {
PsiElement firstReferenceTarget = references[0].resolve();
if (firstReferenceTarget instanceof HTMLMasonFileImpl) {
HTMLMasonCompletionUtil.fillWithMethods(finalResultSet, (HTMLMasonFileImpl) firstReferenceTarget);
}
} else {
HTMLMasonCompletionUtil.fillWithComponentSlugs(finalResultSet);
HTMLMasonCompletionUtil.fillWithSubcomponents(finalResultSet, (HTMLMasonFileImpl) file);
if (!StringUtil.startsWith(fullPrefix, "/")) {
HTMLMasonCompletionUtil.fillWithRelativeSubcomponents(finalResultSet, project, (HTMLMasonFileImpl) file);
} else {
HTMLMasonCompletionUtil.fillWithAbsoluteSubcomponents(finalResultSet, project);
}
}
result.stopHere();
break;
}
}
}
}
use of com.perl5.lang.perl.psi.PerlString in project Perl5-IDEA by Camelcade.
the class HTMLMasonMethodReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PerlString element = getElement();
String methodName = getRangeInElement().substring(element.getText());
if (StringUtil.isNotEmpty(methodName)) {
PsiReference[] references = element.getReferences();
if (references.length == 2) {
PsiReference componentReference = references[0];
PsiElement startComponent = componentReference.resolve();
if (startComponent instanceof HTMLMasonFileImpl) {
HTMLMasonMethodDefinition methodDefinition = ((HTMLMasonFileImpl) startComponent).findMethodDefinitionByNameInThisOrParents(methodName);
if (methodDefinition != null) {
return new ResolveResult[] { new PsiElementResolveResult(methodDefinition) };
}
}
}
}
return ResolveResult.EMPTY_ARRAY;
}
use of com.perl5.lang.perl.psi.PerlString in project Perl5-IDEA by Camelcade.
the class HTMLMasonElementFactory method getBareCallString.
@Nullable
public static PerlString getBareCallString(Project project, String content) {
String fileContent = "<& " + content + "&>";
HTMLMasonFileImpl file = createFile(project, fileContent);
return PsiTreeUtil.findChildOfType(file, PerlString.class);
}
Aggregations