diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java index 14a0c1d4d8b4..091529cbfb4c 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java @@ -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 diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavadocParser.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavadocParser.java index a4623aa3df26..b4648b5e4322 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavadocParser.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavadocParser.java @@ -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) { diff --git a/platform/core-api/src/com/intellij/lang/PsiBuilder.java b/platform/core-api/src/com/intellij/lang/PsiBuilder.java index bfcfc79a55cf..7c87f242b364 100644 --- a/platform/core-api/src/com/intellij/lang/PsiBuilder.java +++ b/platform/core-api/src/com/intellij/lang/PsiBuilder.java @@ -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}). diff --git a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderAdapter.java b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderAdapter.java index 24a4c4d2465c..4f9b76b5db5f 100644 --- a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderAdapter.java +++ b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderAdapter.java @@ -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 getUserDataUnprotected(@NotNull final Key key) { return myDelegate.getUserDataUnprotected(key); } + @SuppressWarnings("deprecation") @Override public void putUserDataUnprotected(@NotNull final Key key, @Nullable final T value) { myDelegate.putUserDataUnprotected(key, value); diff --git a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java index 10bb211c697e..6f8047c9bf4d 100644 --- a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java +++ b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java @@ -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 myUserData; private IElementType myCachedTokenType; private final TIntObjectHashMap myChameleonCache = new TIntObjectHashMap<>(); @@ -991,7 +989,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { MyTreeStructure treeStructure = new MyTreeStructure(newRoot, null); final List customLanguageASTComparators = CustomLanguageASTComparator.getMatchingComparators(myFile); ShallowNodeComparator 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 getUserDataUnprotected(@NotNull final Key key) { + public T getUserData(@NotNull Key key) { if (key == FileContextUtil.CONTAINING_FILE_KEY) return (T)myFile; - return myUserData != null ? (T)myUserData.get(key) : null; + return super.getUserData(key); } @Override - public void putUserDataUnprotected(@NotNull final Key key, @Nullable final T value) { + public void putUserData(@NotNull Key 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); } } diff --git a/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java b/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java index 35a7fc1000d9..52e24485c0d9 100644 --- a/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java +++ b/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java @@ -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(); diff --git a/platform/util/src/com/intellij/openapi/util/UnprotectedUserDataHolder.java b/platform/util/src/com/intellij/openapi/util/UnprotectedUserDataHolder.java new file mode 100644 index 000000000000..26e7c5c254c1 --- /dev/null +++ b/platform/util/src/com/intellij/openapi/util/UnprotectedUserDataHolder.java @@ -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 myUserData; + + @SuppressWarnings("unchecked") + @Nullable + @Override + public T getUserData(@NotNull Key key) { + return myUserData != null ? (T)myUserData.get(key) : null; + } + + @Override + public void putUserData(@NotNull Key key, @Nullable T value) { + if (myUserData == null) myUserData = ContainerUtil.newHashMap(); + myUserData.put(key, value); + } + + @Nullable + @Override + public T getUserDataUnprotected(@NotNull Key key) { + return getUserData(key); + } + + @Override + public void putUserDataUnprotected(@NotNull Key key, @Nullable T value) { + putUserData(key, value); + } +} diff --git a/platform/util/src/com/intellij/openapi/util/UserDataHolderUnprotected.java b/platform/util/src/com/intellij/openapi/util/UserDataHolderUnprotected.java index 9108aa91939e..36252f88cc1c 100644 --- a/platform/util/src/com/intellij/openapi/util/UserDataHolderUnprotected.java +++ b/platform/util/src/com/intellij/openapi/util/UserDataHolderUnprotected.java @@ -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 getUserDataUnprotected(@NotNull Key key); + @Deprecated void putUserDataUnprotected(@NotNull Key key, @Nullable T value); } diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertiesParser.java b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertiesParser.java index 2929104b2d53..5d2657f3486b 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertiesParser.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertiesParser.java @@ -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()) { diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/DtdParsing.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/DtdParsing.java index b8c6b2affe38..2d147cee62f5 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/DtdParsing.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/DtdParsing.java @@ -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(); diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/XmlParser.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/XmlParser.java index c63700b6f80e..1f34ce54d3df 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/XmlParser.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/XmlParser.java @@ -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);