package com.taobao.weex.tags;

import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.taobao.weex.lint.Attribute;
import com.taobao.weex.lint.DirectiveLint;
import com.taobao.weex.lint.WeexTag;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created by moxun on 16/10/25.
 */
public class ContextTagResolver {
    public static List<WeexTag> resolve(PsiElement any) {
        List<WeexTag> result = new ArrayList<WeexTag>();
        PsiFile file = any.getContainingFile();
        PsiDirectory directory = file.getOriginalFile().getContainingDirectory();
        PsiFile[] files = directory.getFiles();
        for (PsiFile p : files) {
            if (!p.getName().equals(any.getContainingFile().getName())) {
                WeexTag common = DirectiveLint.getCommonTag();
                if (common != null) {
                    WeexTag fake = new WeexTag();
                    fake.tag = p.getName().replace(".we","");
                    fake.attrs = new CopyOnWriteArrayList<Attribute>(common.attrs);
                    fake.declare = p;
                    result.add(fake);
                }
            }
        }
        return result;
    }
}

@@ -669,24 +669,197 @@
 irectory();%0A
+        if (directory == null) %7B%0A            directory = file.getOriginalFile().getParent();%0A        %7D%0A        if (directory == null) %7B%0A            return result;%0A        %7D%0A
         PsiF
@@ -1210,16 +1210,17 @@
 e(%22.we%22,
+ 
 %22%22);%0A   

fix #5