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; }
public AntBuildTargetImpl(final AntDomTarget target, final AntBuildModelBase buildModel, final VirtualFile sourceFile, final boolean isImported, final boolean isDefault) { myModel = buildModel; myFile = sourceFile; myIsDefault = isDefault; myHashCode = target.hashCode(); myName = target.getName().getRawText(); String name = target.getName().getRawText(); if (isImported) { final String projectName = target.getAntProject().getName().getRawText(); name = projectName + "." + name; } myDisplayName = name; myProject = target.getManager().getProject(); final DomTarget domTarget = DomTarget.getTarget(target); if (domTarget != null) { myTextOffset = domTarget.getTextOffset(); } else { myTextOffset = target.getXmlTag().getTextOffset(); } final String desc = target.getDescription().getRawText(); myDescription = (desc != null && desc.trim().length() > 0) ? desc : null; }
@Override public SearchScope getAdditionalUseScope(@NotNull PsiElement element) { if (element instanceof PomTargetPsiElement) { PomTarget target = ((PomTargetPsiElement)element).getTarget(); if (target instanceof DomTarget) { DomElement domElement = ((DomTarget)target).getDomElement(); if (domElement instanceof ExtensionPoint) { return createProjectXmlFilesScope(element); } } } if (element instanceof PsiClass && PsiUtil.isIdeaProject(element.getProject()) && ((PsiClass)element).hasModifierProperty(PsiModifier.PUBLIC)) { return createProjectXmlFilesScope(element); } return null; }
public AntBuildTargetImpl(final AntDomTarget target, final AntBuildModelBase buildModel, final VirtualFile sourceFile, final boolean isImported, final boolean isDefault) { myModel = buildModel; myFile = sourceFile; myIsDefault = isDefault; myHashCode = target.hashCode(); myName = target.getName().getRawText(); String name = target.getName().getRawText(); if (isImported) { final String projectName = target.getAntProject().getName().getRawText(); name = projectName + "" + name; } myDisplayName = name; myProject = target.getManager().getProject(); final DomTarget domTarget = DomTarget.getTarget(target); if (domTarget != null) { myTextOffset = domTarget.getTextOffset(); } else { myTextOffset = target.getXmlTag().getTextOffset(); } final String desc = target.getDescription().getRawText(); myDescription = (desc != null && desc.trim().length() > 0) ? desc : null; }
@Override @Nullable protected DomTarget createDomTarget(DomElement parent, DomElement nameElement) { final NameValue nameValue = nameElement.getAnnotation(NameValue.class); if (nameValue != null && nameValue.referencable()) { return DomTarget.getTarget(parent); } return null; }
public static ElementPattern<DomTarget> withDomTarget(final ElementPattern<? extends DomElement> pattern) { return new ObjectPattern.Capture<DomTarget>(DomTarget.class).with(new PatternCondition<DomTarget>("withDomTarget") { @Override public boolean accepts(@NotNull final DomTarget target, final ProcessingContext context) { return pattern.accepts(target.getDomElement(), context); } }); }
@Nullable public static DomElement toDomElement(PsiElement resolve) { if (resolve instanceof PomTargetPsiElement) { final PomTarget target = ((PomTargetPsiElement)resolve).getTarget(); if(target instanceof DomTarget) { return ((DomTarget)target).getDomElement(); } return null; } return DomUtil.getDomElement(resolve); }
@Nullable private static AntDomElement convertToAntDomElement(PsiElement element) { if (element instanceof PomTargetPsiElement) { final PomTarget target = ((PomTargetPsiElement)element).getTarget(); if (target instanceof DomTarget) { final DomElement domElement = ((DomTarget)target).getDomElement(); if (domElement instanceof AntDomElement) { return (AntDomElement)domElement; } } } return null; }
protected DomTarget createDomTarget(DomElement parent, DomElement nameElement) { if (parent instanceof AntDomElement && nameElement.equals(((AntDomElement)parent).getId())) { // id attrib is defined return DomTarget.getTarget(parent, (GenericDomValue)nameElement); } if (parent instanceof AntDomProperty && nameElement.equals(((AntDomProperty)parent).getEnvironment())) { // environment attrib is defined return DomTarget.getTarget(parent, (GenericDomValue)nameElement); } return null; }
public PsiElement resolve(@NotNull PsiReference psiReference, boolean incompleteCode) { final TargetResolver.Result result = ((AntDomTargetReference)psiReference).doResolve(psiReference.getCanonicalText()); if (result == null) { return null; } final Pair<AntDomTarget,String> pair = result.getResolvedTarget(psiReference.getCanonicalText()); final DomTarget domTarget = pair != null && pair.getFirst() != null ? DomTarget.getTarget(pair.getFirst()) : null; return domTarget != null? PomService.convertToPsi(domTarget) : null; }
public PsiElement getNavigationElement(final String propertyName) { DomTarget domTarget = DomTarget.getTarget(this); if (domTarget == null) { final GenericAttributeValue<String> environment = getEnvironment(); if (environment.getRawText() != null) { domTarget = DomTarget.getTarget(this, environment); } if (domTarget == null) { final GenericAttributeValue<String> resource = getResource(); if (resource.getRawText() != null) { domTarget = DomTarget.getTarget(this, resource); } } } if (domTarget != null) { final PsiElement psi = PomService.convertToPsi(domTarget); if (psi != null) { return psi; } } final PsiFileSystemItem psiFile = getFile().getValue(); if (psiFile != null) { final String prefix = getPropertyPrefixValue(); String _propertyName = propertyName; if (prefix != null) { if (!propertyName.startsWith(prefix)) { return null; } _propertyName = propertyName.substring(prefix.length()); } final PropertiesFile pf = toPropertiesFile(psiFile); if (pf != null) { final IProperty property = pf.findPropertyByKey(_propertyName); return property != null? property.getPsiElement() : null; } } return null; }
public BuildTask(final AntBuildTargetBase target, final AntDomElement task) { myTarget = target; myName = task.getXmlElementName(); final DomTarget domTarget = DomTarget.getTarget(task); if (domTarget != null) { myOffset = domTarget.getTextOffset(); } else { myOffset = task.getXmlTag().getTextOffset(); } }
public void testPropertyInMacrodefParam() throws Exception { PsiReference ref = configure(); final PsiElement result = ref.resolve(); assertTrue(result instanceof PomTargetPsiElement); final PsiElement naviElem = ((DomTarget)((PomTargetPsiElement)result).getTarget()).getNavigationElement(); final DomElement domElement = DomUtil.getDomElement(naviElem); assertNotNull(domElement); assertNotNull(domElement.getParentOfType(AntDomMacrodefAttribute.class, false)); }
@Nullable private static ExtensionPoint findExtensionPoint(PsiElement element) { if (element instanceof PomTargetPsiElement && DescriptorUtil.isPluginXml(element.getContainingFile())) { final PomTarget pomTarget = ((PomTargetPsiElement)element).getTarget(); if (pomTarget instanceof DomTarget) { final DomElement domElement = ((DomTarget)pomTarget).getDomElement(); if (domElement instanceof ExtensionPoint) { return (ExtensionPoint)domElement; } } } return null; }
@Nullable protected DomTarget createDomTarget(DomElement parent, DomElement nameElement) { final NameValue nameValue = nameElement.getAnnotation(NameValue.class); if (nameValue != null && nameValue.referencable()) { return DomTarget.getTarget(parent); } return null; }
public PsiElement getNavigationElement(final String propertyName) { DomTarget domTarget = DomTarget.getTarget(this); if (domTarget == null) { final GenericAttributeValue<String> environment = getEnvironment(); if (environment.getRawText() != null) { domTarget = DomTarget.getTarget(this, environment); } if (domTarget == null) { final GenericAttributeValue<String> resource = getResource(); if (resource.getRawText() != null) { domTarget = DomTarget.getTarget(this, resource); } } } if (domTarget != null) { final PsiElement psi = PomService.convertToPsi(domTarget); if (psi != null) { return psi; } } final PsiFileSystemItem psiFile = getFile().getValue(); if (psiFile != null) { final String prefix = getPropertyPrefixValue(); String _propertyName = propertyName; if (prefix != null) { if (!propertyName.startsWith(prefix)) { return null; } _propertyName = propertyName.substring(prefix.length()); } if (psiFile instanceof PropertiesFile) { final IProperty property = ((PropertiesFile)psiFile).findPropertyByKey(_propertyName); return property != null? property.getPsiElement() : null; } } return null; }
@Override public ExtensionPoint getExtensionPoint() { PsiElement declaration = getChildDescription().getDeclaration(getManager().getProject()); if (declaration instanceof PomTargetPsiElement) { PomTarget target = ((PomTargetPsiElement)declaration).getTarget(); return target instanceof DomTarget ? (ExtensionPoint)((DomTarget)target).getDomElement() : null; } return null; }
@Override public SearchScope getAdditionalUseScope(@NotNull PsiElement element) { if (element instanceof PomTargetPsiElement) { PomTarget target = ((PomTargetPsiElement)element).getTarget(); if (target instanceof DomTarget) { DomElement domElement = ((DomTarget)target).getDomElement(); if (domElement instanceof ExtensionPoint) { return GlobalSearchScope.allScope(element.getProject()); } } } return null; }
@Nullable private static PomTarget doFindDeclaration(DomElement parent, XmlName xmlName) { if (!(parent instanceof AntDomElement)) { return null; } final AntDomElement parentElement = (AntDomElement)parent; final AntDomProject antDomProject = parentElement.getAntProject(); if (antDomProject == null) { return null; } final CustomAntElementsRegistry registry = CustomAntElementsRegistry.getInstance(antDomProject); final AntDomElement declaringElement = registry.findDeclaringElement(parentElement, xmlName); if (declaringElement == null) { return null; } DomTarget target = DomTarget.getTarget(declaringElement); if (target == null && declaringElement instanceof AntDomTypeDef) { final AntDomTypeDef typedef = (AntDomTypeDef)declaringElement; final GenericAttributeValue<PsiFileSystemItem> resource = typedef.getResource(); if (resource != null) { target = DomTarget.getTarget(declaringElement, resource); } if (target == null) { final GenericAttributeValue<PsiFileSystemItem> file = typedef.getFile(); if (file != null) { target = DomTarget.getTarget(declaringElement, file); } } } return target; }
@Nullable public PsiElement getNavigationElement(String propertyName) { final DomTarget target = DomTarget.getTarget(this); final PsiElement nameElementPsi = target != null ? PomService.convertToPsi(target) : null; if (nameElementPsi != null) { return nameElementPsi; } final XmlElement xmlElement = getXmlElement(); return xmlElement != null? xmlElement.getNavigationElement() : null; }
@Nullable public static Object getModelObject(PsiElement element) { if(!(element instanceof PomTargetPsiElement)) { return null; } final PomTarget target = ((PomTargetPsiElement) element).getTarget(); return target instanceof CommonModelTarget ? ((CommonModelTarget) target).getCommonElement() : target instanceof JamPomTarget ? ((JamPomTarget) target).getJamElement() : target instanceof DomTarget ? ((DomTarget) target).getDomElement() : null; }
public PsiElement getIdentifyingPsiElement() { final DomTarget target = DomTarget.getTarget(this); return target == null? getXmlElement() : PomService.convertToPsi(target); }