Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
b5e67a74
Commit
b5e67a74
authored
7 years ago
by
Roman Shevchenko
Browse files
Options
Download
Email Patches
Plain Diff
[java] extracts utility method for producing module statements
parent
6637903b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddRequiredModuleFix.java
+2
-18
...odeInsight/daemon/impl/quickfix/AddRequiredModuleFix.java
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MergeModuleStatementsFix.java
+4
-22
...nsight/daemon/impl/quickfix/MergeModuleStatementsFix.java
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MergePackageAccessibilityStatementsFix.java
+5
-17
...impl/quickfix/MergePackageAccessibilityStatementsFix.java
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MergeProvidesStatementsFix.java
+2
-16
...ight/daemon/impl/quickfix/MergeProvidesStatementsFix.java
java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/Java9RedundantRequiresStatementInspection.java
+2
-19
...a19modules/Java9RedundantRequiresStatementInspection.java
java/java-psi-api/src/com/intellij/psi/PsiJavaParserFacade.java
+7
-15
...ava-psi-api/src/com/intellij/psi/PsiJavaParserFacade.java
java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java
+18
-16
...pl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java
with
40 additions
and
123 deletions
+40
-123
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddRequiredModuleFix.java
+
2
-
18
View file @
b5e67a74
/*
* Copyright 2000-2017 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-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.
package
com.intellij.codeInsight.daemon.impl.quickfix
;
import
com.intellij.codeInsight.daemon.QuickFixBundle
;
...
...
@@ -77,9 +63,7 @@ public class AddRequiredModuleFix extends LocalQuickFixAndIntentionActionOnPsiEl
return
false
;
}
PsiJavaParserFacade
parserFacade
=
JavaPsiFacade
.
getInstance
(
module
.
getProject
()).
getParserFacade
();
PsiJavaModule
tempModule
=
parserFacade
.
createModuleFromText
(
"module "
+
module
.
getName
()
+
" { requires "
+
requiredName
+
"; }"
);
Iterable
<
PsiRequiresStatement
>
tempModuleRequires
=
tempModule
.
getRequires
();
PsiRequiresStatement
requiresStatement
=
tempModuleRequires
.
iterator
().
next
();
PsiStatement
requiresStatement
=
parserFacade
.
createModuleStatementFromText
(
PsiKeyword
.
REQUIRES
+
' '
+
requiredName
);
PsiElement
addingPlace
=
findAddingPlace
(
module
);
if
(
addingPlace
!=
null
)
{
...
...
This diff is collapsed.
Click to expand it.
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MergeModuleStatementsFix.java
+
4
-
22
View file @
b5e67a74
/*
* Copyright 2000-2017 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-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.
package
com.intellij.codeInsight.daemon.impl.quickfix
;
import
com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement
;
...
...
@@ -33,7 +19,7 @@ import java.util.stream.Collectors;
/**
* @author Pavel.Dolgov
*/
public
abstract
class
MergeModuleStatementsFix
<
T
extends
Psi
El
ement
>
extends
LocalQuickFixAndIntentionActionOnPsiElement
{
public
abstract
class
MergeModuleStatementsFix
<
T
extends
Psi
Stat
ement
>
extends
LocalQuickFixAndIntentionActionOnPsiElement
{
protected
MergeModuleStatementsFix
(
@NotNull
PsiJavaModule
javaModule
)
{
super
(
javaModule
);
...
...
@@ -58,12 +44,8 @@ public abstract class MergeModuleStatementsFix<T extends PsiElement> extends Loc
final
List
<
T
>
statementsToMerge
=
getStatementsToMerge
(
javaModule
);
LOG
.
assertTrue
(!
statementsToMerge
.
isEmpty
());
final
String
tempModuleText
=
PsiKeyword
.
MODULE
+
" "
+
javaModule
.
getName
()
+
" {"
+
getReplacementText
(
statementsToMerge
)
+
"}"
;
final
PsiJavaModule
tempModule
=
JavaPsiFacade
.
getInstance
(
project
).
getElementFactory
().
createModuleFromText
(
tempModuleText
);
final
List
<
T
>
tempStatements
=
getStatementsToMerge
(
tempModule
);
LOG
.
assertTrue
(!
tempStatements
.
isEmpty
());
final
T
replacement
=
tempStatements
.
get
(
0
);
final
String
text
=
getReplacementText
(
statementsToMerge
);
final
PsiStatement
replacement
=
JavaPsiFacade
.
getInstance
(
project
).
getElementFactory
().
createModuleStatementFromText
(
text
);
final
T
firstStatement
=
statementsToMerge
.
get
(
0
);
final
CommentTracker
commentTracker
=
new
CommentTracker
();
...
...
This diff is collapsed.
Click to expand it.
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MergePackageAccessibilityStatementsFix.java
+
5
-
17
View file @
b5e67a74
/*
* Copyright 2000-2017 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-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.
package
com.intellij.codeInsight.daemon.impl.quickfix
;
import
com.intellij.codeInsight.daemon.QuickFixBundle
;
...
...
@@ -66,9 +52,11 @@ public class MergePackageAccessibilityStatementsFix
protected
String
getReplacementText
(
@NotNull
List
<
PsiPackageAccessibilityStatement
>
statementsToMerge
)
{
final
List
<
String
>
moduleNames
=
getModuleNames
(
statementsToMerge
);
if
(!
moduleNames
.
isEmpty
())
{
return
getKeyword
()
+
" "
+
myPackageName
+
" "
+
PsiKeyword
.
TO
+
" "
+
joinUniqueNames
(
moduleNames
)
+
";"
;
return
getKeyword
()
+
' '
+
myPackageName
+
' '
+
PsiKeyword
.
TO
+
' '
+
joinUniqueNames
(
moduleNames
);
}
else
{
return
getKeyword
()
+
' '
+
myPackageName
;
}
return
getKeyword
()
+
" "
+
myPackageName
+
";"
;
}
@NotNull
...
...
This diff is collapsed.
Click to expand it.
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MergeProvidesStatementsFix.java
+
2
-
16
View file @
b5e67a74
/*
* Copyright 2000-2017 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-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.
package
com.intellij.codeInsight.daemon.impl.quickfix
;
import
com.intellij.codeInsight.daemon.QuickFixBundle
;
...
...
@@ -54,7 +40,7 @@ public class MergeProvidesStatementsFix extends MergeModuleStatementsFix<PsiProv
protected
String
getReplacementText
(
@NotNull
List
<
PsiProvidesStatement
>
statementsToMerge
)
{
final
List
<
String
>
implementationNames
=
getImplementationNames
(
statementsToMerge
);
LOG
.
assertTrue
(!
implementationNames
.
isEmpty
());
return
PsiKeyword
.
PROVIDES
+
" "
+
myInterfaceName
+
" "
+
PsiKeyword
.
WITH
+
" "
+
joinUniqueNames
(
implementationNames
)
+
";"
;
return
PsiKeyword
.
PROVIDES
+
' '
+
myInterfaceName
+
' '
+
PsiKeyword
.
WITH
+
' '
+
joinUniqueNames
(
implementationNames
);
}
@NotNull
...
...
This diff is collapsed.
Click to expand it.
java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/Java9RedundantRequiresStatementInspection.java
+
2
-
19
View file @
b5e67a74
/*
* Copyright 2000-2017 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-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.
package
com.intellij.codeInspection.java19modules
;
import
com.intellij.analysis.AnalysisScope
;
...
...
@@ -203,10 +189,7 @@ public class Java9RedundantRequiresStatementInspection extends GlobalJavaBatchIn
if
(!
reexportedDependencies
.
isEmpty
())
{
PsiJavaParserFacade
parserFacade
=
JavaPsiFacade
.
getInstance
(
currentModule
.
getProject
()).
getParserFacade
();
for
(
String
dependencyName
:
reexportedDependencies
)
{
PsiJavaModule
tempModule
=
parserFacade
.
createModuleFromText
(
"module "
+
currentModule
.
getName
()
+
" { requires "
+
dependencyName
+
"; }"
);
Iterable
<
PsiRequiresStatement
>
tempModuleRequires
=
tempModule
.
getRequires
();
PsiRequiresStatement
requiresStatement
=
tempModuleRequires
.
iterator
().
next
();
PsiStatement
requiresStatement
=
parserFacade
.
createModuleStatementFromText
(
PsiKeyword
.
REQUIRES
+
' '
+
dependencyName
);
currentModule
.
addAfter
(
requiresStatement
,
addingPlace
);
}
}
...
...
This diff is collapsed.
Click to expand it.
java/java-psi-api/src/com/intellij/psi/PsiJavaParserFacade.java
+
7
-
15
View file @
b5e67a74
/*
* Copyright 2000-2017 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-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.
package
com.intellij.psi
;
import
com.intellij.pom.java.LanguageLevel
;
...
...
@@ -247,6 +233,12 @@ public interface PsiJavaParserFacade {
@NotNull
PsiJavaModule
createModuleFromText
(
@NotNull
String
text
);
/**
* Creates a Java module statement from the specified text.
*/
@NotNull
PsiStatement
createModuleStatementFromText
(
@NotNull
String
text
);
/** @deprecated use {@link PsiType#annotate(TypeAnnotationProvider)} (to be removed in IDEA 18) */
PsiType
createPrimitiveType
(
@NotNull
String
text
,
@NotNull
PsiAnnotation
[]
annotations
)
throws
IncorrectOperationException
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java
+
18
-
16
View file @
b5e67a74
/*
* Copyright 2000-2017 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-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.
package
com.intellij.psi.impl
;
import
com.intellij.ide.highlighter.JavaFileType
;
import
com.intellij.lang.PsiBuilder
;
import
com.intellij.lang.java.parser.*
;
import
com.intellij.lang.java.parser.DeclarationParser
;
import
com.intellij.lang.java.parser.JavaParser
;
import
com.intellij.lang.java.parser.JavaParserUtil
;
import
com.intellij.lang.java.parser.ReferenceParser
;
import
com.intellij.openapi.fileTypes.FileType
;
import
com.intellij.openapi.roots.LanguageLevelProjectExtension
;
import
com.intellij.openapi.util.text.StringUtil
;
...
...
@@ -31,6 +20,7 @@ import com.intellij.psi.impl.source.tree.FileElement;
import
com.intellij.psi.impl.source.tree.TreeElement
;
import
com.intellij.psi.javadoc.PsiDocComment
;
import
com.intellij.psi.javadoc.PsiDocTag
;
import
com.intellij.psi.util.PsiTreeUtil
;
import
com.intellij.psi.util.PsiUtil
;
import
com.intellij.util.IncorrectOperationException
;
import
com.intellij.util.containers.HashMap
;
...
...
@@ -404,6 +394,18 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade {
return
(
PsiJavaModule
)
element
;
}
@NotNull
@Override
public
PsiStatement
createModuleStatementFromText
(
@NotNull
String
text
)
{
String
template
=
"module M { "
+
text
+
"; }"
;
DummyHolder
holder
=
DummyHolderFactory
.
createHolder
(
myManager
,
new
JavaDummyElement
(
template
,
MODULE
,
LanguageLevel
.
JDK_1_9
),
null
);
PsiElement
element
=
SourceTreeToPsiMap
.
treeElementToPsi
(
holder
.
getTreeElement
().
getFirstChildNode
());
if
(!(
element
instanceof
PsiJavaModule
))
throw
new
IncorrectOperationException
(
"Incorrect module statement '"
+
text
+
"'"
);
PsiStatement
statement
=
PsiTreeUtil
.
getChildOfType
(
element
,
PsiStatement
.
class
);
if
(
statement
==
null
)
throw
new
IncorrectOperationException
(
"Incorrect module statement '"
+
text
+
"'"
);
return
statement
;
}
@NotNull
@Override
public
PsiType
createPrimitiveType
(
@NotNull
String
text
,
@NotNull
PsiAnnotation
[]
annotations
)
throws
IncorrectOperationException
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help