當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiFile.isValid方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiFile.isValid方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiFile.isValid方法的具體用法?Java PsiFile.isValid怎麽用?Java PsiFile.isValid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiFile的用法示例。


在下文中一共展示了PsiFile.isValid方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findProject

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
public static Project findProject(PsiElement element) {
	PsiFile containingFile = element.getContainingFile();
	if (containingFile == null) {
		if (!element.isValid()) {
			return null;
		}
	} else if (!containingFile.isValid()) {
		return null;
	}

	return (containingFile == null ? element : containingFile).getProject();
}
 
開發者ID:xylo,項目名稱:intellij-postfix-templates,代碼行數:13,代碼來源:CptUtil.java

示例2: getViewFile

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Nullable
public static PsiFile getViewFile(PsiElement element) {
    final MethodReference reference = PsiTreeUtil.getParentOfType(element, MethodReference.class);
    if (reference == null) {
        return null;
    }

    final PsiElement[] parameters = reference.getParameters();
    if (parameters.length == 0 || !(parameters[0] instanceof StringLiteralExpression)) {
        return null;
    }

    String view = reference.getUserData(RENDER_VIEW);
    if (!((StringLiteralExpression) parameters[0]).getContents().equals(view)) {
        view = ((StringLiteralExpression) parameters[0]).getContents();
        reference.putUserData(RENDER_VIEW, view);
        reference.putUserData(RENDER_VIEW_FILE, null);
        reference.putUserData(RENDER_VIEW_PATH, null);
    }

    PsiFile file = reference.getUserData(RENDER_VIEW_FILE);
    if (file != null && file.isValid()) {
        if (!file.getVirtualFile().getPath().equals(reference.getUserData(RENDER_VIEW_PATH))) {
            reference.putUserData(RENDER_VIEW_FILE, null);
            reference.putUserData(RENDER_VIEW_PATH, null);
            file = null;
        }
    }

    if (file == null || !file.isValid()) {
        if (reference.getParameters()[0] instanceof StringLiteralExpression) {
            PsiDirectory directory;

            String path = ((StringLiteralExpression) reference.getParameters()[0]).getContents();
            if (path.startsWith("/")) {
                directory = ViewsUtil.getRootDirectory(element);
                path = path.substring(1);
            } else {
                directory = ViewsUtil.getContextDirectory(element);
            }

            String filename;
            if (path.contains("/")) {
                filename = path.substring(path.lastIndexOf('/') + 1);
                path = path.substring(0, path.lastIndexOf('/') + 1);
            } else {
                filename = path;
                path = "";
            }

            while (path.contains("/") && directory != null) {
                final String dirName = path.substring(0, path.indexOf('/'));
                directory = dirName.equals("..") ? directory.getParent() : directory.findSubdirectory(dirName);
                path = path.substring(path.indexOf('/') + 1);
            }

            if (directory == null) {
                return null;
            }

            if (filename.contains(".")) {
                file = directory.findFile(filename);
            } else {
                file = directory.findFile(filename + ".php");
                if (file == null) {
                    file = directory.findFile(filename + ".twig");
                }
                if (file == null) {
                    file = directory.findFile(filename + ".tpl");
                }
            }

            if (file != null) {
                reference.putUserData(RENDER_VIEW_FILE, file);
                reference.putUserData(RENDER_VIEW_PATH, file.getVirtualFile().getPath());
            }
        }
    }

    return file;
}
 
開發者ID:nvlad,項目名稱:yii2support,代碼行數:82,代碼來源:ViewsUtil.java

示例3: buildVisitor

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean isOnTheFly) {
    return new PhpElementVisitor() {
        @Override
        public void visitPhpMethodReference(MethodReference reference) {
            if (!ViewsUtil.isValidRenderMethod(reference)) {
                return;
            }

            if (ArrayUtil.contains(reference.getName(), ViewsUtil.renderMethods)) {
                if (reference.getParameters().length > 0) {
                    PsiElement pathParameter = reference.getParameters()[0];
                    if (pathParameter instanceof StringLiteralExpression) {
                        String path = ((StringLiteralExpression) pathParameter).getContents();
                        if (path.startsWith("//") || path.startsWith("@")) {
                            return;
                        }
                        PhpClass clazz = ClassUtils.getPhpClassByCallChain(reference);
                        if (clazz != null) {
                            Method method = clazz.findMethodByName("getViewPath");
                            PhpIndex phpIndex = PhpIndex.getInstance(reference.getProject());
                            if (method != null) {
                                PhpClass containingClass = method.getContainingClass();
                                PhpClass controllerBaseClass = ClassUtils.getClass(phpIndex, "yii\\base\\Controller");
                                PhpClass widgetBaseClass = ClassUtils.getClass(phpIndex, "yii\\base\\Widget");
                                if (containingClass != controllerBaseClass && containingClass != widgetBaseClass) {
                                    return;
                                }
                            }
                        }

                        PsiFile file = ViewsUtil.getViewFile(pathParameter);
                        if (file == null || !file.isValid()) {
                            final String errorViewNotFoundTemplate = "View file for \"%name%\" not found.";
                            final MissedViewLocalQuickFix quickFix = new MissedViewLocalQuickFix(path);
                            final String descriptionTemplate = errorViewNotFoundTemplate.replace("%name%", path);
                            final PsiElement stringPart = pathParameter.findElementAt(1);
                            if (stringPart != null) {
                                problemsHolder.registerProblem(stringPart, descriptionTemplate, quickFix);
                            }
                        }
                    }
                }
            }
        }
    };
}
 
開發者ID:nvlad,項目名稱:yii2support,代碼行數:49,代碼來源:MissedViewInspection.java


注:本文中的com.intellij.psi.PsiFile.isValid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。