@Nullable

This commit is contained in:
Roman Shevchenko
2011-04-13 21:19:34 +02:00
parent 5eb3e4d488
commit 9a915100d3
2 changed files with 47 additions and 45 deletions
@@ -170,7 +170,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiAnnotation createAnnotationFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiAnnotation createAnnotationFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ANNOTATION, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiAnnotation)) {
@@ -187,7 +187,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiDocTag createDocTagFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiDocTag createDocTagFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
return createDocTagFromText(text);
}
@@ -202,13 +202,13 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiDocComment createDocCommentFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiDocComment createDocCommentFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
return createDocCommentFromText(text);
}
@NotNull
@Override
public PsiClass createClassFromText(@NotNull final String body, final PsiElement context) throws IncorrectOperationException {
public PsiClass createClassFromText(@NotNull final String body, @Nullable final PsiElement context) throws IncorrectOperationException {
final PsiJavaFile aFile = createDummyJavaFile(StringUtil.join("class _Dummy_ { ", body, " }"));
final PsiClass[] classes = aFile.getClasses();
if (classes.length != 1) {
@@ -219,7 +219,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiField createFieldFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiField createFieldFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiField)) {
@@ -230,7 +230,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiMethod createMethodFromText(@NotNull final String text, final PsiElement context, final LanguageLevel level) throws IncorrectOperationException {
public PsiMethod createMethodFromText(@NotNull final String text, @Nullable final PsiElement context, final LanguageLevel level) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiMethod)) {
@@ -241,14 +241,14 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public final PsiMethod createMethodFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public final PsiMethod createMethodFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final LanguageLevel level = LanguageLevelProjectExtension.getInstance(myManager.getProject()).getLanguageLevel();
return createMethodFromText(text, context, level);
}
@NotNull
@Override
public PsiParameter createParameterFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiParameter createParameterFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, PARAMETER, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiParameter)) {
@@ -259,7 +259,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiResourceVariable createResourceFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiResourceVariable createResourceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, RESOURCE, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiResourceVariable)) {
@@ -270,13 +270,13 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiType createTypeFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiType createTypeFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
return createTypeInner(text, context, false);
}
@NotNull
@Override
public PsiTypeElement createTypeElementFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiTypeElement createTypeElementFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiTypeElement)) {
@@ -285,7 +285,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
return (PsiTypeElement)element;
}
protected PsiType createTypeInner(final String text, final PsiElement context, final boolean markAsCopy) throws IncorrectOperationException {
protected PsiType createTypeInner(final String text, @Nullable final PsiElement context, final boolean markAsCopy) throws IncorrectOperationException {
final PsiPrimitiveType primitiveType = PRIMITIVE_TYPES.get(text);
if (primitiveType != null) return primitiveType;
@@ -298,7 +298,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final boolean isStaticImport = context instanceof PsiImportStaticStatement &&
!((PsiImportStaticStatement)context).isOnDemand();
final boolean mayHaveDiamonds = context instanceof PsiNewExpression &&
@@ -314,7 +314,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiCodeBlock createCodeBlockFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiCodeBlock createCodeBlockFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CODE_BLOCK, level(context), true), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiCodeBlock)) {
@@ -325,7 +325,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiStatement createStatementFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiStatement createStatementFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, STATEMENT, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiStatement)) {
@@ -336,7 +336,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiExpression createExpressionFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiExpression createExpressionFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, EXPRESSION, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiExpression)) {
@@ -353,7 +353,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiTypeParameter createTypeParameterFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiTypeParameter createTypeParameterFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE_PARAMETER, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiTypeParameter)) {
@@ -364,7 +364,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiComment createCommentFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiComment createCommentFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final PsiJavaFile aFile = createDummyJavaFile(text);
for (PsiElement aChildren : aFile.getChildren()) {
if (aChildren instanceof PsiComment) {
@@ -382,7 +382,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiEnumConstant createEnumConstantFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
public PsiEnumConstant createEnumConstantFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ENUM_CONSTANT, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiEnumConstant)) {
@@ -393,8 +393,9 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
@NotNull
@Override
public PsiCatchSection createCatchSection(@NotNull final PsiClassType exceptionType, @NotNull final String exceptionName,
final PsiElement context) throws IncorrectOperationException {
public PsiCatchSection createCatchSection(@NotNull final PsiClassType exceptionType,
@NotNull final String exceptionName,
@Nullable final PsiElement context) throws IncorrectOperationException {
final String text = StringUtil
.join("catch (", exceptionType.getCanonicalText(), " ", exceptionName, ") {}");
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CATCH_SECTION, level(context)), context);
@@ -406,7 +407,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
return (PsiCatchSection)myManager.getCodeStyleManager().reformat(element);
}
private void setupCatchBlock(final String exceptionName, final PsiElement context, final PsiCatchSection psiCatchSection)
private void setupCatchBlock(final String exceptionName, @Nullable final PsiElement context, final PsiCatchSection psiCatchSection)
throws IncorrectOperationException {
final FileTemplate catchBodyTemplate = FileTemplateManager.getInstance().getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
LOG.assertTrue(catchBodyTemplate != null);
@@ -433,6 +434,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
psiCatchSection.getCatchBlock().replace(codeBlockFromText);
}
@NotNull
@Override
public PsiType createPrimitiveType(@NotNull final String text, @NotNull final PsiAnnotation[] annotations) throws IncorrectOperationException {
final PsiPrimitiveType primitiveType = getPrimitiveType(text);
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi;
import com.intellij.pom.java.LanguageLevel;
@@ -22,8 +21,9 @@ import com.intellij.psi.javadoc.PsiDocTag;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/*
/**
* @author max
*/
public interface PsiJavaParserFacade extends PsiParserFacade {
@@ -41,7 +41,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @deprecated use {@link #createDocTagFromText(String)} (to remove in IDEA 11)
*/
@NotNull
PsiDocTag createDocTagFromText(@NotNull String docTagText, PsiElement context) throws IncorrectOperationException;
PsiDocTag createDocTagFromText(@NotNull String docTagText, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a JavaDoc comment from the specified text.
@@ -57,7 +57,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @deprecated use {@link #createDocCommentFromText(String)} (to remove in IDEA 11)
*/
@NotNull
PsiDocComment createDocCommentFromText(@NotNull String docCommentText, PsiElement context) throws IncorrectOperationException;
PsiDocComment createDocCommentFromText(@NotNull String docCommentText, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java class from the specified text.
@@ -69,7 +69,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text is not a valid class body.
*/
@NotNull
PsiClass createClassFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiClass createClassFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java field from the specified text.
@@ -80,7 +80,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text is not a valid field body.
*/
@NotNull
PsiField createFieldFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiField createFieldFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java method from the specified text with the specified language level.
@@ -92,7 +92,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text is not a valid method body.
*/
@NotNull
PsiMethod createMethodFromText(@NotNull @NonNls String text, PsiElement context, LanguageLevel languageLevel) throws IncorrectOperationException;
PsiMethod createMethodFromText(@NotNull @NonNls String text, @Nullable PsiElement context, LanguageLevel languageLevel) throws IncorrectOperationException;
/**
* Creates a Java method from the specified text.
@@ -103,7 +103,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text is not a valid method body.
*/
@NotNull
PsiMethod createMethodFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiMethod createMethodFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java parameter from the specified text.
@@ -114,7 +114,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text is not a valid parameter body.
*/
@NotNull
PsiParameter createParameterFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiParameter createParameterFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java try-resource from the specified text.
@@ -125,7 +125,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text is not a valid resource definition.
*/
@NotNull
PsiResourceVariable createResourceFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException;
PsiResourceVariable createResourceFromText(@NotNull String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java type from the specified text.
@@ -137,7 +137,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid type.
*/
@NotNull
PsiType createTypeFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiType createTypeFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java type element from the specified text.
@@ -149,7 +149,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid type.
*/
@NotNull
PsiTypeElement createTypeElementFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiTypeElement createTypeElementFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java code reference from the specified text.
@@ -161,7 +161,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid type.
*/
@NotNull
PsiJavaCodeReferenceElement createReferenceFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiJavaCodeReferenceElement createReferenceFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java code block from the specified text.
@@ -172,7 +172,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid code block.
*/
@NotNull
PsiCodeBlock createCodeBlockFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiCodeBlock createCodeBlockFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java statement from the specified text.
@@ -183,7 +183,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid statement.
*/
@NotNull
PsiStatement createStatementFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiStatement createStatementFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java expression from the specified text.
@@ -194,7 +194,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid expression.
*/
@NotNull
PsiExpression createExpressionFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiExpression createExpressionFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java comment from the specified text.
@@ -205,7 +205,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid comment.
*/
@NotNull
PsiComment createCommentFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException;
PsiComment createCommentFromText(@NotNull String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a type parameter from the specified text.
@@ -216,7 +216,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid type parameter.
*/
@NotNull
PsiTypeParameter createTypeParameterFromText(@NotNull @NonNls String text, PsiElement context) throws IncorrectOperationException;
PsiTypeParameter createTypeParameterFromText(@NotNull @NonNls String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates an annotation from the specified text.
@@ -227,11 +227,10 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid annotation.
*/
@NotNull
PsiAnnotation createAnnotationFromText(@NotNull @NonNls String annotationText, PsiElement context) throws IncorrectOperationException;
PsiAnnotation createAnnotationFromText(@NotNull @NonNls String annotationText, @Nullable PsiElement context) throws IncorrectOperationException;
@NotNull
PsiEnumConstant createEnumConstantFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException;
PsiEnumConstant createEnumConstantFromText(@NotNull String text, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a <code>catch</code> section for catching an exception of the specified
@@ -243,8 +242,8 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @return the created catch section instance.
* @throws IncorrectOperationException if some of the parameters are not valid.
*/
@NotNull PsiCatchSection createCatchSection(@NotNull PsiClassType exceptionType, @NotNull String exceptionName, PsiElement context)
throws IncorrectOperationException;
@NotNull
PsiCatchSection createCatchSection(@NotNull PsiClassType exceptionType, @NotNull String exceptionName, @Nullable PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java type from the specified text.
@@ -254,5 +253,6 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* @return the created type instance.
* @throws IncorrectOperationException if some of the parameters are not valid.
*/
@NotNull
PsiType createPrimitiveType(@NotNull String text, @NotNull PsiAnnotation[] annotations) throws IncorrectOperationException;
}