Merge branch 'daniil/udh-unprotected'

This commit is contained in:
Daniil Ovchinnikov
2018-06-13 19:26:02 +03:00
11 changed files with 75 additions and 128 deletions
@@ -110,22 +110,22 @@ public class JavaParserUtil {
private JavaParserUtil() { }
public static void setLanguageLevel(final PsiBuilder builder, final LanguageLevel level) {
builder.putUserDataUnprotected(LANG_LEVEL_KEY, level);
builder.putUserData(LANG_LEVEL_KEY, level);
}
@NotNull
public static LanguageLevel getLanguageLevel(final PsiBuilder builder) {
final LanguageLevel level = builder.getUserDataUnprotected(LANG_LEVEL_KEY);
final LanguageLevel level = builder.getUserData(LANG_LEVEL_KEY);
assert level != null : builder;
return level;
}
public static void setParseStatementCodeBlocksDeep(final PsiBuilder builder, final boolean deep) {
builder.putUserDataUnprotected(DEEP_PARSE_BLOCKS_IN_STATEMENTS, deep);
builder.putUserData(DEEP_PARSE_BLOCKS_IN_STATEMENTS, deep);
}
public static boolean isParseStatementCodeBlocksDeep(final PsiBuilder builder) {
return Boolean.TRUE.equals(builder.getUserDataUnprotected(DEEP_PARSE_BLOCKS_IN_STATEMENTS));
return Boolean.TRUE.equals(builder.getUserData(DEEP_PARSE_BLOCKS_IN_STATEMENTS));
}
@NotNull
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.java.parser;
import com.intellij.lang.PsiBuilder;
@@ -249,12 +249,12 @@ public class JavadocParser {
}
private static int getBraceScope(PsiBuilder builder) {
Integer braceScope = builder.getUserDataUnprotected(BRACE_SCOPE_KEY);
Integer braceScope = builder.getUserData(BRACE_SCOPE_KEY);
return braceScope != null ? braceScope : 0;
}
private static void setBraceScope(PsiBuilder builder, int braceScope) {
builder.putUserDataUnprotected(BRACE_SCOPE_KEY, braceScope);
builder.putUserData(BRACE_SCOPE_KEY, braceScope);
}
private static void remapAndAdvance(PsiBuilder builder) {
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang;
import com.intellij.openapi.project.Project;
@@ -32,6 +18,7 @@ import org.jetbrains.annotations.Nullable;
* @see PsiParser
* @see ASTNode
*/
@SuppressWarnings("deprecation")
public interface PsiBuilder extends UserDataHolder, UserDataHolderUnprotected {
/**
* Returns a project for which PSI builder was created (see {@link PsiBuilderFactory}).
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.impl;
import com.intellij.lang.*;
@@ -156,11 +142,13 @@ public class PsiBuilderAdapter implements PsiBuilder {
myDelegate.putUserData(key, value);
}
@SuppressWarnings("deprecation")
@Override
public <T> T getUserDataUnprotected(@NotNull final Key<T> key) {
return myDelegate.getUserDataUnprotected(key);
}
@SuppressWarnings("deprecation")
@Override
public <T> void putUserDataUnprotected(@NotNull final Key<T> key, @Nullable final T value) {
myDelegate.putUserDataUnprotected(key, value);
@@ -13,11 +13,11 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.TokenType;
import com.intellij.psi.impl.BlockSupportImpl;
import com.intellij.psi.impl.DiffLog;
import com.intellij.psi.impl.PsiDocumentManagerBase;
import com.intellij.psi.impl.source.CharTableImpl;
import com.intellij.psi.impl.source.resolve.FileContextUtil;
import com.intellij.psi.impl.BlockSupportImpl;
import com.intellij.psi.impl.DiffLog;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.impl.source.tree.Factory;
import com.intellij.psi.text.BlockSupport;
@@ -40,7 +40,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.AbstractList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static com.intellij.lang.WhitespacesBinders.DEFAULT_RIGHT_BINDER;
@@ -48,7 +47,7 @@ import static com.intellij.lang.WhitespacesBinders.DEFAULT_RIGHT_BINDER;
/**
* @author max
*/
public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
public class PsiBuilderImpl extends UnprotectedUserDataHolder implements PsiBuilder {
private static final Logger LOG = Logger.getInstance("#com.intellij.lang.impl.PsiBuilderImpl");
// function stored in PsiBuilderImpl' user data which called during reparse when merge algorithm is not sure what to merge
@@ -85,7 +84,6 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
private final MyTreeStructure myParentLightTree;
private final int myOffset;
private Map<Key, Object> myUserData;
private IElementType myCachedTokenType;
private final TIntObjectHashMap<LazyParseableToken> myChameleonCache = new TIntObjectHashMap<>();
@@ -991,7 +989,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
MyTreeStructure treeStructure = new MyTreeStructure(newRoot, null);
final List<CustomLanguageASTComparator> customLanguageASTComparators = CustomLanguageASTComparator.getMatchingComparators(myFile);
ShallowNodeComparator<ASTNode, LighterASTNode> comparator =
new MyComparator(getUserDataUnprotected(CUSTOM_COMPARATOR), customLanguageASTComparators, treeStructure);
new MyComparator(getUserData(CUSTOM_COMPARATOR), customLanguageASTComparators, treeStructure);
ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
BlockSupportImpl.diffTrees(oldRoot, builder, comparator, treeStructure, indicator == null ? new EmptyProgressIndicator() : indicator,
@@ -1719,18 +1717,17 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
@SuppressWarnings("unchecked")
@Override
public <T> T getUserDataUnprotected(@NotNull final Key<T> key) {
public <T> T getUserData(@NotNull Key<T> key) {
if (key == FileContextUtil.CONTAINING_FILE_KEY) return (T)myFile;
return myUserData != null ? (T)myUserData.get(key) : null;
return super.getUserData(key);
}
@Override
public <T> void putUserDataUnprotected(@NotNull final Key<T> key, @Nullable final T value) {
public <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {
if (key == FileContextUtil.CONTAINING_FILE_KEY) {
myFile = (PsiFile)value;
return;
}
if (myUserData == null) myUserData = ContainerUtil.newHashMap();
myUserData.put(key, value);
super.putUserData(key, value);
}
}
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.parser;
@@ -956,7 +942,7 @@ public class GeneratedParserUtilBase {
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) {
state.extendsSets = extendsSets;
PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
PsiFile file = builder.getUserData(FileContextUtil.CONTAINING_FILE_KEY);
state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
Language language = file == null? root.getLanguage() : file.getLanguage();
state.caseSensitive = language.isCaseSensitive();
@@ -0,0 +1,41 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.util;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
/**
* Non thread safe version of {@link UserDataHolderBase}.
*/
@SuppressWarnings("deprecation")
public class UnprotectedUserDataHolder implements UserDataHolder, UserDataHolderUnprotected {
private Map<Key, Object> myUserData;
@SuppressWarnings("unchecked")
@Nullable
@Override
public <T> T getUserData(@NotNull Key<T> key) {
return myUserData != null ? (T)myUserData.get(key) : null;
}
@Override
public <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {
if (myUserData == null) myUserData = ContainerUtil.newHashMap();
myUserData.put(key, value);
}
@Nullable
@Override
public <T> T getUserDataUnprotected(@NotNull Key<T> key) {
return getUserData(key);
}
@Override
public <T> void putUserDataUnprotected(@NotNull Key<T> key, @Nullable T value) {
putUserData(key, value);
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2010 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.util;
import org.jetbrains.annotations.NotNull;
@@ -22,9 +8,13 @@ import org.jetbrains.annotations.Nullable;
* Like UserDataHolder, but stores data in non-thread-safe way.
* Should not be accessed across threads.
*/
@Deprecated
public interface UserDataHolderUnprotected {
@Deprecated
@Nullable
<T> T getUserDataUnprotected(@NotNull Key<T> key);
@Deprecated
<T> void putUserDataUnprotected(@NotNull Key<T> key, @Nullable T value);
}
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.properties.parsing;
import com.intellij.lang.*;
@@ -78,7 +64,7 @@ public class PropertiesParser implements PsiParser {
}
public void doParse(IElementType root, PsiBuilder builder) {
builder.putUserDataUnprotected(PsiBuilderImpl.CUSTOM_COMPARATOR, MATCH_BY_KEY);
builder.putUserData(PsiBuilderImpl.CUSTOM_COMPARATOR, MATCH_BY_KEY);
final PsiBuilder.Marker rootMarker = builder.mark();
final PsiBuilder.Marker propertiesList = builder.mark();
while (!builder.eof()) {
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.impl.source.parsing.xml;
import com.intellij.codeInsight.daemon.XmlErrorMessages;
@@ -72,7 +58,7 @@ public class DtdParsing extends XmlParsing implements XmlElementType {
}, chars
)
);
if (contextFile != null) myBuilder.putUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY, contextFile);
if (contextFile != null) myBuilder.putUserData(FileContextUtil.CONTAINING_FILE_KEY, contextFile);
}
public ASTNode parse() {
@@ -119,7 +105,7 @@ public class DtdParsing extends XmlParsing implements XmlElementType {
ASTNode astNode = myBuilder.getTreeBuilt();
if (myRootType != DTD_FILE) {
PsiFile file = myBuilder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
PsiFile file = myBuilder.getUserData(FileContextUtil.CONTAINING_FILE_KEY);
if (file != null) {
final DummyHolder result = DummyHolderFactory.createHolder(file.getManager(), DTDLanguage.INSTANCE, file);
final FileElement holder = result.getTreeElement();
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
/*
* @author max
@@ -58,7 +44,7 @@ public class XmlParser implements PsiParser {
@NotNull
public ASTNode parse(final IElementType root, final PsiBuilder builder) {
builder.enforceCommentTokens(TokenSet.EMPTY);
builder.putUserDataUnprotected(PsiBuilderImpl.CUSTOM_COMPARATOR, REPARSE_XML_TAG_BY_NAME);
builder.putUserData(PsiBuilderImpl.CUSTOM_COMPARATOR, REPARSE_XML_TAG_BY_NAME);
final PsiBuilder.Marker file = builder.mark();
new XmlParsing(builder).parseDocument();
file.done(root);