summaryrefslogtreecommitdiff
path: root/xml/xml-psi-impl/src/com/intellij/psi
diff options
context:
space:
mode:
Diffstat (limited to 'xml/xml-psi-impl/src/com/intellij/psi')
-rw-r--r--xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/AttributeValueSelfReference.java56
-rw-r--r--xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileBasedUserDataCache.java56
-rw-r--r--xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/ImplicitIdRefProvider.java30
-rw-r--r--xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java17
4 files changed, 151 insertions, 8 deletions
diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/AttributeValueSelfReference.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/AttributeValueSelfReference.java
new file mode 100644
index 000000000000..781c49f527f0
--- /dev/null
+++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/AttributeValueSelfReference.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2000-2013 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.psi.impl.source.resolve.reference.impl.providers;
+
+import com.intellij.openapi.util.TextRange;
+import com.intellij.psi.PsiElement;
+import com.intellij.util.ArrayUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author peter
+*/
+public class AttributeValueSelfReference extends BasicAttributeValueReference {
+ public AttributeValueSelfReference(final PsiElement element) {
+ super(element);
+ }
+
+ public AttributeValueSelfReference(final PsiElement element, int offset) {
+ super(element, offset);
+ }
+
+ public AttributeValueSelfReference(final PsiElement element, TextRange range) {
+ super(element, range);
+ }
+
+ @Override
+ @Nullable
+ public PsiElement resolve() {
+ return myElement;
+ }
+
+ @Override
+ @NotNull
+ public Object[] getVariants() {
+ return ArrayUtil.EMPTY_OBJECT_ARRAY;
+ }
+
+ @Override
+ public boolean isSoft() {
+ return true;
+ }
+}
diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileBasedUserDataCache.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileBasedUserDataCache.java
new file mode 100644
index 000000000000..5f30df017190
--- /dev/null
+++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileBasedUserDataCache.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2000-2013 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.psi.impl.source.resolve.reference.impl.providers;
+
+import com.intellij.psi.util.CachedValue;
+import com.intellij.psi.util.CachedValueProvider;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.FileViewProvider;
+import com.intellij.openapi.util.UserDataCache;
+import com.intellij.openapi.util.Key;
+import com.intellij.psi.util.CachedValuesManager;
+
+/**
+ * @author Maxim.Mossienko
+* Date: 30.12.2008
+* Time: 21:03:42
+*/
+public abstract class FileBasedUserDataCache<T> extends UserDataCache<CachedValue<T>, PsiFile, Object> {
+ @Override
+ protected CachedValue<T> compute(final PsiFile xmlFile, final Object o) {
+ return CachedValuesManager.getManager(xmlFile.getProject()).createCachedValue(new CachedValueProvider<T>() {
+ @Override
+ public Result<T> compute() {
+
+ return new Result<T>(doCompute(xmlFile), getDependencies(xmlFile));
+ }
+ }, false);
+ }
+
+ protected Object[] getDependencies(PsiFile xmlFile) {
+ return new Object[] {xmlFile};
+ }
+
+ protected abstract T doCompute(PsiFile file);
+ protected abstract Key<CachedValue<T>> getKey();
+
+ public T compute(PsiFile file) {
+ final FileViewProvider fileViewProvider = file.getViewProvider();
+ final PsiFile baseFile = fileViewProvider.getPsi(fileViewProvider.getBaseLanguage());
+ baseFile.getFirstChild(); // expand chameleon out of lock
+ return get(getKey(), baseFile, null).getValue();
+ }
+}
diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/ImplicitIdRefProvider.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/ImplicitIdRefProvider.java
new file mode 100644
index 000000000000..891f0c67e6e4
--- /dev/null
+++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/ImplicitIdRefProvider.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2000-2013 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.psi.impl.source.resolve.reference.impl.providers;
+
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.psi.xml.XmlAttribute;
+import com.intellij.psi.xml.XmlTag;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public interface ImplicitIdRefProvider {
+ ExtensionPointName<ImplicitIdRefProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.xml.implicitIdRefProvider");
+
+ @Nullable
+ XmlAttribute getIdRefAttribute(@NotNull XmlTag tag);
+}
diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java
index b030815ad2a4..7cbc00cc4587 100644
--- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java
+++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java
@@ -89,7 +89,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag {
private volatile long myDescriptorModCount = -1;
private volatile long myExtResourcesModCount = -1;
- private volatile boolean myHaveNamespaceDeclarations = false;
+ private volatile boolean myHasNamespaceDeclarations = false;
private volatile BidirectionalMap<String, String> myNamespaceMap = null;
@NonNls private static final String XML_NS_PREFIX = "xml";
@@ -135,7 +135,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag {
myDescriptorModCount = -1;
myAttributes = null;
myAttributeValueMap = null;
- myHaveNamespaceDeclarations = false;
+ myHasNamespaceDeclarations = false;
myValue = null;
myNSDescriptorsMap = null;
super.clearCaches();
@@ -584,7 +584,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag {
XmlAttribute attribute = (XmlAttribute)element;
result.add(attribute);
cacheOneAttributeValue(attribute.getName(), attribute.getValue(), attributesValueMap);
- myHaveNamespaceDeclarations = myHaveNamespaceDeclarations || attribute.isNamespaceDeclaration();
+ myHasNamespaceDeclarations = myHasNamespaceDeclarations || attribute.isNamespaceDeclaration();
}
else if (element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_TAG_END) {
return false;
@@ -866,7 +866,8 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag {
@Nullable
private BidirectionalMap<String, String> computeNamespaceMap(PsiElement parent) {
BidirectionalMap<String, String> map = null;
- if (hasNamespaceDeclarations()) {
+ boolean hasNamespaceDeclarations = hasNamespaceDeclarations();
+ if (hasNamespaceDeclarations) {
map = new BidirectionalMap<String, String>();
final XmlAttribute[] attributes = getAttributes();
@@ -891,12 +892,12 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag {
if (parent instanceof XmlDocument) {
final XmlExtension extension = XmlExtension.getExtensionByElement(parent);
if (extension != null) {
- final String[][] defaultNamespace = extension.getNamespacesFromDocument((XmlDocument)parent, map != null);
- if (defaultNamespace != null) {
+ final String[][] namespacesFromDocument = extension.getNamespacesFromDocument((XmlDocument)parent, hasNamespaceDeclarations);
+ if (namespacesFromDocument != null) {
if (map == null) {
map = new BidirectionalMap<String, String>();
}
- for (final String[] prefix2ns : defaultNamespace) {
+ for (final String[] prefix2ns : namespacesFromDocument) {
map.put(prefix2ns[0], getRealNs(prefix2ns[1]));
}
}
@@ -930,7 +931,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag {
@Override
public boolean hasNamespaceDeclarations() {
getAttributes();
- return myHaveNamespaceDeclarations;
+ return myHasNamespaceDeclarations;
}
@Override