com.intellij.xml.impl.dtd.BaseXmlElementDescriptorImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xml-psi-impl Show documentation
Show all versions of xml-psi-impl Show documentation
A packaging of the IntelliJ Community Edition xml-psi-impl library.
This is release number 1 of trunk branch 142.
The newest version!
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.xml.impl.dtd;
import com.intellij.openapi.util.FieldCache;
import com.intellij.openapi.util.SimpleFieldCache;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.xml.XmlAttributeDescriptor;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.XmlElementsGroup;
import java.util.HashMap;
public abstract class BaseXmlElementDescriptorImpl implements XmlElementDescriptor {
private volatile XmlElementDescriptor[] myElementDescriptors = null;
private volatile XmlAttributeDescriptor[] myAttributeDescriptors;
private volatile HashMap myElementDescriptorsMap;
private volatile HashMap attributeDescriptorsMap;
protected BaseXmlElementDescriptorImpl() {}
@Override
public XmlElementsGroup getTopGroup() {
return null;
}
@Override
public String getDefaultValue() {
return null;
}
// Read-only action
protected abstract XmlElementDescriptor[] doCollectXmlDescriptors(final XmlTag context);
static final FieldCache myElementDescriptorsCache =
new FieldCache() {
@Override
protected final XmlElementDescriptor[] compute(final BaseXmlElementDescriptorImpl xmlElementDescriptor, XmlTag tag) {
return xmlElementDescriptor.doCollectXmlDescriptors(tag);
}
@Override
protected final XmlElementDescriptor[] getValue(final BaseXmlElementDescriptorImpl xmlElementDescriptor, Object o) {
return xmlElementDescriptor.myElementDescriptors;
}
@Override
protected final void putValue(final XmlElementDescriptor[] xmlElementDescriptors, final BaseXmlElementDescriptorImpl xmlElementDescriptor,Object o) {
xmlElementDescriptor.myElementDescriptors = xmlElementDescriptors;
}
};
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
return myElementDescriptorsCache.get(null, this, context);
}
private static final SimpleFieldCache myAttributeDescriptorsCache =
new SimpleFieldCache() {
@Override
protected final XmlAttributeDescriptor[] compute(final BaseXmlElementDescriptorImpl xmlElementDescriptor) {
return xmlElementDescriptor.collectAttributeDescriptors(null);
}
@Override
protected final XmlAttributeDescriptor[] getValue(final BaseXmlElementDescriptorImpl xmlElementDescriptor) {
return xmlElementDescriptor.myAttributeDescriptors;
}
@Override
protected final void putValue(final XmlAttributeDescriptor[] xmlAttributeDescriptors, final BaseXmlElementDescriptorImpl xmlElementDescriptor) {
xmlElementDescriptor.myAttributeDescriptors = xmlAttributeDescriptors;
}
};
@Override
public XmlAttributeDescriptor[] getAttributesDescriptors(final XmlTag context) {
return myAttributeDescriptorsCache.get(this);
}
// Read-only calculation
protected abstract XmlAttributeDescriptor[] collectAttributeDescriptors(final XmlTag context);
private static final SimpleFieldCache, BaseXmlElementDescriptorImpl> attributeDescriptorsMapCache =
new SimpleFieldCache, BaseXmlElementDescriptorImpl>() {
@Override
protected final HashMap compute(final BaseXmlElementDescriptorImpl baseXmlElementDescriptor) {
return baseXmlElementDescriptor.collectAttributeDescriptorsMap(null);
}
@Override
protected final HashMap getValue(final BaseXmlElementDescriptorImpl baseXmlElementDescriptor) {
return baseXmlElementDescriptor.attributeDescriptorsMap;
}
@Override
protected final void putValue(final HashMap hashMap, final BaseXmlElementDescriptorImpl baseXmlElementDescriptor) {
baseXmlElementDescriptor.attributeDescriptorsMap = hashMap;
}
};
@Override
public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, final XmlTag context) {
return attributeDescriptorsMapCache.get(this).get(attributeName);
}
// Read-only calculation
protected abstract HashMap collectAttributeDescriptorsMap(final XmlTag context);
private static final FieldCache,BaseXmlElementDescriptorImpl,Object,XmlTag> myElementDescriptorsMapCache =
new FieldCache, BaseXmlElementDescriptorImpl, Object, XmlTag>() {
@Override
protected final HashMap compute(final BaseXmlElementDescriptorImpl baseXmlElementDescriptor, final XmlTag p) {
return baseXmlElementDescriptor.collectElementDescriptorsMap(p);
}
@Override
protected final HashMap getValue(final BaseXmlElementDescriptorImpl baseXmlElementDescriptor, final Object p) {
return baseXmlElementDescriptor.myElementDescriptorsMap;
}
@Override
protected final void putValue(final HashMap hashMap,
final BaseXmlElementDescriptorImpl baseXmlElementDescriptor, final Object p) {
baseXmlElementDescriptor.myElementDescriptorsMap = hashMap;
}
};
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag element, XmlTag contextTag){
return myElementDescriptorsMapCache.get(null, this, element).get(element.getName());
}
public final XmlElementDescriptor getElementDescriptor(String name, XmlTag context){
return myElementDescriptorsMapCache.get(null, this, context).get(name);
}
// Read-only calculation
protected abstract HashMap collectElementDescriptorsMap(final XmlTag element);
@Override
public final XmlAttributeDescriptor getAttributeDescriptor(XmlAttribute attr){
return getAttributeDescriptor(attr.getName(), attr.getParent());
}
@Override
public String toString() {
return getQualifiedName();
}
}