This commit is contained in:
Alexey Kudravtsev
2015-01-21 15:53:46 +03:00
parent 785fe8316d
commit 968e8ea0b5
16 changed files with 87 additions and 38 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -41,6 +41,7 @@ public interface ASTNode extends UserDataHolder {
*
* @return the element type.
*/
@NotNull
IElementType getElementType();
/**
@@ -48,6 +49,7 @@ public interface ASTNode extends UserDataHolder {
*
* @return the node text.
*/
@NotNull
String getText();
/**
@@ -55,6 +57,7 @@ public interface ASTNode extends UserDataHolder {
*
* @return the node text.
*/
@NotNull
CharSequence getChars();
/**
@@ -129,6 +132,7 @@ public interface ASTNode extends UserDataHolder {
* all children should be returned.
* @return the children array.
*/
@NotNull
ASTNode[] getChildren(@Nullable TokenSet filter);
/**
@@ -201,6 +205,7 @@ public interface ASTNode extends UserDataHolder {
*
* @return the top node of the copied tree (as an ASTNode object)
*/
@NotNull
Object clone();
/**
@@ -228,7 +233,7 @@ public interface ASTNode extends UserDataHolder {
* @see #putCopyableUserData(com.intellij.openapi.util.Key, Object)
*/
@Nullable
<T> T getCopyableUserData(Key<T> key);
<T> T getCopyableUserData(@NotNull Key<T> key);
/**
* Attaches a copyable user data object to this node. Copyable user data objects are copied
@@ -238,7 +243,7 @@ public interface ASTNode extends UserDataHolder {
* @param value the user data object to attach.
* @see #getCopyableUserData(com.intellij.openapi.util.Key)
*/
<T> void putCopyableUserData(Key<T> key, T value);
<T> void putCopyableUserData(@NotNull Key<T> key, T value);
/**
* Returns the first child of the specified node which has the specified type.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -153,12 +153,12 @@ public abstract class ASTDelegatePsiElement extends PsiElementBase {
}
@Override
public <T> T getCopyableUserData(Key<T> key) {
public <T> T getCopyableUserData(@NotNull Key<T> key) {
return getNode().getCopyableUserData(key);
}
@Override
public <T> void putCopyableUserData(Key<T> key, T value) {
public <T> void putCopyableUserData(@NotNull Key<T> key, T value) {
getNode().putCopyableUserData(key, value);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -34,8 +34,9 @@ public class ASTShallowComparator implements ShallowNodeComparator<ASTNode, ASTN
myIndicator = indicator;
}
@NotNull
@Override
public ThreeState deepEqual(final ASTNode oldNode, final ASTNode newNode) {
public ThreeState deepEqual(@NotNull final ASTNode oldNode, @NotNull final ASTNode newNode) {
return textMatches(oldNode, newNode);
}
@@ -105,12 +106,12 @@ public class ASTShallowComparator implements ShallowNodeComparator<ASTNode, ASTN
}
@Override
public boolean typesEqual(final ASTNode n1, final ASTNode n2) {
public boolean typesEqual(@NotNull final ASTNode n1, @NotNull final ASTNode n2) {
return n1.getElementType() == n2.getElementType();
}
@Override
public boolean hashCodesEqual(final ASTNode n1, final ASTNode n2) {
public boolean hashCodesEqual(@NotNull final ASTNode n1, @NotNull final ASTNode n2) {
if (n1 instanceof LeafElement && n2 instanceof LeafElement) {
return textMatches(n1, n2) == ThreeState.YES;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -68,6 +68,7 @@ public class CompositeElement extends TreeElement {
return myModificationsCount;
}
@NotNull
@Override
public CompositeElement clone() {
CompositeElement clone = (CompositeElement)super.clone();
@@ -261,6 +262,7 @@ public class CompositeElement extends TreeElement {
return StringFactory.createShared(textToCharArray());
}
@NotNull
@Override
public CharSequence getChars() {
return getText();
@@ -448,6 +450,7 @@ public class CompositeElement extends TreeElement {
return 0; //ChildRole.NONE;
}
@NotNull
@Override
public ASTNode[] getChildren(@Nullable TokenSet filter) {
int count = countChildren(filter);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -47,6 +47,7 @@ public abstract class CompositePsiElement extends CompositeElement implements Ps
setPsi(this);
}
@NotNull
@Override
public CompositePsiElement clone() {
CompositePsiElement clone = (CompositePsiElement)super.clone();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -26,7 +26,7 @@ import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class ForeignLeafPsiElement extends LeafPsiElement {
private final ForeignLeafType myForeignType;
@NotNull private final ForeignLeafType myForeignType;
public ForeignLeafPsiElement(@NotNull ForeignLeafType type, CharSequence text) {
super(dereferenceElementType(type.getDelegate()), text);
@@ -76,6 +76,7 @@ public class ForeignLeafPsiElement extends LeafPsiElement {
return 0;
}
@NotNull
public ForeignLeafType getForeignType() {
return myForeignType;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -53,6 +53,7 @@ public class LazyParseablePsiElement extends LazyParseableElement implements Psi
setPsi(this);
}
@NotNull
@Override
public LazyParseablePsiElement clone() {
LazyParseablePsiElement clone = (LazyParseablePsiElement)super.clone();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -42,6 +42,7 @@ public abstract class LeafElement extends TreeElement {
myText = text;
}
@NotNull
@Override
public LeafElement clone() {
LeafElement clone = (LeafElement)super.clone();
@@ -54,11 +55,13 @@ public abstract class LeafElement extends TreeElement {
return myText.length();
}
@NotNull
@Override
public CharSequence getChars() {
return myText;
}
@NotNull
@Override
public String getText() {
if (myText.length() > 1000 && !(myText instanceof String)) { // e.g. a large text file
@@ -239,6 +242,7 @@ public abstract class LeafElement extends TreeElement {
return getNotCachedLength();
}
@NotNull
@Override
public ASTNode[] getChildren(TokenSet filter) {
return EMPTY_ARRAY;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -44,6 +44,7 @@ public abstract class TreeElement extends ElementBase implements ASTNode, Clonea
myType = type;
}
@NotNull
@Override
public Object clone() {
TreeElement clone = (TreeElement)super.clone();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -512,16 +512,17 @@ public class PsiBuilderQuickTest extends LightPlatformLangTestCase {
DiffTree.diff(
new ASTStructure(root), builder2.getLightTree(),
new ShallowNodeComparator<ASTNode, LighterASTNode>() {
@NotNull
@Override
public ThreeState deepEqual(ASTNode oldNode, LighterASTNode newNode) {
public ThreeState deepEqual(@NotNull ASTNode oldNode, @NotNull LighterASTNode newNode) {
return ThreeState.UNSURE;
}
@Override
public boolean typesEqual(ASTNode oldNode, LighterASTNode newNode) {
public boolean typesEqual(@NotNull ASTNode oldNode, @NotNull LighterASTNode newNode) {
return true;
}
@Override
public boolean hashCodesEqual(ASTNode oldNode, LighterASTNode newNode) {
public boolean hashCodesEqual(@NotNull ASTNode oldNode, @NotNull LighterASTNode newNode) {
return true;
}
},
@@ -1,5 +1,17 @@
/*
* Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
* Copyright 2000-2015 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.mock;
@@ -160,7 +172,7 @@ public class MockPsiElement extends UserDataHolderBase implements PsiElement, Na
@Override
@Nullable
public <T> T getCopyableUserData(final Key<T> key) {
public <T> T getCopyableUserData(@NotNull final Key<T> key) {
throw new UnsupportedOperationException("Method getCopyableUserData is not yet implemented in " + getClass().getName());
}
@@ -336,7 +348,7 @@ public class MockPsiElement extends UserDataHolderBase implements PsiElement, Na
}
@Override
public <T> void putCopyableUserData(final Key<T> key, final T value) {
public <T> void putCopyableUserData(@NotNull final Key<T> key, final T value) {
throw new UnsupportedOperationException("Method putCopyableUserData is not yet implemented in " + getClass().getName());
}
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2015 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.mock;
import com.intellij.lang.FileASTNode;
@@ -308,12 +323,12 @@ public class MockPsiFile extends MockPsiElement implements PsiFile {
}
@Override
public <T> T getCopyableUserData(Key<T> key) {
public <T> T getCopyableUserData(@NotNull Key<T> key) {
return null;
}
@Override
public <T> void putCopyableUserData(Key<T> key, T value) {
public <T> void putCopyableUserData(@NotNull Key<T> key, T value) {
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -80,13 +80,13 @@ public class UserDataHolderBase implements UserDataHolderEx, Cloneable {
return updater.compareAndSet(this, oldMap, newMap);
}
public <T> T getCopyableUserData(Key<T> key) {
public <T> T getCopyableUserData(@NotNull Key<T> key) {
KeyFMap map = getUserData(COPYABLE_USER_MAP_KEY);
//noinspection unchecked,ConstantConditions
return map == null ? null : map.get(key);
}
public <T> void putCopyableUserData(Key<T> key, T value) {
public <T> void putCopyableUserData(@NotNull Key<T> key, T value) {
while (true) {
KeyFMap map = getUserMap();
KeyFMap copyableMap = map.get(COPYABLE_USER_MAP_KEY);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -17,12 +17,14 @@
package com.intellij.util.diff;
import com.intellij.util.ThreeState;
import org.jetbrains.annotations.NotNull;
/**
* @author max
*/
public interface ShallowNodeComparator<OT, NT> {
ThreeState deepEqual(OT oldNode, NT newNode);
boolean typesEqual(OT oldNode, NT newNode);
boolean hashCodesEqual(OT oldNode, NT newNode);
@NotNull
ThreeState deepEqual(@NotNull OT oldNode, @NotNull NT newNode);
boolean typesEqual(@NotNull OT oldNode, @NotNull NT newNode);
boolean hashCodesEqual(@NotNull OT oldNode, @NotNull NT newNode);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -93,18 +93,19 @@ public class DiffTreeTest extends TestCase {
}
private static class NodeComparator implements ShallowNodeComparator<Node, Node> {
@NotNull
@Override
public ThreeState deepEqual(final Node node, final Node node1) {
public ThreeState deepEqual(@NotNull final Node node, @NotNull final Node node1) {
return ThreeState.UNSURE;
}
@Override
public boolean typesEqual(final Node node, final Node node1) {
public boolean typesEqual(@NotNull final Node node, @NotNull final Node node1) {
return node.getId() == node1.getId();
}
@Override
public boolean hashCodesEqual(final Node node, final Node node1) {
public boolean hashCodesEqual(@NotNull final Node node, @NotNull final Node node1) {
return node.hashCode() == node1.hashCode();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -350,6 +350,7 @@ public class XmlDocumentImpl extends XmlElementImpl implements XmlDocument {
return descriptor;
}
@NotNull
@Override
public CompositePsiElement clone() {
HashMap<String, CachedValue<XmlNSDescriptor>> cacheStrict = new HashMap<String, CachedValue<XmlNSDescriptor>>(