public DomElementsToggleAction(final DomModelTreeView treeView, final Class aClass) { myTreeView = treeView; myClass = aClass; Icon myIcon = ElementPresentationManager.getIcon(myClass); if (myIcon == null) { myIcon = AllIcons.Nodes.Pointcut; } this.myIcon = myIcon; myText = TypePresentationService.getService().getTypePresentableName(myClass); if(getHiders() == null) DomUtil.getFile(myTreeView.getRootElement()).putUserData(AbstractDomElementNode.TREE_NODES_HIDERS_KEY, new HashMap<Class, Boolean>()); if(getHiders().get(myClass) == null) getHiders().put(myClass, true); }
@Override protected AnAction createAddingAction(final AnActionEvent e, final String name, final Icon icon, final Type type, final DomCollectionChildDescription description) { final DomElement parentDomElement = getParentDomElement(e); if (parentDomElement instanceof MergedObject) { final List<DomElement> implementations = (List<DomElement>)((MergedObject)parentDomElement).getImplementations(); final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true); for (DomElement implementation : implementations) { final XmlFile xmlFile = DomUtil.getFile(implementation); actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), xmlFile.getIcon(0), e, type, description)); } return actionGroup; } return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description); }
@Override public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) { final SimpleNode selectedNode = treeView.getTree().getSelectedNode(); if (selectedNode instanceof BaseDomElementNode) { if (selectedNode instanceof DomFileElementNode) { e.getPresentation().setVisible(false); return; } final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement(); final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode, "Remove") + "?", "Remove", Messages.getQuestionIcon()); if (ret == Messages.OK) { new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) { @Override protected void run(@NotNull final Result result) throws Throwable { domElement.undefine(); } }.execute(); } } }
@Override @NotNull public DomElementsProblemsHolder getProblemHolder(DomElement element) { if (element == null || !element.isValid()) return EMPTY_PROBLEMS_HOLDER; final DomFileElement<DomElement> fileElement = DomUtil.getFileElement(element); synchronized (LOCK) { final XmlTag tag = fileElement.getRootElement().getXmlTag(); if (tag != null) { final DomElementsProblemsHolder readyHolder = tag.getUserData(DOM_PROBLEM_HOLDER_KEY); if (readyHolder != null) { return readyHolder; } } return EMPTY_PROBLEMS_HOLDER; } }
@NotNull public DomHighlightStatus getHighlightStatus(final DomElement element) { synchronized (LOCK) { final DomFileElement<DomElement> root = DomUtil.getFileElement(element); if (!isHolderOutdated(root.getFile())) { final DomElementsProblemsHolder holder = getProblemHolder(element); if (holder instanceof DomElementsProblemsHolderImpl) { DomElementsProblemsHolderImpl holderImpl = (DomElementsProblemsHolderImpl)holder; final List<DomElementsInspection> suitableInspections = getSuitableDomInspections(root, true); final DomElementsInspection mockInspection = getMockInspection(root); final boolean annotatorsFinished = mockInspection == null || holderImpl.isInspectionCompleted(mockInspection); final boolean inspectionsFinished = areInspectionsFinished(holderImpl, suitableInspections); if (annotatorsFinished) { if (suitableInspections.isEmpty() || inspectionsFinished) return DomHighlightStatus.INSPECTIONS_FINISHED; return DomHighlightStatus.ANNOTATORS_FINISHED; } } } return DomHighlightStatus.NONE; } }
protected boolean shouldBeShown(final Type type) { final Map<Class, Boolean> hiders = DomUtil.getFile(getDomElement()).getUserData(TREE_NODES_HIDERS_KEY); if (type == null || hiders == null || hiders.size() == 0) return true; final Class aClass = ReflectionUtil.getRawType(type); List<Class> allParents = new ArrayList<Class>(); for (Map.Entry<Class, Boolean> entry : hiders.entrySet()) { if (entry.getKey().isAssignableFrom(aClass)) { allParents.add(entry.getKey()); } } if (allParents.size() == 0) return false; Collections.sort(allParents, INHERITORS_COMPARATOR); return hiders.get(allParents.get(0)).booleanValue(); }
@Nullable public T process(@NotNull MavenDomProjectModel projectDom) { MavenDomParent parent = projectDom.getMavenParent(); MavenParentDesc parentDesc = null; if (DomUtil.hasXml(parent)) { String parentGroupId = parent.getGroupId().getStringValue(); String parentArtifactId = parent.getArtifactId().getStringValue(); String parentVersion = parent.getVersion().getStringValue(); String parentRelativePath = parent.getRelativePath().getStringValue(); if (StringUtil.isEmptyOrSpaces(parentRelativePath)) parentRelativePath = "../pom.xml"; MavenId parentId = new MavenId(parentGroupId, parentArtifactId, parentVersion); parentDesc = new MavenParentDesc(parentId, parentRelativePath); } return process(myManager.getGeneralSettings(), MavenDomUtil.getVirtualFile(projectDom), parentDesc); }
@Override public Promise<Void> changeLanguageLevel(@NotNull Module module, @NotNull final LanguageLevel level) { if (!myProjectsManager.isMavenizedModule(module)) return null; MavenProject mavenProject = myProjectsManager.findProject(module); if (mavenProject == null) return null; final MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile()); if (model == null) return null; new WriteCommandAction(myProject, "Add Maven Dependency", DomUtil.getFile(model)) { @Override protected void run(@NotNull Result result) throws Throwable { MavenDomConfiguration configuration = getCompilerPlugin(model).getConfiguration(); XmlTag tag = configuration.ensureTagExists(); setChildTagValue(tag, "source", level.getCompilerComplianceDefaultOption()); setChildTagValue(tag, "target", level.getCompilerComplianceDefaultOption()); Document document = PsiDocumentManager.getInstance(myProject).getDocument(DomUtil.getFile(model)); if (document != null) { FileDocumentManager.getInstance().saveDocument(document); } } }.execute(); return myProjectsManager.forceUpdateProjects(Collections.singleton(mavenProject)); }
public PsiElement resolve(@NotNull PsiReference psiReference, boolean incompleteCode) { final PsiElement element = psiReference.getElement(); if (element == null) { return null; } final DomElement domElement = DomUtil.getDomElement(element); if (domElement == null) { return null; } final AntDomMacroDef macrodef = domElement.getParentOfType(AntDomMacroDef.class, false); if (macrodef == null) { return null; } final String name = AntStringResolver.computeString(domElement, psiReference.getCanonicalText()); for (AntDomMacrodefAttribute attribute : macrodef.getMacroAttributes()) { if (name.equals(attribute.getName().getStringValue())) { final DomTarget target = DomTarget.getTarget(attribute); return target != null? PomService.convertToPsi(target) : null; } } return null; }
@Nullable @Override public LookupElement createLookupElement(ActionOrGroup actionOrGroup) { if (actionOrGroup instanceof Action) { Action action = (Action)actionOrGroup; final PsiElement element = getPsiElement(actionOrGroup); if (element == null) { throw new IllegalStateException(action.getId().getStringValue() + " in " + DomUtil.getFile(action) + " " + action.isValid() + " "); } LookupElementBuilder builder = LookupElementBuilder.create(ObjectUtils.assertNotNull(element), ObjectUtils.assertNotNull(getName(action))); final String text = action.getText().getStringValue(); if (StringUtil.isNotEmpty(text)) { String withoutMnemonic = StringUtil.replace(text, "_", ""); builder = builder.withTailText(" \"" + withoutMnemonic + "\"", true); } return builder; } return super.createLookupElement(actionOrGroup); }
private boolean checkIncludes(PsiFile layoutFile, PsiElement idElement) { AndroidFacet facet = AndroidFacet.getInstance(idElement); PsiFile containingFile = idElement.getContainingFile(); DomFileElement<AndroidDomElement> fileElement = DomManager.getDomManager(layoutFile.getProject()).getFileElement((XmlFile) layoutFile, AndroidDomElement.class); boolean found = false; if (fileElement != null) { AndroidDomElement rootElement = fileElement.getRootElement(); List<Include> includes = DomUtil.getChildrenOfType(rootElement, Include.class); for (Include include : includes) { ResourceValue value = include.getLayout().getValue(); if (value != null) { if (facet != null) { if (value.getResourceType() != null && value.getResourceName() != null) { List<PsiFile> resourceFiles = facet.getLocalResourceManager().findResourceFiles(value.getResourceType(), value.getResourceName()); if (!resourceFiles.isEmpty()) { found = isInAllIncludes(idElement, found, resourceFiles); } } } } } } return found; }
public DomElementsToggleAction(final DomModelTreeView treeView, final Class aClass) { myTreeView = treeView; myClass = aClass; Icon myIcon = ElementPresentationManager.getIcon(myClass); if (myIcon == null) { myIcon = AllIcons.Nodes.Pointcut; } this.myIcon = myIcon; myText = TypePresentationService.getService().getTypePresentableName(myClass); if(getHiders() == null) DomUtil.getFile(myTreeView.getRootElement()).putUserData(BaseDomElementNode.TREE_NODES_HIDERS_KEY, new HashMap<Class, Boolean>()); if(getHiders().get(myClass) == null) getHiders().put(myClass, true); }
protected AnAction createAddingAction(final AnActionEvent e, final String name, final Icon icon, final Type type, final DomCollectionChildDescription description) { final DomElement parentDomElement = getParentDomElement(e); if (parentDomElement instanceof MergedObject) { final List<DomElement> implementations = (List<DomElement>)((MergedObject)parentDomElement).getImplementations(); final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true); for (DomElement implementation : implementations) { final XmlFile xmlFile = DomUtil.getFile(implementation); actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), xmlFile.getIcon(0), e, type, description)); } return actionGroup; } return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description); }
public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) { final SimpleNode selectedNode = treeView.getTree().getSelectedNode(); if (selectedNode instanceof BaseDomElementNode) { if (selectedNode instanceof DomFileElementNode) { e.getPresentation().setVisible(false); return; } final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement(); final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode) + "?", ApplicationBundle.message("action.remove"), Messages.getQuestionIcon()); if (ret == 0) { new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) { protected void run(final Result result) throws Throwable { domElement.undefine(); } }.execute(); } } }
@NotNull private Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> getProblemsMap(final DomElement domElement) { final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> map = myCachedChildrenErrors.get(domElement); if (map != null) { return map; } final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> problems = new THashMap<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>>(); if (domElement == myElement) { for (Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> listMap : myCachedErrors.values()) { mergeMaps(problems, listMap); } } else { mergeMaps(problems, myCachedErrors.get(domElement)); if (DomUtil.hasXml(domElement)) { domElement.acceptChildren(new DomElementVisitor() { public void visitDomElement(DomElement element) { mergeMaps(problems, getProblemsMap(element)); } }); } } myCachedChildrenErrors.put(domElement, problems); return problems; }
public void invoke(@NotNull final Project project, Editor editor, final PsiFile file) throws IncorrectOperationException { if (!myRef.isValid()) return; MavenProject mavenProject = MavenDomUtil.findContainingProject(file); if (mavenProject == null) return; final List<MavenId> ids = MavenArtifactSearchDialog.searchForClass(project, getReferenceText()); if (ids.isEmpty()) return; final MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(project, mavenProject.getFile()); if (model == null) return; new WriteCommandAction(project, "Add Maven Dependency", DomUtil.getFile(model)) { @Override protected void run(Result result) throws Throwable { for (MavenId each : ids) { MavenDomUtil.createDomDependency(model, null, each); } } }.execute(); }
@NotNull protected PsiType getPsiType(final ConvertContext context) { final Resource resource; final EjbReference ejbReference; final ServiceRef serviceReference; final PsiClass aClass; if ((resource = DomUtil.getParentOfType(context.getInvocationElement(), Resource.class, false)) != null) { aClass = resource.getType().getValue(); } else if ((ejbReference = DomUtil.getParentOfType(context.getInvocationElement(), EjbReference.class, false)) != null) { aClass = ejbReference.getBeanInterface().getValue(); } else if ((serviceReference = DomUtil.getParentOfType(context.getInvocationElement(), ServiceRef.class, false)) != null) { aClass = serviceReference.getServiceInterface().getValue(); } else { aClass = null; } return aClass == null? super.getPsiType(context) : JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory().createType(aClass); }
private static boolean is23(final ConvertContext context) { final DomElement element = DomUtil.getFileElement(context.getInvocationElement()).getRootElement(); final XmlTag tag = element.getXmlTag(); if (tag != null && "web-app".equals(element.getXmlElementName()) && tag.getAttribute("version") == null) { XmlDocument document = (XmlDocument)tag.getParent(); final XmlProlog prolog = document.getProlog(); if (prolog != null) { final XmlDoctype doctype = prolog.getDoctype(); if (doctype != null) { final String uri = doctype.getDtdUri(); if (uri != null && uri.contains("2_3")) return true; } } return false; } return true; }
@Nullable public Module getModule() { if (!isValid()) { return null; } if (getManager().isMockElement(this)) { return DomUtil.getFile(this).getUserData(DomManager.MOCK_ELEMENT_MODULE); } final DomElement root = DomUtil.getRoot(this); if (equals(root)) { final PsiElement element = getIdentifyingPsiElement(); return element == null ? null : ModuleUtil.findModuleForPsiElement(element); } else { return root.getModule(); } }
public DomElementsToggleAction(final DomModelTreeView treeView, final Class aClass) { myTreeView = treeView; myClass = aClass; Icon myIcon = ElementPresentationManager.getIcon(myClass); if (myIcon == null) { myIcon = AllIcons.Nodes.Pointcut; } this.myIcon = myIcon; myText = TypePresentationService.getInstance().getTypePresentableName(myClass); if(getHiders() == null) DomUtil.getFile(myTreeView.getRootElement()).putUserData(BaseDomElementNode.TREE_NODES_HIDERS_KEY, new HashMap<Class, Boolean>()); if(getHiders().get(myClass) == null) getHiders().put(myClass, true); }
protected AnAction createAddingAction(final AnActionEvent e, final String name, final Icon icon, final Type type, final DomCollectionChildDescription description) { final DomElement parentDomElement = getParentDomElement(e); if (parentDomElement instanceof MergedObject) { final List<DomElement> implementations = (List<DomElement>)((MergedObject)parentDomElement).getImplementations(); final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true); for (DomElement implementation : implementations) { final XmlFile xmlFile = DomUtil.getFile(implementation); actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), IconDescriptorUpdaters.getIcon(xmlFile, 0), e, type, description)); } return actionGroup; } return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description); }
@Override public boolean isSuppressedFor(@NotNull PsiElement element, @NotNull String name) { DomElement domElement = DomUtil.getDomElement(element); if (domElement != null) { if (domElement.getAnnotation(NoSpellchecking.class) != null) { return true; } } return false; }
@Override public void update(AnActionEvent e, DomModelTreeView treeView) { final SimpleNode selectedNode = treeView.getTree().getSelectedNode(); if (selectedNode instanceof DomFileElementNode) { e.getPresentation().setVisible(false); return; } boolean enabled = false; if (selectedNode instanceof BaseDomElementNode) { final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement(); if (domElement.isValid() && DomUtil.hasXml(domElement) && !(domElement.getParent() instanceof DomFileElement)) { enabled = true; } } e.getPresentation().setEnabled(enabled); if (enabled) { e.getPresentation().setText(getPresentationText(selectedNode, ApplicationBundle.message("action.remove"))); } else { e.getPresentation().setText(ApplicationBundle.message("action.remove")); } e.getPresentation().setIcon(AllIcons.General.Remove); }
@NotNull private Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> getProblemsMap(final DomElement domElement) { final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> map = myCachedChildrenErrors.get(domElement); if (map != null) { return map; } final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> problems = new THashMap<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>>(); if (domElement == myElement) { for (Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> listMap : myCachedErrors.values()) { mergeMaps(problems, listMap); } } else { mergeMaps(problems, myCachedErrors.get(domElement)); if (DomUtil.hasXml(domElement)) { domElement.acceptChildren(new DomElementVisitor() { @Override public void visitDomElement(DomElement element) { mergeMaps(problems, getProblemsMap(element)); } }); } } myCachedChildrenErrors.put(domElement, problems); return problems; }
@Override public BackgroundEditorHighlighter createDomHighlighter(final Project project, final PerspectiveFileEditor editor, final DomElement element) { return new BackgroundEditorHighlighter() { @Override @NotNull public HighlightingPass[] createPassesForEditor() { if (!element.isValid()) return HighlightingPass.EMPTY_ARRAY; final XmlFile psiFile = DomUtil.getFile(element); final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); final Document document = psiDocumentManager.getDocument(psiFile); if (document == null) return HighlightingPass.EMPTY_ARRAY; editor.commit(); psiDocumentManager.commitAllDocuments(); GeneralHighlightingPass ghp = new GeneralHighlightingPass(project, psiFile, document, 0, document.getTextLength(), true, new ProperTextRange(0, document.getTextLength()), null, new DefaultHighlightInfoProcessor()); LocalInspectionsPass lip = new LocalInspectionsPass(psiFile, document, 0, document.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true, new DefaultHighlightInfoProcessor()); return new HighlightingPass[]{ghp, lip}; } @Override @NotNull public HighlightingPass[] createPassesForVisibleArea() { return createPassesForEditor(); } }; }
protected GenericDomValuePattern(final Class<T> aClass) { super(new InitialPatternCondition(aClass) { @Override public boolean accepts(@Nullable final Object o, final ProcessingContext context) { return o instanceof GenericDomValue && aClass.equals(DomUtil.getGenericValueParameter(((GenericDomValue)o).getDomElementType())); } }); }
public ErrorableTableCellRenderer(@Nullable final T cellValueDomElement, final TableCellRenderer renderer, @NotNull final DomElement rowDomElement) { myCellValueDomElement = cellValueDomElement; myRenderer = renderer; myRowDomElement = rowDomElement; myRoot = DomUtil.getRoot(myRowDomElement); }
public ColumnInfo createColumnInfo(final DomCollectionChildDescription description, final DomElement element) { final String presentableName = description.getCommonPresentableName(element); final Class aClass = DomUtil.extractParameterClassFromGenericType(description.getType()); if (aClass != null) { if (Boolean.class.equals(aClass) || boolean.class.equals(aClass)) { return new BooleanColumnInfo(presentableName); } return new GenericValueColumnInfo(presentableName, aClass, createCellEditor(element, aClass)); } return new StringColumnInfo(presentableName); }
@Override protected void wrapValueSetting(@NotNull final DomElement domElement, final Runnable valueSetter) { if (domElement.isValid()) { new WriteCommandAction(getProject(), DomUtil.getFile(domElement)) { @Override protected void run(@NotNull final Result result) throws Throwable { valueSetter.run(); } }.execute(); fireChanged(); } }