protected Collection<PsiElement> classGoToDeclaration(PsiElement psiElement, String className) { Collection<PsiElement> psiElements = new HashSet<PsiElement>(); // Class::method // Class::FooAction // Class:Foo if (className.contains(":")) { String[] split = className.replaceAll("(:)\\1", "$1").split(":"); if (split.length == 2) { for (String append : new String[] {"", "Action"}) { Method classMethod = PhpElementsUtil.getClassMethod(psiElement.getProject(), split[0], split[1] + append); if (classMethod != null) { psiElements.add(classMethod); } } } return psiElements; } // ClassName psiElements.addAll(PhpElementsUtil.getClassesInterface(psiElement.getProject(), className)); return psiElements; }
@Nullable @Override public String getType(PsiElement e) { if (DumbService.getInstance(e.getProject()).isDumb() || !Settings.getInstance(e.getProject()).pluginEnabled || !Settings.getInstance(e.getProject()).objectManagerFindTypeProvider) { return null; } if (!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "find")) { return null; } String refSignature = ((MethodReference) e).getSignature(); if (StringUtil.isEmpty(refSignature)) { return null; } // we need the param key on getBySignature(), since we are already in the resolved method there // attach it to signature // param can have dotted values split with \ PsiElement[] parameters = ((MethodReference) e).getParameters(); if (parameters.length == 2) { return PhpTypeProviderUtil.getReferenceSignature((MethodReference) e, TRIM_KEY, 2); } return null; }
@Nullable @Override public PhpType getType(PsiElement e) { if (DumbService.getInstance(e.getProject()).isDumb()) { return null; } if (!ContainerGetHelper.isContainerGetCall(e)) { return null; } String serviceId = ContainerGetHelper.getServiceId((MethodReference) e); if (null == serviceId) { return null; } Symfony2ProjectComponent symfony2ProjectComponent = e.getProject().getComponent(Symfony2ProjectComponent.class); ServiceMap serviceMap = symfony2ProjectComponent.getServicesMap(); if (null == serviceMap) { return null; } String serviceClass = serviceMap.getMap().get(serviceId); if (null == serviceClass) { return null; } return new PhpType().add(serviceClass); }
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { if (ApplicationManager.getApplication().isUnitTestMode()) { return null; } if (!(element instanceof PsiMethod) && !(element instanceof PsiClass)) { return null; } if (!PsiUtil.isPluginProject(element.getProject())) { return null; } final VirtualFile file = PsiUtilCore.getVirtualFile(element); if (file == null || !ProjectFileIndex.SERVICE .getInstance(element.getProject()) .isInTestSourceContent(file)) { return null; } if (element instanceof PsiMethod) { final PsiMethod method = (PsiMethod) element; if (isTestMethod(method)) { return new LineMarkerInfo<PsiMethod>( method, method.getModifierList().getTextRange(), PlatformIcons.TEST_SOURCE_FOLDER, Pass.UPDATE_ALL, null, new TestDataNavigationHandler(), GutterIconRenderer.Alignment.LEFT); } } else { final PsiClass psiClass = (PsiClass) element; final String basePath = getTestDataBasePath(psiClass); if (basePath != null) { PsiModifierList modifierList = psiClass.getModifierList(); assert modifierList != null; return new LineMarkerInfo<PsiClass>( psiClass, modifierList.getTextRange(), PlatformIcons.TEST_SOURCE_FOLDER, Pass.UPDATE_ALL, new TooltipProvider(basePath), new GutterIconNavigationHandler<PsiClass>() { @Override public void navigate(MouseEvent e, PsiClass elt) { final VirtualFile baseDir = VfsUtil.findFileByIoFile(new File(basePath), true); if (baseDir != null) { new OpenFileDescriptor(psiClass.getProject(), baseDir).navigate(true); } } }, GutterIconRenderer.Alignment.LEFT); } } return null; }
public void showParameterInfo(@NotNull PsiElement element, CreateParameterInfoContext context) { ResolveResult[] variants = ResolveResult.EMPTY_ARRAY; if (element instanceof PsiPolyVariantReference) { variants = ((PsiPolyVariantReference) element).multiResolve(true); if (variants.length != 0) { context.setItemsToShow( ContainerUtil.map2Array( variants, CfmlFunctionDescription.class, new Function<ResolveResult, CfmlFunctionDescription>() { public CfmlFunctionDescription fun(ResolveResult resolveResult) { final PsiElement element1 = resolveResult.getElement(); if (CfmlPsiUtil.isFunctionDefinition(element1)) { CfmlFunction function = CfmlPsiUtil.getFunctionDefinition(element1); if (function != null) { return function.getFunctionInfo(); } } else if (element1 instanceof PsiMethod) { PsiMethod function = (PsiMethod) element1; CfmlFunctionDescription javaMethodDescr = new CfmlFunctionDescription( function.getName(), function.getReturnType().getPresentableText()); final PsiParameter[] psiParameters = function.getParameterList().getParameters(); final int paramsNum = psiParameters.length; for (int i = 0; i < paramsNum; i++) { PsiParameter psiParameter = psiParameters[i]; javaMethodDescr.addParameter( new CfmlFunctionDescription.CfmlParameterDescription( psiParameter.getName(), psiParameter.getType().getPresentableText(), true)); } return javaMethodDescr; } return null; } })); context.showHint(element, element.getTextRange().getStartOffset(), this); return; } } if (element instanceof CfmlReferenceExpression) { String functionName = element.getText().toLowerCase(); if (ArrayUtil.find( CfmlLangInfo.getInstance(element.getProject()).getPredefinedFunctionsLowCase(), functionName) != -1) { context.setItemsToShow( new Object[] { CfmlLangInfo.getInstance(element.getProject()) .getFunctionParameters() .get(functionName) }); context.showHint(element, element.getTextRange().getStartOffset(), this); } } }
public static String cleanRefIdForPsiElement(PsiElement element) { final Language language = element.getLanguage(); if (language instanceof JavaLanguage) { if (element instanceof PsiModifierList) { PsiAnnotation[] annotations = ((PsiAnnotationOwner) element).getAnnotations(); for (PsiAnnotation annotation : annotations) { if (AnnoRefConfigSettings.getInstance(element.getProject()) .getAnnoRefState() .ANNOREF_ANNOTATION_FQN .equals(annotation.getQualifiedName())) { String refKey = SQLRefNamingUtil.cleanAnnoRefForName(annotation.getContainingFile(), annotation); if (refKey != null) { return refKey; } } } } if (element instanceof PsiAnnotation) { final PsiAnnotation psiAnnotation = (PsiAnnotation) element; if (AnnoRefConfigSettings.getInstance(element.getProject()) .getAnnoRefState() .ANNOREF_ANNOTATION_FQN .equals(psiAnnotation.getQualifiedName())) { String cleanedAnnoRef = SQLRefNamingUtil.cleanAnnoRefForName( psiAnnotation.getContainingFile(), psiAnnotation); if (cleanedAnnoRef != null) { return cleanedAnnoRef; } } if (element instanceof PsiJavaToken && ((PsiJavaToken) element).getTokenType() == JavaTokenType.STRING_LITERAL) { final String refKey = StringUtils.cleanQuote(element.getText()); if (refKey != null) { return refKey; } } } } if (language instanceof XMLLanguage) { if (SQLRefNamingUtil.isPropitiousXmlFile(element.getContainingFile())) { final boolean isXmlTokenValid = new FilterElementProcessor( new XmlTokenTypeFilter(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)) .execute(element); if (isXmlTokenValid) { final String refKey = getSqlRefKey(element); if (refKey != null) { return refKey; } } } } return null; }
public static PsiClass getTypeOfElement(PsiElement element) { final String name; if (element instanceof PsiVariable) { name = Util.getErasedCanonicalText(((PsiVariable) element).getType().getCanonicalText()); } else { return null; } return JavaPsiFacade.getInstance(element.getProject()) .findClass(name, GlobalSearchScope.allScope(element.getProject())); }
/** * Try to visit possible class name for PsiElements with text like "Foo\|Bar", "Foo|\Bar", * "\Foo|\Bar" Cursor must have position in PsiElement * * @param psiElement the element context, cursor should be in it * @param cursorOffset current cursor editor eg from completion context * @param visitor callback on matching class */ public static void visitNamespaceClassForCompletion( PsiElement psiElement, int cursorOffset, ClassForCompletionVisitor visitor) { int cursorOffsetClean = cursorOffset - psiElement.getTextOffset(); if (cursorOffsetClean < 1) { return; } String content = psiElement.getText(); int length = content.length(); if (!(length >= cursorOffsetClean)) { return; } String beforeCursor = content.substring(0, cursorOffsetClean); boolean isValid; // espend\|Container, espend\Cont|ainer <- fallback to last full namespace // espend|\Container <- only on known namespace "espend" String namespace = beforeCursor; // if no backslash or its equal in first position, fallback on namespace completion int lastSlash = beforeCursor.lastIndexOf("\\"); if (lastSlash <= 0) { isValid = PhpIndexUtil.hasNamespace(psiElement.getProject(), beforeCursor); } else { isValid = true; namespace = beforeCursor.substring(0, lastSlash); } if (!isValid) { return; } // format namespaces and add prefix for fluent completion String prefix = ""; if (namespace.startsWith("\\")) { prefix = "\\"; } else { namespace = "\\" + namespace; } // search classes in current namespace and child namespaces for (PhpClass phpClass : PhpIndexUtil.getPhpClassInsideNamespace(psiElement.getProject(), namespace)) { String presentableFQN = phpClass.getPresentableFQN(); if (presentableFQN != null && fr.adrienbrault.idea.symfony2plugin.util.StringUtils.startWithEqualClassname( presentableFQN, beforeCursor)) { visitor.visit(phpClass, presentableFQN, prefix); } } }
@NotNull public Collection<PsiElement> findTestsForClass(@NotNull PsiElement element) { PsiClass klass = findSourceElement(element); if (klass == null) return Collections.emptySet(); GlobalSearchScope scope; Module module = getModule(element); if (module != null) { scope = GlobalSearchScope.moduleWithDependentsScope(module); } else { scope = GlobalSearchScope.projectScope(element.getProject()); } PsiShortNamesCache cache = JavaPsiFacade.getInstance(element.getProject()).getShortNamesCache(); String klassName = klass.getName(); Pattern pattern = Pattern.compile(".*" + klassName + ".*"); List<Pair<PsiClass, Integer>> classesWithProximities = new ArrayList<Pair<PsiClass, Integer>>(); HashSet<String> names = new HashSet<String>(); cache.getAllClassNames(names); for (String eachName : names) { if (pattern.matcher(eachName).matches()) { for (PsiClass eachClass : cache.getClassesByName(eachName, scope)) { if (TestUtil.isTestClass(eachClass)) { classesWithProximities.add( new Pair<PsiClass, Integer>(eachClass, calcTestNameProximity(klassName, eachName))); } } } } Collections.sort( classesWithProximities, new Comparator<Pair<PsiClass, Integer>>() { public int compare(Pair<PsiClass, Integer> o1, Pair<PsiClass, Integer> o2) { int result = o1.second.compareTo(o2.second); if (result == 0) { result = o1.first.getName().compareTo(o2.first.getName()); } return result; } }); List<PsiElement> result = new ArrayList<PsiElement>(); for (Pair<PsiClass, Integer> each : classesWithProximities) { result.add(each.first); } return result; }
public KotlinPrimaryConstructorParameterTableModel( KotlinMethodDescriptor methodDescriptor, PsiElement typeContext, PsiElement defaultValueContext) { super( methodDescriptor, typeContext, defaultValueContext, new ValVarColumn(), new NameColumn(typeContext.getProject()), new TypeColumn(typeContext.getProject(), KotlinFileType.INSTANCE), new DefaultValueColumn< KotlinParameterInfo, ParameterTableModelItemBase<KotlinParameterInfo>>( typeContext.getProject(), KotlinFileType.INSTANCE)); }
private void fixReferencesToStatic(PsiElement classMember) throws IncorrectOperationException { final StaticReferencesCollector collector = new StaticReferencesCollector(); classMember.accept(collector); ArrayList<PsiJavaCodeReferenceElement> refs = collector.getReferences(); ArrayList<PsiElement> members = collector.getReferees(); ArrayList<PsiClass> classes = collector.getRefereeClasses(); PsiElementFactory factory = JavaPsiFacade.getInstance(classMember.getProject()).getElementFactory(); for (int i = 0; i < refs.size(); i++) { PsiJavaCodeReferenceElement ref = refs.get(i); PsiElement namedElement = members.get(i); PsiClass aClass = classes.get(i); if (namedElement instanceof PsiNamedElement) { PsiReferenceExpression newRef = (PsiReferenceExpression) factory.createExpressionFromText( "a." + ((PsiNamedElement) namedElement).getName(), null); PsiExpression qualifierExpression = newRef.getQualifierExpression(); assert qualifierExpression != null; qualifierExpression = (PsiExpression) qualifierExpression.replace(factory.createReferenceExpression(aClass)); qualifierExpression.putCopyableUserData(PRESERVE_QUALIFIER, ref.isQualified()); ref.replace(newRef); } } }
@NotNull @Override public Collection<PsiReference> findReferences(PsiElement element) { assert element instanceof GrField; ArrayList<PsiReference> refs = new ArrayList<>(); GrField field = (GrField) element; GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject()); PsiMethod setter = field.getSetter(); if (setter != null) { refs.addAll( RenameAliasedUsagesUtil.filterAliasedRefs( MethodReferencesSearch.search(setter, projectScope, true).findAll(), setter)); } GrAccessorMethod[] getters = field.getGetters(); for (GrAccessorMethod getter : getters) { refs.addAll( RenameAliasedUsagesUtil.filterAliasedRefs( MethodReferencesSearch.search(getter, projectScope, true).findAll(), getter)); } refs.addAll( RenameAliasedUsagesUtil.filterAliasedRefs( ReferencesSearch.search(field, projectScope, false).findAll(), field)); return refs; }
private static void qualify(PsiMember member, PsiElement renamed, String name) { if (!(renamed instanceof GrReferenceExpression)) return; final PsiClass clazz = member.getContainingClass(); if (clazz == null) return; final GrReferenceExpression refExpr = (GrReferenceExpression) renamed; if (refExpr.getQualifierExpression() != null) return; final PsiElement replaced; if (member.hasModifierProperty(PsiModifier.STATIC)) { final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) .createReferenceExpressionFromText(clazz.getQualifiedName() + "." + name); replaced = refExpr.replace(newRefExpr); } else { final PsiClass containingClass = PsiTreeUtil.getParentOfType(renamed, PsiClass.class); if (member.getManager().areElementsEquivalent(containingClass, clazz)) { final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) .createReferenceExpressionFromText("this." + name); replaced = refExpr.replace(newRefExpr); } else { final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) .createReferenceExpressionFromText(clazz.getQualifiedName() + ".this." + name); replaced = refExpr.replace(newRefExpr); } } JavaCodeStyleManager.getInstance(replaced.getProject()).shortenClassReferences(replaced); }
@Override public void apply( @NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) { PsiFile file = startElement.getContainingFile(); if (file instanceof XmlFile) { ResourceFolderType folderType = ResourceHelper.getFolderType(file); if (folderType != null) { if (folderType != ResourceFolderType.VALUES) { forkResourceFile((XmlFile) file, myFolder, true); } else { XmlTag tag = getValueTag(PsiTreeUtil.getParentOfType(startElement, XmlTag.class, false)); if (tag != null) { AndroidFacet facet = AndroidFacet.getInstance(startElement); if (facet != null) { PsiDirectory dir = null; if (myFolder != null) { PsiDirectory resFolder = findRes(file); if (resFolder != null) { dir = resFolder.findSubdirectory(myFolder); if (dir == null) { dir = resFolder.createSubdirectory(myFolder); } } } forkResourceValue(startElement.getProject(), tag, file, facet, dir); } } } } } }
@NotNull private static String getPresentableElementPosition( @NotNull final CodeInsightTestFixture fixture, final @Nullable PsiElement element) { if (element == null) return ""; final StringBuilder buf = new StringBuilder(element.getText()); DartComponent component = PsiTreeUtil.getParentOfType(element, DartComponent.class); while (component != null) { final DartComponentName componentName = component.getComponentName(); if (componentName != null && componentName != element) { buf.insert(0, component.getName() + " -> "); } component = PsiTreeUtil.getParentOfType(component, DartComponent.class); } String path = element instanceof PsiDirectoryImpl ? ((PsiDirectoryImpl) element).getVirtualFile().getPath() : element.getContainingFile().getVirtualFile().getPath(); final String contentRoot = ModuleRootManager.getInstance(fixture.getModule()).getContentRoots()[0].getPath(); if (path.equals(contentRoot)) path = "[content root]"; final String contentRootWithSlash = contentRoot + "/"; if (path.startsWith(contentRootWithSlash)) path = path.substring(contentRootWithSlash.length()); final DartSdk sdk = DartSdk.getDartSdk(element.getProject()); if (sdk != null && path.startsWith(sdk.getHomePath())) path = "[Dart SDK]" + path.substring(sdk.getHomePath().length()); if (buf.length() > 0) buf.insert(0, " -> "); buf.insert(0, path); return buf.toString(); }
@NotNull private static PyExpression invertExpression(@NotNull final PsiElement expression) { final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(expression.getProject()); if (expression instanceof PyBoolLiteralExpression) { final String value = ((PyBoolLiteralExpression) expression).getValue() ? PyNames.FALSE : PyNames.TRUE; return elementGenerator.createExpressionFromText(LanguageLevel.forElement(expression), value); } if (expression instanceof PyReferenceExpression && (PyNames.FALSE.equals(expression.getText()) || PyNames.TRUE.equals(expression.getText()))) { final String value = PyNames.TRUE.equals(expression.getText()) ? PyNames.FALSE : PyNames.TRUE; return elementGenerator.createExpressionFromText(LanguageLevel.forElement(expression), value); } else if (expression instanceof PyPrefixExpression) { if (((PyPrefixExpression) expression).getOperator() == PyTokenTypes.NOT_KEYWORD) { final PyExpression operand = ((PyPrefixExpression) expression).getOperand(); if (operand != null) return elementGenerator.createExpressionFromText( LanguageLevel.forElement(expression), operand.getText()); } } return elementGenerator.createExpressionFromText( LanguageLevel.forElement(expression), "not " + expression.getText()); }
private void updateEditorText() { disposeNonTextEditor(); final PsiElement elt = myElements[myIndex].getNavigationElement(); Project project = elt.getProject(); PsiFile psiFile = getContainingFile(elt); final VirtualFile vFile = psiFile.getVirtualFile(); if (vFile == null) return; final FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(project, vFile); for (FileEditorProvider provider : providers) { if (provider instanceof TextEditorProvider) { updateTextElement(elt); myBinarySwitch.show(myViewingPanel, TEXT_PAGE_KEY); break; } else if (provider.accept(project, vFile)) { myCurrentNonTextEditorProvider = provider; myNonTextEditor = myCurrentNonTextEditorProvider.createEditor(project, vFile); myBinaryPanel.removeAll(); myBinaryPanel.add(myNonTextEditor.getComponent()); myBinarySwitch.show(myViewingPanel, BINARY_PAGE_KEY); break; } } }
@NotNull @Override public Collection<PsiReference> findReferences(final PsiElement element) { if (element instanceof GrField) { ArrayList<PsiReference> refs = new ArrayList<PsiReference>(); GrField field = (GrField) element; PsiMethod setter = GroovyPropertyUtils.findSetterForField(field); GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject()); if (setter != null && setter instanceof GrAccessorMethod) { refs.addAll( RenameAliasedUsagesUtil.filterAliasedRefs( MethodReferencesSearch.search(setter, projectScope, true).findAll(), setter)); } GrAccessorMethod[] getters = field.getGetters(); for (GrAccessorMethod getter : getters) { refs.addAll( RenameAliasedUsagesUtil.filterAliasedRefs( MethodReferencesSearch.search(getter, projectScope, true).findAll(), getter)); } refs.addAll( RenameAliasedUsagesUtil.filterAliasedRefs( ReferencesSearch.search(field, projectScope, true).findAll(), field)); return refs; } return super.findReferences(element); }
public AddModuleDependencyFix( Module currentModule, VirtualFile classVFile, PsiClass[] classes, PsiReference reference) { final PsiElement psiElement = reference.getElement(); final Project project = psiElement.getProject(); final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); for (PsiClass aClass : classes) { if (!facade.getResolveHelper().isAccessible(aClass, psiElement, aClass)) continue; PsiFile psiFile = aClass.getContainingFile(); if (psiFile == null) continue; VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) continue; final Module classModule = fileIndex.getModuleForFile(virtualFile); if (classModule != null && classModule != currentModule && !ModuleRootManager.getInstance(currentModule).isDependsOn(classModule)) { myModules.add(classModule); } } myCurrentModule = currentModule; myClassVFile = classVFile; myClasses = classes; myReference = reference; }
@Nullable public static PsiReferenceExpression createMockReference( final PsiElement place, @NotNull PsiType qualifierType, LookupElement qualifierItem) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject()); if (qualifierItem.getObject() instanceof PsiClass) { final String qname = ((PsiClass) qualifierItem.getObject()).getQualifiedName(); if (qname == null) return null; final String text = qname + ".xxx"; try { final PsiExpression expr = factory.createExpressionFromText(text, place); if (expr instanceof PsiReferenceExpression) { return (PsiReferenceExpression) expr; } return null; // ignore ill-formed qualified names like "org.spark-project.jetty" that can't // be used from Java code anyway } catch (IncorrectOperationException e) { LOG.info(e); return null; } } return (PsiReferenceExpression) factory.createExpressionFromText( "xxx.xxx", JavaCompletionUtil.createContextWithXxxVariable(place, qualifierType)); }
@Override protected void addCompletions( @NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement position = completionParameters.getPosition(); if (!Symfony2ProjectComponent.isEnabled(position)) { return; } YAMLCompoundValue yamlCompoundValue = PsiTreeUtil.getParentOfType(position, YAMLCompoundValue.class); if (yamlCompoundValue == null) { return; } String className = YamlHelper.getYamlKeyValueAsString(yamlCompoundValue, "targetEntity", false); if (className == null) { return; } PhpClass phpClass = PhpElementsUtil.getClass(position.getProject(), className); if (phpClass == null) { return; } for (DoctrineModelField field : EntityHelper.getModelFields(phpClass)) { if (field.getRelation() != null) { completionResultSet.addElement(new DoctrineModelFieldLookupElement(field)); } } }
@Override protected void addCompletions( @NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { if (!Symfony2ProjectComponent.isEnabled(completionParameters.getPosition())) { return; } PsiElement psiElement = completionParameters.getPosition(); YAMLCompoundValue yamlCompoundValue = PsiTreeUtil.getParentOfType(psiElement, YAMLCompoundValue.class); if (yamlCompoundValue == null) { return; } yamlCompoundValue = PsiTreeUtil.getParentOfType(yamlCompoundValue, YAMLCompoundValue.class); if (yamlCompoundValue == null) { return; } String value = YamlHelper.getYamlKeyValueAsString(yamlCompoundValue, "class", true); if (value != null) { PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), value); if (phpClass != null) { FormUtil.attachFormAliasesCompletions(phpClass, completionResultSet); } } }
@Override protected void addCompletions( @NotNull CompletionParameters parameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement position = parameters.getPosition(); if (!Symfony2ProjectComponent.isEnabled(position)) { return; } PsiElement prevSiblingOfType = PsiElementUtils.getPrevSiblingOfType( position, YamlElementPatternHelper.getPreviousCommaSibling()); if (prevSiblingOfType == null) { return; } String service = PsiElementUtils.trimQuote(prevSiblingOfType.getText()); if (StringUtils.isBlank(service)) { return; } PhpClass phpClass = ServiceUtil.getServiceClass(prevSiblingOfType.getProject(), service); if (phpClass == null) { return; } for (Method method : phpClass.getMethods()) { if (method.getAccess().isPublic() && !(method.getName().startsWith("__"))) { completionResultSet.addElement(new PhpLookupElement(method)); } } }
@Nullable @Override public InspectionToolWrapper getEnabledTool( @Nullable PsiElement element, boolean includeDoNotShow) { if (!myEnabled) return null; if (myTools != null && element != null) { final Project project = element.getProject(); final DependencyValidationManager manager = DependencyValidationManager.getInstance(project); for (ScopeToolState state : myTools) { final NamedScope scope = state.getScope(project); if (scope != null) { final PackageSet set = scope.getValue(); if (set != null && set.contains(element.getContainingFile(), manager)) { return state.isEnabled() && (includeDoNotShow || !HighlightDisplayLevel.DO_NOT_SHOW.equals(state.getLevel())) ? state.getTool() : null; } } } } return myDefaultState.isEnabled() && (includeDoNotShow || !HighlightDisplayLevel.DO_NOT_SHOW.equals(myDefaultState.getLevel())) ? myDefaultState.getTool() : null; }
public TextRange getTextRangeForNavigation() { TextRange textRange = getTextRange(); if (textRange == null) return null; PsiElement element = getPsiElement(); return InjectedLanguageManager.getInstance(element.getProject()) .injectedToHost(element, textRange); }
public void addCompletions( @NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { PsiElement element = parameters.getPosition().getParent(); Project project = element.getProject(); if (!SilexProjectComponent.isEnabled(project)) { return; } if (!(element instanceof StringLiteralExpression)) { return; } Container container = Utils.findContainerForFirstParameterOfPimpleMethod((StringLiteralExpression) element); if (container == null) { return; } for (Service service : container.getServices().values()) { resultSet.addElement(new ServiceLookupElement(service, project)); } for (Parameter parameter : container.getParameters().values()) { resultSet.addElement(new ParameterLookupElement(parameter)); } resultSet.stopHere(); }
@Nullable public static MavenProject findContainingProject(@NotNull PsiElement element) { VirtualFile file = getVirtualFile(element); if (file == null) return null; MavenProjectsManager manager = MavenProjectsManager.getInstance(element.getProject()); return manager.findContainingProject(file); }
@Override public boolean canFindUsages(final PsiElement element) { Project _project = element.getProject(); FindUsagesHandlerFactory[] delegates = Extensions.<FindUsagesHandlerFactory>getExtensions( FindUsagesHandlerFactory.EP_NAME, _project); for (final FindUsagesHandlerFactory delegate : delegates) { if ((delegate != this)) { try { boolean _canFindUsages = delegate.canFindUsages(element); if (_canFindUsages) { return true; } } catch (final Throwable _t) { if (_t instanceof IndexNotReadyException) { final IndexNotReadyException e = (IndexNotReadyException) _t; throw e; } else if (_t instanceof ProcessCanceledException) { final ProcessCanceledException e_1 = (ProcessCanceledException) _t; throw e_1; } else if (_t instanceof Exception) { final Exception e_2 = (Exception) _t; GeneratedSourceAwareUsagesHandlerFactory.LOG.error(e_2); } else { throw Exceptions.sneakyThrow(_t); } } } } return false; }
@NotNull private static ControlFlow getControlFlow(@NotNull PsiElement context) throws AnalysisCanceledException { LocalsOrMyInstanceFieldsControlFlowPolicy policy = LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance(); return ControlFlowFactory.getInstance(context.getProject()).getControlFlow(context, policy); }
public void disableTool(@NotNull PsiElement element) { final Project project = element.getProject(); final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(project); if (myTools != null) { for (ScopeToolState state : myTools) { final NamedScope scope = state.getScope(project); if (scope != null) { final PackageSet packageSet = scope.getValue(); if (packageSet != null) { final PsiFile file = element.getContainingFile(); if (file != null) { if (packageSet.contains(file, validationManager)) { state.setEnabled(false); return; } } else { if (packageSet instanceof PackageSetBase && ((PackageSetBase) packageSet) .contains(PsiUtilCore.getVirtualFile(element), project, validationManager)) { state.setEnabled(false); return; } } } } } myDefaultState.setEnabled(false); } else { myDefaultState.setEnabled(false); setEnabled(false); } }