This commit is contained in:
Alexey Kudravtsev
2017-12-14 14:24:02 +03:00
parent 49c35f06d3
commit 02a852d1ba
14 changed files with 99 additions and 67 deletions
@@ -17,14 +17,15 @@ package com.intellij.psi.impl.source.tree;
import com.intellij.psi.impl.source.javadoc.PsiDocTagValueImpl;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
/**
* @author max
*/
public class JavaASTFactory extends CoreJavaASTFactory {
@Override
public CompositeElement createComposite(final IElementType type) {
if (type == DOC_TAG_VALUE_ELEMENT) {
public CompositeElement createComposite(@NotNull final IElementType type) {
if (type == JavaDocElementType.DOC_TAG_VALUE_ELEMENT) {
return new PsiDocTagValueImpl();
}
@@ -18,7 +18,7 @@ package com.intellij.psi.impl.source.tree;
import com.intellij.lang.ASTFactory;
import com.intellij.lang.DefaultASTFactory;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.psi.impl.source.Constants;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.impl.source.javadoc.CorePsiDocTagValueImpl;
import com.intellij.psi.impl.source.javadoc.PsiDocTokenImpl;
import com.intellij.psi.impl.source.tree.java.PsiIdentifierImpl;
@@ -32,25 +32,25 @@ import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
public class CoreJavaASTFactory extends ASTFactory implements Constants {
public class CoreJavaASTFactory extends ASTFactory {
private final DefaultASTFactory myDefaultASTFactory = ServiceManager.getService(DefaultASTFactory.class);
@Override
public LeafElement createLeaf(@NotNull final IElementType type, @NotNull final CharSequence text) {
if (type == C_STYLE_COMMENT || type == END_OF_LINE_COMMENT) {
if (type == JavaTokenType.C_STYLE_COMMENT || type == JavaTokenType.END_OF_LINE_COMMENT) {
return myDefaultASTFactory.createComment(type, text);
}
else if (type == IDENTIFIER) {
if (type == JavaTokenType.IDENTIFIER) {
return new PsiIdentifierImpl(text);
}
else if (KEYWORD_BIT_SET.contains(type)) {
if (ElementType.KEYWORD_BIT_SET.contains(type)) {
return new PsiKeywordImpl(type, text);
}
else if (type instanceof IJavaElementType) {
if (type instanceof IJavaElementType) {
return new PsiJavaTokenImpl(type, text);
}
else if (type instanceof IJavaDocElementType) {
assert type != DOC_TAG_VALUE_ELEMENT;
if (type instanceof IJavaDocElementType) {
assert type != JavaDocElementType.DOC_TAG_VALUE_ELEMENT;
return new PsiDocTokenImpl(type, text);
}
@@ -58,8 +58,8 @@ public class CoreJavaASTFactory extends ASTFactory implements Constants {
}
@Override
public CompositeElement createComposite(IElementType type) {
if (type == DOC_TAG_VALUE_ELEMENT) {
public CompositeElement createComposite(@NotNull IElementType type) {
if (type == JavaDocElementType.DOC_TAG_VALUE_ELEMENT) {
return new CorePsiDocTagValueImpl();
}
return null;
@@ -74,7 +74,8 @@ public abstract class LiteralTextEscaper<T extends PsiLanguageInjectionHost> {
*/
public abstract boolean isOneLine();
public static <T extends PsiLanguageInjectionHost> LiteralTextEscaper<T> createSimple(T element) {
@NotNull
public static <T extends PsiLanguageInjectionHost> LiteralTextEscaper<T> createSimple(@NotNull T element) {
return new LiteralTextEscaper<T>(element) {
@Override
public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
@@ -108,7 +108,7 @@ public class PsiInvalidElementAccessException extends RuntimeException implement
private static Object getPsiInvalidationTrace(@NotNull PsiElement element) {
Object trace = getInvalidationTrace(element);
if (trace != null) return trace;
if (element instanceof PsiFile) {
return getInvalidationTrace(((PsiFile)element).getOriginalFile());
}
@@ -167,7 +167,9 @@ public class PsiInvalidElementAccessException extends RuntimeException implement
@NonNls
@NotNull
public static String findOutInvalidationReason(@NotNull PsiElement root) {
if (root == PsiUtilCore.NULL_PSI_ELEMENT) return "NULL_PSI_ELEMENT";
if (root == PsiUtilCore.NULL_PSI_ELEMENT) {
return "NULL_PSI_ELEMENT";
}
PsiElement element = root instanceof PsiFile ? root : root.getParent();
if (element == null) {
@@ -188,11 +190,15 @@ public class PsiInvalidElementAccessException extends RuntimeException implement
while (element != null && !(element instanceof PsiFile)) element = element.getParent();
PsiFile file = (PsiFile)element;
if (file == null) return "containing file is null";
if (file == null) {
return "containing file is null";
}
FileViewProvider provider = file.getViewProvider();
VirtualFile vFile = provider.getVirtualFile();
if (!vFile.isValid()) return vFile + " is invalid";
if (!vFile.isValid()) {
return vFile + " is invalid";
}
if (!provider.isPhysical()) {
PsiElement context = file.getContext();
if (context != null && !context.isValid()) {
@@ -206,15 +212,23 @@ public class PsiInvalidElementAccessException extends RuntimeException implement
}
PsiManager manager = file.getManager();
if (manager.getProject().isDisposed()) return "project is disposed";
if (manager.getProject().isDisposed()) {
return "project is disposed";
}
Language language = file.getLanguage();
if (language != provider.getBaseLanguage()) return "File language:" + language + " != Provider base language:" + provider.getBaseLanguage();
if (language != provider.getBaseLanguage()) {
return "File language:" + language + " != Provider base language:" + provider.getBaseLanguage();
}
FileViewProvider p = manager.findViewProvider(vFile);
if (provider != p) return "different providers: " + provider + "(" + id(provider) + "); " + p + "(" + id(p) + ")";
if (provider != p) {
return "different providers: " + provider + "(" + id(provider) + "); " + p + "(" + id(p) + ")";
}
if (!provider.isPhysical()) return "non-physical provider: " + provider; // "dummy" file?
if (!provider.isPhysical()) {
return "non-physical provider: " + provider; // "dummy" file?
}
return "psi is outdated";
}
@@ -46,7 +46,7 @@ public interface PsiLanguageInjectionHost extends PsiElement {
/**
* Update the host element using the provided text of the injected file. It may be required to escape characters from {@code text}
* in accordance with the host language syntax. The implementation may delegate to {@link ElementManipulators#handleContentChange(PsiElement, String)}
* if {@link com.intellij.psi.ElementManipulator} implementation is registered for this element class
* if {@link ElementManipulator} implementation is registered for this element class
* @param text text of the injected file
* @return the updated instance
*/
@@ -42,12 +42,12 @@ public abstract class ASTFactory {
// interface methods
@Nullable
public LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text) {
public LazyParseableElement createLazy(@NotNull ILazyParseableElementType type, final CharSequence text) {
return null;
}
@Nullable
public CompositeElement createComposite(final IElementType type) {
public CompositeElement createComposite(@NotNull IElementType type) {
return null;
}
@@ -66,7 +66,7 @@ public abstract class ASTFactory {
if (type == TokenType.CODE_FRAGMENT) {
return new CodeFragmentElement(null);
}
else if (type == TokenType.DUMMY_HOLDER) {
if (type == TokenType.DUMMY_HOLDER) {
return new DummyHolderElement(text);
}
@@ -98,7 +98,6 @@ public abstract class ASTFactory {
return customLeaf != null ? customLeaf : DefaultFactoryHolder.DEFAULT.createLeaf(type, text);
}
@Nullable
private static ASTFactory factory(final IElementType type) {
return LanguageASTFactory.INSTANCE.forLanguage(type.getLanguage());
}
@@ -373,7 +373,7 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
@NotNull final ModalityState modalityState) {
IndicatorDisposable indicatorDisposable;
if (progressIndicator instanceof Disposable) {
// use CancelIndicatorDisposable instead of progressIndicator to
// use IndicatorDisposable instead of progressIndicator to
// avoid re-registering progressIndicator if it was registered on some other parent before
indicatorDisposable = new IndicatorDisposable(progressIndicator);
Disposer.register(ApplicationManager.getApplication(), indicatorDisposable);
@@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable;
public class PropertiesASTFactory extends ASTFactory {
@Override
@Nullable
public CompositeElement createComposite(final IElementType type) {
public CompositeElement createComposite(@NotNull final IElementType type) {
if (type instanceof IFileElementType) {
return new FileElement(type, null);
}
@@ -43,6 +43,7 @@ public class PropertyImpl extends PropertiesStubElementImpl<PropertyStub> implem
return "Property{ key = " + getKey() + ", value = " + getValue() + "}";
}
@Override
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
PropertyImpl property = (PropertyImpl)PropertiesElementFactory.createProperty(getProject(), name, "xxx", null);
ASTNode keyNode = getKeyNode();
@@ -57,6 +58,7 @@ public class PropertyImpl extends PropertiesStubElementImpl<PropertyStub> implem
return this;
}
@Override
public void setValue(@NotNull String value) throws IncorrectOperationException {
ASTNode node = getValueNode();
PropertyImpl property = (PropertyImpl)PropertiesElementFactory.createProperty(getProject(), "xxx", value, getKeyValueDelimiter());
@@ -76,10 +78,12 @@ public class PropertyImpl extends PropertiesStubElementImpl<PropertyStub> implem
}
}
@Override
public String getName() {
return getUnescapedKey();
}
@Override
public String getKey() {
final PropertyStub stub = getStub();
if (stub != null) {
@@ -103,6 +107,7 @@ public class PropertyImpl extends PropertiesStubElementImpl<PropertyStub> implem
return getNode().findChildByType(PropertiesTokenTypes.VALUE_CHARACTERS);
}
@Override
public String getValue() {
final ASTNode node = getValueNode();
if (node == null) {
@@ -111,6 +116,7 @@ public class PropertyImpl extends PropertiesStubElementImpl<PropertyStub> implem
return node.getText();
}
@Override
@Nullable
public String getUnescapedValue() {
return unescape(getValue());
@@ -335,6 +341,7 @@ public class PropertyImpl extends PropertiesStubElementImpl<PropertyStub> implem
return startSpaces == -1 ? null : new TextRange(startSpaces, len);
}
@Override
@Nullable
public String getUnescapedKey() {
return unescape(getKey());
@@ -346,6 +353,7 @@ public class PropertyImpl extends PropertiesStubElementImpl<PropertyStub> implem
return PlatformIcons.PROPERTY_ICON;
}
@Override
public void delete() throws IncorrectOperationException {
final ASTNode parentNode = getParent().getNode();
assert parentNode != null;
@@ -360,10 +368,12 @@ public class PropertyImpl extends PropertiesStubElementImpl<PropertyStub> implem
}
}
@Override
public PropertiesFile getPropertiesFile() {
return (PropertiesFile)super.getContainingFile();
}
@Override
public String getDocCommentText() {
StringBuilder text = new StringBuilder();
for (PsiElement doc = getPrevSibling(); doc != null; doc = doc.getPrevSibling()) {
@@ -389,22 +399,27 @@ public class PropertyImpl extends PropertiesStubElementImpl<PropertyStub> implem
return this;
}
@Override
@NotNull
public SearchScope getUseScope() {
// property ref can occur in any file
return GlobalSearchScope.allScope(getProject());
}
@Override
public ItemPresentation getPresentation() {
return new ItemPresentation() {
@Override
public String getPresentableText() {
return getName();
}
@Override
public String getLocationString() {
return getPropertiesFile().getName();
}
@Override
public Icon getIcon(final boolean open) {
return null;
}
@@ -8,12 +8,12 @@ import org.jetbrains.annotations.NotNull;
/**
* @author gregsh
*/
public class PropertyImplEscaper extends LiteralTextEscaper<PropertyImpl> {
class PropertyImplEscaper extends LiteralTextEscaper<PropertyImpl> {
private static final Logger LOG = Logger.getInstance(PropertyImplEscaper.class);
private int[] outSourceOffsets;
public PropertyImplEscaper(PropertyImpl value) {
PropertyImplEscaper(@NotNull PropertyImpl value) {
super(value);
}
@@ -348,10 +348,12 @@ public class PyStringLiteralExpressionImpl extends PyElementImpl implements PySt
};
}
@Override
public PsiLanguageInjectionHost updateText(@NotNull String text) {
return ElementManipulators.handleContentChange(this, text);
}
@Override
@NotNull
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
return new StringLiteralTextEscaper(this);
@@ -35,80 +35,80 @@ import static com.intellij.psi.xml.XmlElementType.*;
public class XmlASTFactory extends ASTFactory {
@Override
public CompositeElement createComposite(final IElementType type) {
public CompositeElement createComposite(@NotNull final IElementType type) {
if (type == XML_TAG) {
return new XmlTagImpl();
}
else if (type == XML_CONDITIONAL_SECTION) {
if (type == XML_CONDITIONAL_SECTION) {
return new XmlConditionalSectionImpl();
}
else if (type == HTML_TAG) {
if (type == HTML_TAG) {
return new HtmlTagImpl();
}
else if (type == XML_TEXT) {
if (type == XML_TEXT) {
return new XmlTextImpl();
}
else if (type == XML_PROCESSING_INSTRUCTION) {
if (type == XML_PROCESSING_INSTRUCTION) {
return new XmlProcessingInstructionImpl();
}
else if (type == XML_DOCUMENT) {
if (type == XML_DOCUMENT) {
return new XmlDocumentImpl();
}
else if (type == HTML_DOCUMENT) {
if (type == HTML_DOCUMENT) {
return new HtmlDocumentImpl();
}
else if (type == XML_PROLOG) {
if (type == XML_PROLOG) {
return new XmlPrologImpl();
}
else if (type == XML_DECL) {
if (type == XML_DECL) {
return new XmlDeclImpl();
}
else if (type == XML_ATTRIBUTE) {
if (type == XML_ATTRIBUTE) {
return new XmlAttributeImpl();
}
else if (type == XML_ATTRIBUTE_VALUE) {
if (type == XML_ATTRIBUTE_VALUE) {
return new XmlAttributeValueImpl();
}
else if (type == XML_COMMENT) {
if (type == XML_COMMENT) {
return new XmlCommentImpl();
}
else if (type == XML_DOCTYPE) {
if (type == XML_DOCTYPE) {
return new XmlDoctypeImpl();
}
else if (type == XML_MARKUP_DECL) {
if (type == XML_MARKUP_DECL) {
return new XmlMarkupDeclImpl();
}
else if (type == XML_ELEMENT_DECL) {
if (type == XML_ELEMENT_DECL) {
return new XmlElementDeclImpl();
}
else if (type == XML_ENTITY_DECL) {
if (type == XML_ENTITY_DECL) {
return new XmlEntityDeclImpl();
}
else if (type == XML_ATTLIST_DECL) {
if (type == XML_ATTLIST_DECL) {
return new XmlAttlistDeclImpl();
}
else if (type == XML_ATTRIBUTE_DECL) {
if (type == XML_ATTRIBUTE_DECL) {
return new XmlAttributeDeclImpl();
}
else if (type == XML_NOTATION_DECL) {
if (type == XML_NOTATION_DECL) {
return new XmlNotationDeclImpl();
}
else if (type == XML_ELEMENT_CONTENT_SPEC) {
if (type == XML_ELEMENT_CONTENT_SPEC) {
return new XmlElementContentSpecImpl();
}
else if (type == XML_ELEMENT_CONTENT_GROUP) {
if (type == XML_ELEMENT_CONTENT_GROUP) {
return new XmlElementContentGroupImpl();
}
else if (type == XML_ENTITY_REF) {
if (type == XML_ENTITY_REF) {
return new XmlEntityRefImpl();
}
else if (type == XML_ENUMERATED_TYPE) {
if (type == XML_ENUMERATED_TYPE) {
return new XmlEnumeratedTypeImpl();
}
else if (type == XML_CDATA) {
if (type == XML_CDATA) {
return new CompositePsiElement(XML_CDATA) {};
}
else if (type instanceof ITemplateDataElementType) {
if (type instanceof ITemplateDataElementType) {
return new XmlFileElement(type, null);
}
@@ -116,20 +116,20 @@ public class XmlASTFactory extends ASTFactory {
}
@Override
public LazyParseableElement createLazy(ILazyParseableElementType type, CharSequence text) {
public LazyParseableElement createLazy(@NotNull ILazyParseableElementType type, CharSequence text) {
if (type == XML_FILE) {
return new XmlFileElement(type, text);
}
else if (type == DTD_FILE) {
if (type == DTD_FILE) {
return new XmlFileElement(type, text);
}
else if (type == XHTML_FILE) {
if (type == XHTML_FILE) {
return new XmlFileElement(type, text);
}
else if (type == HTML_FILE) {
if (type == HTML_FILE) {
return new HtmlFileElement(text);
}
else if (type instanceof ITemplateDataElementType) {
if (type instanceof ITemplateDataElementType) {
return new XmlFileElement(type, text);
}
return null;
@@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull;
* @author cdr
*/
public class XmlTextLiteralEscaper extends LiteralTextEscaper<XmlTextImpl> {
public XmlTextLiteralEscaper(final XmlTextImpl xmlText) {
public XmlTextLiteralEscaper(@NotNull XmlTextImpl xmlText) {
super(xmlText);
}
@@ -98,11 +98,11 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText, PsiLanguageI
LOG.assertTrue(text != null, child);
buffer.append(XmlUtil.getCharFromEntityRef(text));
}
else if (elementType == XmlTokenType.XML_WHITE_SPACE || elementType == XmlTokenType.XML_DATA_CHARACTERS || elementType == XmlTokenType
.XML_ATTRIBUTE_VALUE_TOKEN) {
buffer.append(child.getText());
}
else if (elementType == TokenType.ERROR_ELEMENT || elementType == TokenType.NEW_LINE_INDENT) {
else if (elementType == XmlTokenType.XML_WHITE_SPACE ||
elementType == XmlTokenType.XML_DATA_CHARACTERS ||
elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN ||
elementType == TokenType.ERROR_ELEMENT ||
elementType == TokenType.NEW_LINE_INDENT) {
buffer.append(child.getText());
}
@@ -379,11 +379,11 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText, PsiLanguageI
public TextRange getCDATAInterior() {
PsiElement[] elements = getChildren();
int start = 0;
int first = 0;
if (elements.length > 0 && elements[0] instanceof PsiWhiteSpace) {
first ++;
}
int start = 0;
if (elements.length > first && elements[first].getNode().getElementType() == XmlElementType.XML_CDATA) {
ASTNode startNode = elements[first].getNode().findChildByType(XmlTokenType.XML_CDATA_START);
if (startNode != null) {