public int getCumulativeVersion(boolean forStubs) { int result = 0; for (DomFileDescription description : getAllFileDescriptions()) { if (forStubs) { if (description.hasStubs()) { result += description.getStubVersion(); result += description.getRootTagName().hashCode(); // so that a plugin enabling/disabling could trigger the reindexing } } else { result += description.getVersion(); result += description.getRootTagName().hashCode(); // so that a plugin enabling/disabling could trigger the reindexing } } return result; }
@Nullable private static ContextSpecificSettingsProviders.Provider getContextSpecificSettings(PsiElement context) { final PsiFile file = context.getContainingFile(); if (!(file instanceof XmlFile) || AndroidFacet.getInstance(file) == null) { return null; } final DomFileDescription<?> description = DomManager.getDomManager( context.getProject()).getDomFileDescription((XmlFile)file); if (description instanceof LayoutDomFileDescription) { return ContextSpecificSettingsProviders.LAYOUT; } else if (description instanceof ManifestDomFileDescription) { return ContextSpecificSettingsProviders.MANIFEST; } else if (description instanceof ResourcesDomFileDescription || description instanceof DrawableStateListDomFileDescription || description instanceof ColorDomFileDescription) { return ContextSpecificSettingsProviders.VALUE_RESOURCE_FILE; } else if (description instanceof AndroidResourceDomFileDescription) { return ContextSpecificSettingsProviders.OTHER; } return null; }
@Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof XmlFile)) { return ProblemDescriptor.EMPTY_ARRAY; } final AndroidFacet facet = AndroidFacet.getInstance(file); if (facet == null) { return ProblemDescriptor.EMPTY_ARRAY; } final DomFileDescription<?> description = DomManager.getDomManager(file.getProject()).getDomFileDescription((XmlFile)file); if (!(description instanceof LayoutDomFileDescription) && !(description instanceof MenuDomFileDescription)) { return ProblemDescriptor.EMPTY_ARRAY; } final Collection<PsiClass> activities = findRelatedActivities((XmlFile)file, facet, description); final MyVisitor visitor = new MyVisitor(manager, isOnTheFly, activities); file.accept(visitor); return visitor.myResult.toArray(new ProblemDescriptor[visitor.myResult.size()]); }
static boolean isMyFile(@NotNull AndroidFacet facet, XmlFile file) { String resourceType = facet.getLocalResourceManager().getFileResourceType(file); if (resourceType != null) { if (ourSupportedResourceTypes == null) { ourSupportedResourceTypes = new HashSet<String>(); for (DomFileDescription description : DomFileDescription.EP_NAME.getExtensions()) { if (description instanceof AndroidResourceDomFileDescription) { String[] resourceTypes = ((AndroidResourceDomFileDescription)description).getResourceTypes(); Collections.addAll(ourSupportedResourceTypes, resourceTypes); } } } if (!ourSupportedResourceTypes.contains(resourceType)) { return false; } if (ResourceType.XML.getName().equals(resourceType)) { final XmlTag rootTag = file.getRootTag(); return rootTag != null && AndroidXmlResourcesUtil.isSupportedRootTag(facet, rootTag.getName()); } return true; } return ManifestDomFileDescription.isManifestFile(file, facet); }
public final synchronized void registerFileDescription(final DomFileDescription description) { myRootTagName2FileDescription.get(description.getRootTagName()).add(description); if(description.acceptsOtherRootTagNames()) { myAcceptingOtherRootTagNamesDescriptions.add(description); } //noinspection unchecked final Map<Class<? extends DomElement>, Class<? extends DomElement>> implementations = description.getImplementations(); for(final Map.Entry<Class<? extends DomElement>, Class<? extends DomElement>> entry : implementations.entrySet()) { registerImplementation(entry.getKey(), entry.getValue(), null); } myTypeChooserManager.copyFrom(description.getTypeChooserManager()); }
public final synchronized void registerFileDescription(final DomFileDescription description) { myRootTagName2FileDescription.get(description.getRootTagName()).add(description); if (description.acceptsOtherRootTagNames()) { myAcceptingOtherRootTagNamesDescriptions.add(description); } //noinspection unchecked final Map<Class<? extends DomElement>, Class<? extends DomElement>> implementations = description.getImplementations(); for (final Map.Entry<Class<? extends DomElement>, Class<? extends DomElement>> entry : implementations.entrySet()) { registerImplementation(entry.getKey(), entry.getValue(), null); } myTypeChooserManager.copyFrom(description.getTypeChooserManager()); }
public synchronized List<DomFileDescription> getAllFileDescriptions() { final List<DomFileDescription> result = newArrayList(); for (Set<DomFileDescription> descriptions : myRootTagName2FileDescription.values()) { result.addAll(descriptions); } result.addAll(myAcceptingOtherRootTagNamesDescriptions); return result; }
@NotNull private static Collection<PsiClass> findRelatedActivities(@NotNull XmlFile file, @NotNull AndroidFacet facet, @NotNull DomFileDescription<?> description) { if (description instanceof LayoutDomFileDescription) { final Computable<List<GotoRelatedItem>> computable = AndroidGotoRelatedProvider.getLazyItemsForXmlFile(file, facet); if (computable == null) { return Collections.emptyList(); } final List<GotoRelatedItem> items = computable.compute(); if (items.isEmpty()) { return Collections.emptyList(); } final PsiClass activityClass = findActivityClass(facet.getModule()); if (activityClass == null) { return Collections.emptyList(); } final List<PsiClass> result = new ArrayList<PsiClass>(); for (GotoRelatedItem item : items) { final PsiElement element = item.getElement(); if (element instanceof PsiClass) { final PsiClass aClass = (PsiClass)element; if (aClass.isInheritor(activityClass, true)) { result.add(aClass); } } } return result; } else { return findRelatedActivitiesForMenu(file, facet); } }
@Override protected boolean isMyFile(PsiFile file) { final DomFileDescription<?> description = DomManager.getDomManager(file.getProject()).getDomFileDescription((XmlFile)file); return description instanceof LayoutDomFileDescription || description instanceof ResourcesDomFileDescription; }
@Override public int getStubVersion() { int version = 11; DomFileDescription[] descriptions = Extensions.getExtensions(DomFileDescription.EP_NAME); for(DomFileDescription description : descriptions) { version += description.getStubVersion(); } return version; }
public DomApplicationComponent() { for(final DomFileDescription description : Extensions.getExtensions(DomFileDescription.EP_NAME)) { registerFileDescription(description); } }
public int getCumulativeVersion() { int result = 0; for(DomFileDescription description : getAllFileDescriptions()) { result += description.getVersion(); result += description.getRootTagName().hashCode(); // so that a plugin enabling/disabling could trigger the reindexing } return result; }
public synchronized List<DomFileDescription> getAllFileDescriptions() { final List<DomFileDescription> result = newArrayList(); for(Set<DomFileDescription> descriptions : myRootTagName2FileDescription.values()) { result.addAll(descriptions); } result.addAll(myAcceptingOtherRootTagNamesDescriptions); return result; }
@Override protected Set<DomFileDescription> create(final String key) { return new THashSet<DomFileDescription>(); }
@Override protected DomElementsAnnotator create(Class key) { final DomFileDescription desc = findFileDescription(key); return desc == null ? null : desc.createAnnotator(); }
public DomApplicationComponent() { for (final DomFileDescription description : Extensions.getExtensions(DomFileDescription.EP_NAME)) { registerFileDescription(description); } }
public final synchronized Set<DomFileDescription> getFileDescriptions(String rootTagName) { return myRootTagName2FileDescription.get(rootTagName); }
public final synchronized Set<DomFileDescription> getAcceptingOtherRootTagNameDescriptions() { return myAcceptingOtherRootTagNamesDescriptions; }
@Override public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet result) { if (TemplateManager.getInstance(parameters.getOriginalFile().getProject()).getActiveTemplate(parameters.getEditor()) != null) { return; // Don't brake the template. } PsiFile psiFile = parameters.getOriginalFile(); if (!(psiFile instanceof XmlFile)) return; if (!MavenDomUtil.isProjectFile(psiFile)) return; DomFileDescription<?> description = DomManager.getDomManager(psiFile.getProject()).getDomFileDescription((XmlFile)psiFile); if (!(description instanceof MavenDomProjectModelDescription)) return; result.runRemainingContributors(parameters, new Consumer<CompletionResult>() { @Override public void consume(CompletionResult r) { final LookupElement lookupElement = r.getLookupElement(); if (myHandledTags.contains(lookupElement.getLookupString())) { LookupElement decorator = LookupElementDecorator.withInsertHandler(lookupElement, new InsertHandler<LookupElementDecorator<LookupElement>>() { @Override public void handleInsert(final InsertionContext context, LookupElementDecorator<LookupElement> item) { lookupElement.handleInsert(context); Object object = lookupElement.getObject(); if ("dependency".equals(lookupElement.getLookupString()) && object instanceof XmlTag && "maven-4.0.0.xsd".equals(((XmlTag)object).getContainingFile().getName())) { context.commitDocument(); CaretModel caretModel = context.getEditor().getCaretModel(); PsiElement psiElement = context.getFile().findElementAt(caretModel.getOffset()); XmlTag xmlTag = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class); if (xmlTag != null) { DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement(xmlTag); if (domElement instanceof MavenDomDependency) { String s = "\n<groupId></groupId>\n<artifactId></artifactId>\n"; context.getDocument().insertString(caretModel.getOffset(), s); caretModel.moveToOffset(caretModel.getOffset() + s.length() - "</artifactId>\n".length()); context.commitDocument(); new ReformatCodeProcessor(context.getProject(), context.getFile(), xmlTag.getTextRange(), false).run(); MavenDependencyCompletionUtil.invokeCompletion(context, CompletionType.BASIC); } } } } }); r = r.withLookupElement(decorator); } result.passResult(r); } }); }
protected Set<DomFileDescription> create(final String key) { return new THashSet<DomFileDescription>(); }
@Nullable private DomFileDescription<T> findFileDescription(final XmlFileHeader rootTagName, @Nullable StringBuilder sb) { final DomFileDescription<T> mockDescription = myXmlFile.getUserData(DomManagerImpl.MOCK_DESCRIPTION); if(mockDescription != null) { return mockDescription; } if(sb != null) { sb.append("no mock\n"); } final XmlFile originalFile = (XmlFile) myXmlFile.getOriginalFile(); if(sb != null) { sb.append("original: " + originalFile + "\n"); } if(!originalFile.equals(myXmlFile)) { final FileDescriptionCachedValueProvider<T> provider = myDomManager.getOrCreateCachedValueProvider(originalFile); final DomFileElementImpl<T> element = provider.getFileElement(); if(sb != null) { sb.append("originalDom " + element + "\n"); } return element == null ? null : element.getFileDescription(); } //noinspection unchecked final Set<DomFileDescription> namedDescriptions = myDomManager.getFileDescriptions(rootTagName.getRootTagLocalName()); if(sb != null) { sb.append("named " + new HashSet<DomFileDescription>(namedDescriptions) + "\n"); } DomFileDescription<T> description = ContainerUtil.find(namedDescriptions, myCondition); if(description == null) { final Set<DomFileDescription> unnamed = myDomManager.getAcceptingOtherRootTagNameDescriptions(); description = ContainerUtil.find(unnamed, myCondition); } if(sb != null) { sb.append("found " + description + "\n"); } return description; }
@Override public boolean value(final DomFileDescription description) { return description.isMyFile(myXmlFile); }