From d44433484b9bf51c360e1bc2fcf9c10270cfb7f3 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Wed, 23 May 2018 21:06:53 +0300 Subject: [PATCH] deprecate UserDataHolderUnprotected and update its usages --- .../lang/java/parser/JavaParserUtil.java | 8 ++++---- .../lang/java/parser/JavadocParser.java | 6 +++--- .../src/com/intellij/lang/PsiBuilder.java | 17 ++-------------- .../intellij/lang/impl/PsiBuilderAdapter.java | 18 +++-------------- .../lang/parser/GeneratedParserUtilBase.java | 18 ++--------------- .../util/UnprotectedUserDataHolder.java | 1 + .../util/UserDataHolderUnprotected.java | 20 +++++-------------- .../properties/parsing/PropertiesParser.java | 18 ++--------------- .../impl/source/parsing/xml/DtdParsing.java | 20 +++---------------- .../impl/source/parsing/xml/XmlParser.java | 18 ++--------------- 10 files changed, 27 insertions(+), 117 deletions(-) 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 54a517932a1e..fe769da6ac27 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 9cd3540180b0..8a2484ae2287 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.*; @@ -154,11 +140,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/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java b/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java index 54d86d2a9e8c..cb63ba157bef 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; @@ -943,7 +929,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 index 4316a610de2e..26e7c5c254c1 100644 --- a/platform/util/src/com/intellij/openapi/util/UnprotectedUserDataHolder.java +++ b/platform/util/src/com/intellij/openapi/util/UnprotectedUserDataHolder.java @@ -10,6 +10,7 @@ import java.util.Map; /** * Non thread safe version of {@link UserDataHolderBase}. */ +@SuppressWarnings("deprecation") public class UnprotectedUserDataHolder implements UserDataHolder, UserDataHolderUnprotected { private Map myUserData; 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);