use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings in project Perl5-IDEA by Camelcade.
the class HTMLMasonFileImpl method getChildComponents.
@NotNull
public List<HTMLMasonFileImpl> getChildComponents() {
final List<HTMLMasonFileImpl> result = new ArrayList<>();
VirtualFile containingFile = getComponentVirtualFile();
if (containingFile != null) {
VirtualFile componentRoot = getComponentRoot();
if (componentRoot != null) {
final String relativePath = VfsUtil.VFS_SEPARATOR_CHAR + VfsUtil.getRelativePath(containingFile, componentRoot);
final Project project = getProject();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
final HTMLMasonFileImpl currentFile = this;
HTMLMasonSettings settings = HTMLMasonSettings.getInstance(project);
// indexed children
for (String parentPath : StubIndex.getInstance().getAllKeys(HTMLMasonFlagsStubIndex.KEY, project)) {
boolean isEquals = StringUtil.equals(relativePath, parentPath);
boolean isRelative = parentPath.length() == 0 || parentPath.charAt(0) != VfsUtil.VFS_SEPARATOR_CHAR;
for (HTMLMasonFlagsStatement statement : StubIndex.getElements(HTMLMasonFlagsStubIndex.KEY, parentPath, project, scope, HTMLMasonFlagsStatement.class)) {
PsiFile file = statement.getContainingFile();
if (file instanceof HTMLMasonFileImpl) {
if (isEquals || isRelative && currentFile.equals(((HTMLMasonFileImpl) file).getParentComponent())) {
result.add((HTMLMasonFileImpl) file);
}
}
}
}
// implicit autohandled children
if (StringUtil.equals(containingFile.getName(), settings.autoHandlerName)) {
collectAuthoHandledFiles(PsiManager.getInstance(project), containingFile.getParent(), result, settings.autoHandlerName, null);
}
}
}
return result;
}
use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings in project Perl5-IDEA by Camelcade.
the class HTMLMasonParserTest method addCustomTag.
private void addCustomTag(String text, HTMLMasonCustomTagRole role) {
HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
settings.customTags.add(new HTMLMasonCustomTag(text, role));
settings.settingsUpdated();
}
use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings in project Perl5-IDEA by Camelcade.
the class HTMLMasonArgsDefVariablesResolveTest method doTestResolve.
@Override
public void doTestResolve() {
HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
settings.globalVariables.add(new VariableDescription("$product", "Foo::Bar"));
settings.settingsUpdated();
super.doTestResolve();
}
use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings in project Perl5-IDEA by Camelcade.
the class HTMLMasonComponentReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
List<ResolveResult> result = null;
// looking subcomponents
String nameOrPath = getRangeInElement().substring(getElement().getText());
final PsiFile file = getElement().getContainingFile();
if (file instanceof HTMLMasonFileImpl) {
for (HTMLMasonCompositeElement subcomponentDefitnition : ((HTMLMasonFileImpl) file).getSubComponentsDefinitions()) {
assert subcomponentDefitnition instanceof HTMLMasonSubcomponentDefitnition;
if (StringUtil.equals(((HTMLMasonSubcomponentDefitnition) subcomponentDefitnition).getName(), nameOrPath)) {
if (result == null) {
result = new ArrayList<>();
}
result.add(new PsiElementResolveResult(subcomponentDefitnition));
}
}
}
// looking components
if (result == null) {
final Project project = file.getProject();
VirtualFile componentVirtualFile = null;
if (StringUtil.startsWith(nameOrPath, "/")) {
HTMLMasonSettings settings = HTMLMasonSettings.getInstance(project);
for (VirtualFile componentRoot : settings.getComponentsRoots()) {
componentVirtualFile = componentRoot.findFileByRelativePath(nameOrPath);
if (componentVirtualFile != null) {
break;
}
}
} else // possible relative path
{
VirtualFile containingFile = file.getVirtualFile();
if (containingFile != null) {
VirtualFile containingDir = containingFile.getParent();
componentVirtualFile = containingDir.findFileByRelativePath(nameOrPath);
}
}
if (componentVirtualFile != null) {
PsiFile componentFile = PsiManager.getInstance(project).findFile(componentVirtualFile);
if (componentFile instanceof HTMLMasonFileImpl) {
result = new ArrayList<>();
result.add(new PsiElementResolveResult(componentFile));
}
}
}
return result == null ? ResolveResult.EMPTY_ARRAY : result.toArray(new ResolveResult[result.size()]);
}
use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings in project Perl5-IDEA by Camelcade.
the class HTMLMasonFileImpl method getParentComponent.
@Nullable
public HTMLMasonFileImpl getParentComponent() {
String parentComponentPath = getParentComponentPath();
HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
VirtualFile parentFile = null;
if (// autohandler
parentComponentPath == null) {
VirtualFile containingFile = getComponentVirtualFile();
if (containingFile != null) {
VirtualFile startDir = containingFile.getParent();
if (StringUtil.equals(containingFile.getName(), settings.autoHandlerName)) {
startDir = startDir.getParent();
}
VirtualFile componentRoot = HTMLMasonUtil.getComponentRoot(getProject(), startDir);
if (componentRoot != null) {
while (VfsUtil.isAncestor(componentRoot, startDir, false)) {
if ((parentFile = startDir.findFileByRelativePath(settings.autoHandlerName)) != null) {
break;
}
startDir = startDir.getParent();
}
}
}
} else if (// Specific component
!StringUtil.equals(parentComponentPath, HTMLMasonFlagsStatement.UNDEF_RESULT)) {
if (// absolute path
StringUtil.startsWith(parentComponentPath, "/")) {
parentComponentPath = parentComponentPath.substring(1);
for (VirtualFile root : settings.getComponentsRoots()) {
if ((parentFile = root.findFileByRelativePath(parentComponentPath)) != null) {
break;
}
}
} else // relative path
{
VirtualFile containingVirtualFile = getComponentVirtualFile();
if (containingVirtualFile != null) {
VirtualFile containingDir = containingVirtualFile.getParent();
if (containingDir != null) {
parentFile = containingDir.findFileByRelativePath(parentComponentPath);
}
}
}
}
if (parentFile != null) {
PsiFile file = PsiManager.getInstance(getProject()).findFile(parentFile);
if (file instanceof HTMLMasonFileImpl) {
return (HTMLMasonFileImpl) file;
}
}
return null;
}
Aggregations