@Override public boolean isReferenceTo(PsiElement element) { return GoUtil.couldBeReferenceTo(element, getElement()) && getElement().getManager().areElementsEquivalent(resolve(), element); } };
@Nullable public static GoFile findBuiltinFile(@NotNull PsiElement context) { Project project = context.getProject(); // it's important to ask module on file, otherwise module won't be found for elements in libraries files [zolotov] Module moduleFromContext = ModuleUtilCore.findModuleForPsiElement(context.getContainingFile()); if (moduleFromContext == null) { for (Module module : ModuleManager.getInstance(project).getModules()) { if (GoSdkService.getInstance(project).isGoModule(module)) { moduleFromContext = module; break; } } } Module module = moduleFromContext; UserDataHolder holder = ObjectUtils.notNull(module, project); VirtualFile file = CachedValuesManager.getManager(context.getProject()).getCachedValue(holder, () -> { VirtualFile sdkSrcDir = getSdkSrcDir(project, module); VirtualFile result = sdkSrcDir != null ? sdkSrcDir.findFileByRelativePath(GoConstants.BUILTIN_FILE_PATH) : null; return CachedValueProvider.Result.create(result, getSdkAndLibrariesCacheDependencies(project, module, result)); }); if (file == null) return null; PsiFile psiBuiltin = context.getManager().findFile(file); return psiBuiltin instanceof GoFile ? (GoFile)psiBuiltin : null; }
final VirtualFile root = isOuterFile ? contextVirtualFile : ((parent != null) ? parent.getVirtualFile() : null); final PsiManager psiManager = getElement().getManager();
public PerlDelegatingLightElement(@NotNull Delegate delegate, @NotNull IElementType elementType) { super(delegate.getManager(), delegate.getLanguage()); myDelegate = delegate; myElementType = elementType; }
@Override public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) { return declaration.getManager().isInProject(declaration) ? Visibility.VISIBLE : Visibility.NOT_VISIBLE; } };
@Override public PsiManager getManager() { return getDelegate().getManager(); }
private PsiCapturedWildcardType(@NotNull PsiWildcardType existential, @NotNull PsiElement context, @Nullable PsiTypeParameter parameter) { super(PsiAnnotation.EMPTY_ARRAY); myExistential = existential; myContext = context; myParameter = parameter; myUpperBound = PsiType.getJavaLangObject(myContext.getManager(), getResolveScope()); }
@NotNull public static PerlImplicitVariableDeclaration create(@NotNull PsiElement parent, @NotNull String variableName, @Nullable String variableClass, boolean isLexical, boolean isLocal, boolean isInvocant ) { return new PerlImplicitVariableDeclaration( parent.getManager(), variableName, variableClass, isLexical, isLocal, isInvocant, parent ); } }
public static MonkeyFunctionDeclaration getTestMethod(PsiElement element, boolean checkAbstract, boolean checkRunWith) { PsiManager manager = element.getManager(); Location<PsiElement> location = PsiLocation.fromPsiElement(manager.getProject(), element); Iterator<Location<MonkeyFunctionDeclaration>> iterator = location.getAncestors(MonkeyFunctionDeclaration.class, false); Location<MonkeyFunctionDeclaration> methodLocation; do { if (!iterator.hasNext()) { return null; } methodLocation = iterator.next(); } while (!isTestMethod(methodLocation, checkAbstract, checkRunWith)); return methodLocation.getPsiElement(); }
@Nullable public static PsiType createJavaLangClassType(@NotNull PsiElement context, @Nullable PsiType qualifierType, boolean captureTopLevelWildcards) { if (qualifierType != null) { PsiUtil.ensureValidType(qualifierType); JavaPsiFacade facade = JavaPsiFacade.getInstance(context.getProject()); PsiClass javaLangClass = facade.findClass(CommonClassNames.JAVA_LANG_CLASS, context.getResolveScope()); if (javaLangClass != null && javaLangClass.getTypeParameters().length == 1) { PsiSubstitutor substitutor = PsiSubstitutor.EMPTY. put(javaLangClass.getTypeParameters()[0], PsiWildcardType.createExtends(context.getManager(), qualifierType)); final PsiClassType classType = facade.getElementFactory().createType(javaLangClass, substitutor, PsiUtil.getLanguageLevel(context)); return captureTopLevelWildcards ? PsiUtil.captureToplevelWildcards(classType, context) : classType; } } return null; }