diff --git a/community-main.iml b/community-main.iml
index e984246e74c7..e3109b8263bf 100644
--- a/community-main.iml
+++ b/community-main.iml
@@ -77,6 +77,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
index dd503c74277e..5cbc5fea985e 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
@@ -1038,12 +1038,12 @@ public class CompileDriver {
generatedTypes.addAll(compilerManager.getRegisteredOutputTypes(compiler));
}
- if (_context.getMessageCount(CompilerMessageCategory.ERROR) > 0) {
- throw new ExitException(ExitStatus.ERRORS);
- }
-
didSomething |= compiledSomething;
compiledSomethingForThisChunk |= didSomething;
+
+ if (_context.getMessageCount(CompilerMessageCategory.ERROR) > 0) {
+ break; // break the loop over compilers
+ }
}
final boolean hasUnprocessedTraverseRoots = context.getDependencyCache().hasUnprocessedTraverseRoots();
diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java
index 5d12ced33651..efff8ab5787a 100644
--- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java
+++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java
@@ -351,7 +351,7 @@ public class DebugProcessEvents extends DebugProcessImpl {
//noinspection HardCodedStringLiteral
RequestHint hint = (RequestHint)event.request().getProperty("hint");
- deleteStepRequests();
+ deleteStepRequests(event.thread());
boolean shouldResume = false;
diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java
index 0e907ad96f1f..c88999862fdc 100644
--- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java
+++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java
@@ -353,12 +353,13 @@ public abstract class DebugProcessImpl implements DebugProcess {
return;
}
try {
+ final ThreadReference stepThreadReference = stepThread.getThreadReference();
if (LOG.isDebugEnabled()) {
- LOG.debug("DO_STEP: creating step request for " + stepThread.getThreadReference());
+ LOG.debug("DO_STEP: creating step request for " + stepThreadReference);
}
- deleteStepRequests();
+ deleteStepRequests(stepThreadReference);
EventRequestManager requestManager = getVirtualMachineProxy().eventRequestManager();
- StepRequest stepRequest = requestManager.createStepRequest(stepThread.getThreadReference(), StepRequest.STEP_LINE, depth);
+ StepRequest stepRequest = requestManager.createStepRequest(stepThreadReference, StepRequest.STEP_LINE, depth);
DebuggerSettings settings = DebuggerSettings.getInstance();
if (!(hint != null && hint.isIgnoreFilters()) /*&& depth == StepRequest.STEP_INTO*/) {
final List activeFilters = new ArrayList();
@@ -404,7 +405,7 @@ public abstract class DebugProcessImpl implements DebugProcess {
}
}
- void deleteStepRequests() {
+ void deleteStepRequests(@Nullable final ThreadReference stepThread) {
EventRequestManager requestManager = getVirtualMachineProxy().eventRequestManager();
List stepRequests = requestManager.stepRequests();
if (stepRequests.size() > 0) {
@@ -412,7 +413,7 @@ public abstract class DebugProcessImpl implements DebugProcess {
for (final StepRequest request : stepRequests) {
ThreadReference threadReference = request.thread();
// [jeka] on attempt to delete a request assigned to a thread with unknown status, a JDWP error occures
- if (threadReference.status() != ThreadReference.THREAD_STATUS_UNKNOWN) {
+ if (threadReference.status() != ThreadReference.THREAD_STATUS_UNKNOWN && (stepThread == null || stepThread.equals(threadReference))) {
toDelete.add(request);
}
}
diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java
index 07bed88ea199..110d70270f5d 100644
--- a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java
+++ b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerImpl.java
@@ -298,7 +298,8 @@ public class SuspendManagerImpl implements SuspendManager {
}
myDebugProcess.logThreads();
myDebugProcess.cancelRunToCursorBreakpoint();
- myDebugProcess.deleteStepRequests();
+ final ThreadReferenceProxyImpl thread = suspendContext.getThread();
+ myDebugProcess.deleteStepRequests(thread != null? thread.getThreadReference() : null);
notifyPaused(suspendContext);
}
}
diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java
index 472402354c00..9ea0bfe2ba0c 100644
--- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java
+++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java
@@ -127,59 +127,55 @@ public class LineBreakpoint extends BreakpointWithHighlighter {
if (!isInScopeOf(debugProcess, classType.name())) {
return;
}
- ApplicationManager.getApplication().runReadAction(new Runnable() {
- public void run() {
- try {
- List locs = debugProcess.getPositionManager().locationsOfLine(classType, getSourcePosition());
- if (locs.size() > 0) {
- for (final Location location : locs) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Found location for reference type " + classType.name() + " at line " + getLineIndex() + "; isObsolete: " + (debugProcess.getVirtualMachineProxy().versionHigher("1.4") && location.method().isObsolete()));
- }
- BreakpointRequest request = debugProcess.getRequestsManager().createBreakpointRequest(LineBreakpoint.this, location);
- debugProcess.getRequestsManager().enableRequest(request);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Created breakpoint request for reference type " + classType.name() + " at line " + getLineIndex());
- }
- }
- }
- else {
- // there's no executable code in this class
- debugProcess.getRequestsManager().setInvalid(LineBreakpoint.this, DebuggerBundle.message(
- "error.invalid.breakpoint.no.executable.code", (getLineIndex() + 1), classType.name())
- );
- if (LOG.isDebugEnabled()) {
- LOG.debug("No locations of type " + classType.name() + " found at line " + getLineIndex());
- }
- }
- }
- catch (ClassNotPreparedException ex) {
+ try {
+ List locs = debugProcess.getPositionManager().locationsOfLine(classType, getSourcePosition());
+ if (locs.size() > 0) {
+ for (final Location location : locs) {
if (LOG.isDebugEnabled()) {
- LOG.debug("ClassNotPreparedException: " + ex.getMessage());
+ LOG.debug("Found location for reference type " + classType.name() + " at line " + getLineIndex() + "; isObsolete: " + (debugProcess.getVirtualMachineProxy().versionHigher("1.4") && location.method().isObsolete()));
}
- // there's a chance to add a breakpoint when the class is prepared
- }
- catch (ObjectCollectedException ex) {
+ BreakpointRequest request = debugProcess.getRequestsManager().createBreakpointRequest(LineBreakpoint.this, location);
+ debugProcess.getRequestsManager().enableRequest(request);
if (LOG.isDebugEnabled()) {
- LOG.debug("ObjectCollectedException: " + ex.getMessage());
+ LOG.debug("Created breakpoint request for reference type " + classType.name() + " at line " + getLineIndex());
}
- // there's a chance to add a breakpoint when the class is prepared
}
- catch (InvalidLineNumberException ex) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("InvalidLineNumberException: " + ex.getMessage());
- }
- debugProcess.getRequestsManager().setInvalid(LineBreakpoint.this, DebuggerBundle.message("error.invalid.breakpoint.bad.line.number"));
- }
- catch (InternalException ex) {
- LOG.info(ex);
- }
- catch(Exception ex) {
- LOG.info(ex);
- }
- updateUI();
}
- });
+ else {
+ // there's no executable code in this class
+ debugProcess.getRequestsManager().setInvalid(LineBreakpoint.this, DebuggerBundle.message(
+ "error.invalid.breakpoint.no.executable.code", (getLineIndex() + 1), classType.name())
+ );
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("No locations of type " + classType.name() + " found at line " + getLineIndex());
+ }
+ }
+ }
+ catch (ClassNotPreparedException ex) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("ClassNotPreparedException: " + ex.getMessage());
+ }
+ // there's a chance to add a breakpoint when the class is prepared
+ }
+ catch (ObjectCollectedException ex) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("ObjectCollectedException: " + ex.getMessage());
+ }
+ // there's a chance to add a breakpoint when the class is prepared
+ }
+ catch (InvalidLineNumberException ex) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("InvalidLineNumberException: " + ex.getMessage());
+ }
+ debugProcess.getRequestsManager().setInvalid(LineBreakpoint.this, DebuggerBundle.message("error.invalid.breakpoint.bad.line.number"));
+ }
+ catch (InternalException ex) {
+ LOG.info(ex);
+ }
+ catch(Exception ex) {
+ LOG.info(ex);
+ }
+ updateUI();
}
private boolean isInScopeOf(DebugProcessImpl debugProcess, String className) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/AllClassesGetter.java b/java/java-impl/src/com/intellij/codeInsight/completion/AllClassesGetter.java
index 91d283bba58d..1f7c36f5a010 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/AllClassesGetter.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/AllClassesGetter.java
@@ -132,6 +132,7 @@ public class AllClassesGetter {
start--;
}
context.getDocument().replaceString(start + 1, context.getTailOffset(), qName);
+ LOG.assertTrue(context.getTailOffset() >= 0);
}
}
};
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java
index 1ad49a9ddbdf..1e4e1a6bb2fb 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.AutoPopupController;
import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.ExpectedTypesProvider;
import com.intellij.codeInsight.lookup.LookupElement;
+import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
@@ -94,7 +95,18 @@ class JavaClassNameInsertHandler implements InsertHandler= 0);
+ String docText = context.getDocument().getText();
DefaultInsertHandler.addImportForItem(context.getFile(), context.getStartOffset(), item);
+ if (context.getTailOffset() < 0) {
+ if (ApplicationManagerEx.getApplicationEx().isInternal()) {
+ LOG.error("Tail offset degraded: " + context.getStartOffset() + "; " + docText);
+ } else {
+ LOG.error("Tail offset degraded after insertion");
+ }
+ }
+
if (annotation) {
// Check if someone inserts annotation class that require @
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java
index 89a09e685c17..c1955ee5df1d 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java
@@ -923,14 +923,21 @@ public class JavaCompletionUtil {
public static void insertParentheses(final InsertionContext context, final LookupElement item, boolean overloadsMatter, boolean hasParams) {
final Editor editor = context.getEditor();
- final TailType tailType = getTailType(item, context);
+ final char completionChar = context.getCompletionChar();
final PsiFile file = context.getFile();
+ final TailType tailType = completionChar == '(' ? TailType.NONE : LookupItem.handleCompletionChar(context.getEditor(), item, completionChar);
+ final boolean hasTail = tailType != TailType.NONE && tailType != TailType.UNKNOWN;
+ final boolean smart = completionChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR;
+
+ final boolean addCompletionChar = context.shouldAddCompletionChar();
context.setAddCompletionChar(false);
-
final boolean needLeftParenth = isToInsertParenth(file.findElementAt(context.getStartOffset()));
- final boolean needRightParenth = tailType != TailType.SMART_COMPLETION && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET;
+ final boolean needRightParenth = !smart && (CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET || hasTail);
+ if (hasTail) {
+ hasParams = false;
+ }
if (needLeftParenth) {
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
@@ -947,42 +954,20 @@ public class JavaCompletionUtil {
AutoPopupController.getInstance(file.getProject()).autoPopupParameterInfo(editor, overloadsMatter ? null : (PsiElement)item.getObject());
}
- if (tailType == TailType.SEMICOLON) {
- if (!needRightParenth) {
- return;
- }
-
- PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
- if (psiElement().beforeLeaf(psiElement().withText(".")).accepts(file.findElementAt(context.getTailOffset() - 1))) {
- return;
+ if (smart || needLeftParenth && needRightParenth && addCompletionChar) {
+ TailType toInsert = tailType;
+ LookupItem lookupItem = item.as(LookupItem.class);
+ if (lookupItem == null || lookupItem.getAttribute(LookupItem.TAIL_TYPE_ATTR) != TailType.UNKNOWN) {
+ if (!hasTail && item.getObject() instanceof PsiMethod && ((PsiMethod)item.getObject()).getReturnType() == PsiType.VOID) {
+ PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
+ if (psiElement().beforeLeaf(psiElement().withText(".")).accepts(file.findElementAt(context.getTailOffset() - 1))) {
+ return;
+ }
+ toInsert = TailType.SEMICOLON;
+ }
}
+ toInsert.processTail(editor, context.getTailOffset());
}
-
- if (tailType == TailType.SMART_COMPLETION || needLeftParenth && needRightParenth) {
- tailType.processTail(editor, context.getTailOffset());
- }
- }
-
- @NotNull
- public static TailType getTailType(final LookupElement item, InsertionContext context) {
- final char completionChar = context.getCompletionChar();
- if (completionChar == '!') return item instanceof LookupItem ? ((LookupItem)item).getTailType() : TailType.NONE;
- if (completionChar == '(') {
- final Object o = item.getObject();
- if (o instanceof PsiMethod) {
- final PsiMethod psiMethod = (PsiMethod)o;
- return psiMethod.getParameterList().getParameters().length > 0 || psiMethod.getReturnType() != PsiType.VOID
- ? TailType.NONE : TailType.SEMICOLON;
- } else if (o instanceof PsiClass) { // it may be a constructor
- return TailType.NONE;
- }
- }
- if (completionChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) return TailType.SMART_COMPLETION;
- if (!context.shouldAddCompletionChar()) {
- return TailType.NONE;
- }
-
- return LookupItem.handleCompletionChar(context.getEditor(), item, completionChar);
}
public static boolean isToInsertParenth(PsiElement place){
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallElement.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallElement.java
index a6a754150700..00a0ac458506 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallElement.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallElement.java
@@ -17,7 +17,6 @@ package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.ExpectedTypesProvider;
-import com.intellij.codeInsight.TailType;
import com.intellij.codeInsight.completion.util.MethodParenthesesHandler;
import com.intellij.codeInsight.lookup.*;
import com.intellij.codeInsight.lookup.impl.JavaElementLookupRenderer;
@@ -57,8 +56,6 @@ public class JavaMethodCallElement extends LookupItem implements Type
LOG.error(method.getName());
}
myCanImportStatic = canImportStatic;
- PsiType type = method.getReturnType();
- setTailType(PsiType.VOID.equals(type) ? TailType.SEMICOLON : TailType.NONE);
}
public PsiType getType() {
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/RemoveSuppressWarningAction.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/RemoveSuppressWarningAction.java
index 972cc03e1441..dec89978d01f 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/RemoveSuppressWarningAction.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/RemoveSuppressWarningAction.java
@@ -138,7 +138,7 @@ public class RemoveSuppressWarningAction implements LocalQuickFix {
}
else if (newText != null) {
newText = "@" + SuppressionUtil.SUPPRESS_INSPECTIONS_TAG_NAME + " " + newText;
- PsiDocTag newTag = JavaPsiFacade.getInstance(tag.getProject()).getElementFactory().createDocTagFromText(newText, tag);
+ PsiDocTag newTag = JavaPsiFacade.getInstance(tag.getProject()).getElementFactory().createDocTagFromText(newText);
tag.replace(newTag);
}
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressAllForClassFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressAllForClassFix.java
index 421a8161fd30..e39e54fbf800 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressAllForClassFix.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressAllForClassFix.java
@@ -84,7 +84,7 @@ public class SuppressAllForClassFix extends SuppressFix {
PsiDocTag noInspectionTag = docComment.findTagByName(SuppressionUtil.SUPPRESS_INSPECTIONS_TAG_NAME);
if (noInspectionTag != null) {
String tagText = "@" + SuppressionUtil.SUPPRESS_INSPECTIONS_TAG_NAME + " " + SuppressionUtil.ALL;
- noInspectionTag.replace(JavaPsiFacade.getInstance(project).getElementFactory().createDocTagFromText(tagText, null));
+ noInspectionTag.replace(JavaPsiFacade.getInstance(project).getElementFactory().createDocTagFromText(tagText));
DaemonCodeAnalyzer.getInstance(project).restart();
return;
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressFix.java
index 99db61ace268..b3fd3fbe2676 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressFix.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressFix.java
@@ -109,7 +109,7 @@ public class SuppressFix extends SuppressIntentionAction {
PsiManager manager = PsiManager.getInstance(project);
if (docComment == null) {
String commentText = "/** @" + SuppressionUtil.SUPPRESS_INSPECTIONS_TAG_NAME + " " + getID(container) + "*/";
- docComment = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocCommentFromText(commentText, null);
+ docComment = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocCommentFromText(commentText);
PsiElement firstChild = container.getFirstChild();
container.addBefore(docComment, firstChild);
}
@@ -122,11 +122,11 @@ public class SuppressFix extends SuppressIntentionAction {
" " +
(valueElement != null ? valueElement.getText() + "," : "") +
getID(container);
- noInspectionTag.replace(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText, null));
+ noInspectionTag.replace(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText));
}
else {
String tagText = "@" + SuppressionUtil.SUPPRESS_INSPECTIONS_TAG_NAME + " " + getID(container);
- docComment.add(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText, null));
+ docComment.add(JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createDocTagFromText(tagText));
}
}
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/VariableAccessFromInnerClassFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/VariableAccessFromInnerClassFix.java
index 5b5355f5f048..56b34711ed8b 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/VariableAccessFromInnerClassFix.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/VariableAccessFromInnerClassFix.java
@@ -176,7 +176,7 @@ public class VariableAccessFromInnerClassFix implements IntentionAction {
variableDeclarationStatement = factory.createVariableDeclarationStatement(variable.getName(), newType, init);
}
else {
- PsiExpression init = factory.createExpressionFromText(" { " + initializer.getText() + " }", variable);
+ PsiExpression init = factory.createExpressionFromText("{ " + initializer.getText() + " }", variable);
variableDeclarationStatement = factory.createVariableDeclarationStatement(variable.getName(), newType, init);
}
PsiVariable newVariable = (PsiVariable)variableDeclarationStatement.getDeclaredElements()[0];
diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConvertToBasicLatinAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConvertToBasicLatinAction.java
index 98a5bcf697aa..e4b0467119e9 100644
--- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConvertToBasicLatinAction.java
+++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConvertToBasicLatinAction.java
@@ -177,7 +177,7 @@ public class ConvertToBasicLatinAction extends PsiElementBaseIntentionAction {
}
public PsiElement createReplacement(final PsiElement element, final String newText) {
- return JavaPsiFacade.getElementFactory(element.getProject()).createDocCommentFromText(newText, element.getParent());
+ return JavaPsiFacade.getElementFactory(element.getProject()).createDocCommentFromText(newText);
}
private static void loadEntities(final Project project) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitDeclarationAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitDeclarationAction.java
index 521756db08eb..da5558d9c490 100644
--- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitDeclarationAction.java
+++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitDeclarationAction.java
@@ -145,8 +145,18 @@ public class SplitDeclarationAction extends PsiElementBaseIntentionAction {
}
}
- block.getParent().addBefore(varDeclStatement, block);
+ final PsiElement parent = block.getParent();
decl.replace(statement);
+ if (!(parent instanceof PsiCodeBlock)) {
+ final PsiBlockStatement blockStatement =
+ (PsiBlockStatement)JavaPsiFacade.getElementFactory(project).createStatementFromText("{}", null);
+ final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
+ codeBlock.add(varDeclStatement);
+ codeBlock.add(block);
+ block.replace(blockStatement);
+ } else {
+ parent.addBefore(varDeclStatement, block);
+ }
} else {
block.addAfter(statement, decl);
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java
index 6f56bc39b7f0..5d3ff59a8e97 100644
--- a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java
+++ b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java
@@ -1343,9 +1343,8 @@ public class JavaDocInfoGenerator {
}
else {
try {
- final PsiDocTag tag = JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createDocCommentFromText("/** @exception " + paramName + " */",
- method.getContainingFile()).getTags()[0];
-
+ final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
+ final PsiDocTag tag = elementFactory.createDocTagFromText("@exception " + paramName);
collectedTags.addLast(new Pair>(tag, ourEmptyProvider));
}
catch (IncorrectOperationException e) {
diff --git a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java
index 73c1821c0a38..4eedb6c34abe 100644
--- a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java
+++ b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java
@@ -323,7 +323,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
if (owner != null) {
if (!CodeInsightUtil.preparePsiElementsForWrite(owner)) return;
final PsiDocComment docComment = owner.getDocComment();
- final PsiDocTag tag = factory.createDocTagFromText("@" + myTag+" "+myValue, docComment);
+ final PsiDocTag tag = factory.createDocTagFromText("@" + myTag + " " + myValue);
if (docComment != null) {
PsiElement addedTag;
final PsiElement anchor = getAnchor();
diff --git a/java/java-impl/src/com/intellij/lang/java/parser/DeclarationParser.java b/java/java-impl/src/com/intellij/lang/java/parser/DeclarationParser.java
index d1d91be0ee21..2c01a1babfe2 100644
--- a/java/java-impl/src/com/intellij/lang/java/parser/DeclarationParser.java
+++ b/java/java-impl/src/com/intellij/lang/java/parser/DeclarationParser.java
@@ -146,7 +146,7 @@ public class DeclarationParser {
}
@Nullable
- private static PsiBuilder.Marker parseEnumConstant(final PsiBuilder builder) {
+ public static PsiBuilder.Marker parseEnumConstant(final PsiBuilder builder) {
final PsiBuilder.Marker constant = builder.mark();
parseModifierList(builder);
diff --git a/java/java-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java b/java/java-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java
index 99982aed1d3d..9313500b6149 100644
--- a/java/java-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java
+++ b/java/java-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java
@@ -184,13 +184,18 @@ public class JavaParserUtil {
return builder;
}
+ @Nullable
public static ASTNode parseFragment(final ASTNode chameleon, final ParserWrapper wrapper) {
+ return parseFragment(chameleon, wrapper, true, LanguageLevel.HIGHEST);
+ }
+
+ @Nullable
+ public static ASTNode parseFragment(final ASTNode chameleon, final ParserWrapper wrapper, final boolean eatAll, final LanguageLevel level) {
final PsiElement psi = (chameleon.getTreeParent() != null ? chameleon.getTreeParent().getPsi() : chameleon.getPsi());
assert psi != null : chameleon;
final Project project = psi.getProject();
final PsiBuilderFactory factory = PsiBuilderFactory.getInstance();
- final LanguageLevel level = LanguageLevel.HIGHEST;
final Lexer lexer = JavaParserDefinition.createLexer(level);
final PsiBuilder builder = factory.createBuilder(project, chameleon, lexer, chameleon.getElementType().getLanguage(), chameleon.getChars());
setLanguageLevel(builder, level);
@@ -198,6 +203,7 @@ public class JavaParserUtil {
final PsiBuilder.Marker root = builder.mark();
wrapper.parse(builder);
if (!builder.eof()) {
+ if (!eatAll) throw new AssertionError("Unexpected tokens");
final PsiBuilder.Marker extras = builder.mark();
while (!builder.eof()) builder.advanceLexer();
extras.error(JavaErrorMessages.message("unexpected.tokens"));
@@ -389,4 +395,4 @@ public class JavaParserUtil {
myDelegate.putUserDataUnprotected(key, value);
}
}
-}
+}
\ No newline at end of file
diff --git a/java/java-impl/src/com/intellij/lang/java/parser/ReferenceParser.java b/java/java-impl/src/com/intellij/lang/java/parser/ReferenceParser.java
index e6cfac8b80a2..1d25b4b7841f 100644
--- a/java/java-impl/src/com/intellij/lang/java/parser/ReferenceParser.java
+++ b/java/java-impl/src/com/intellij/lang/java/parser/ReferenceParser.java
@@ -311,7 +311,7 @@ public class ReferenceParser {
}
@Nullable
- private static PsiBuilder.Marker parseTypeParameter(final PsiBuilder builder) {
+ public static PsiBuilder.Marker parseTypeParameter(final PsiBuilder builder) {
final PsiBuilder.Marker param = builder.mark();
DeclarationParser.parseAnnotations(builder);
diff --git a/java/java-impl/src/com/intellij/lang/java/parser/StatementParser.java b/java/java-impl/src/com/intellij/lang/java/parser/StatementParser.java
index 561e249289cb..42c861dc6cfa 100644
--- a/java/java-impl/src/com/intellij/lang/java/parser/StatementParser.java
+++ b/java/java-impl/src/com/intellij/lang/java/parser/StatementParser.java
@@ -165,7 +165,7 @@ public class StatementParser {
}
@Nullable
- private static PsiBuilder.Marker parseStatement(final PsiBuilder builder) {
+ public static PsiBuilder.Marker parseStatement(final PsiBuilder builder) {
final IElementType tokenType = builder.getTokenType();
// todo: custom parsers (?)
@@ -637,7 +637,8 @@ public class StatementParser {
return statement;
}
- private static boolean parseCatchBlock(final PsiBuilder builder) {
+ public static boolean parseCatchBlock(final PsiBuilder builder) {
+ assert builder.getTokenType() == JavaTokenType.CATCH_KEYWORD : builder.getTokenType();
final PsiBuilder.Marker section = builder.mark();
builder.advanceLexer();
diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java
index 4a4c8a7620ba..e048f84772b8 100644
--- a/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java
+++ b/java/java-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java
@@ -17,7 +17,6 @@ package com.intellij.psi.impl;
import com.intellij.lang.*;
import com.intellij.lexer.Lexer;
-import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
@@ -27,12 +26,15 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.impl.light.*;
import com.intellij.psi.impl.source.*;
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
-import com.intellij.psi.impl.source.tree.*;
+import com.intellij.psi.impl.source.tree.FileElement;
+import com.intellij.psi.impl.source.tree.JavaElementType;
+import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.psi.javadoc.PsiDocTag;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.StringBuilderSpinAllocator;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -41,30 +43,14 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.Map;
+import static com.intellij.openapi.util.text.StringUtil.join;
+
public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements PsiElementFactory {
- private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.PsiElementFactoryImpl");
+ private PsiClass myArrayClass;
+ private PsiClass myArrayClass15;
+ private PsiJavaFile myDummyJavaFile;
- private PsiClass ARRAY_CLASS;
- private PsiClass ARRAY_CLASS15;
-
- static {
- initPrimitiveTypes();
- }
-
- private static void initPrimitiveTypes() {
- ourPrimitiveTypesMap.put(PsiType.BYTE.getCanonicalText(), (PsiPrimitiveType)PsiType.BYTE);
- ourPrimitiveTypesMap.put(PsiType.CHAR.getCanonicalText(), (PsiPrimitiveType)PsiType.CHAR);
- ourPrimitiveTypesMap.put(PsiType.DOUBLE.getCanonicalText(), (PsiPrimitiveType)PsiType.DOUBLE);
- ourPrimitiveTypesMap.put(PsiType.FLOAT.getCanonicalText(), (PsiPrimitiveType)PsiType.FLOAT);
- ourPrimitiveTypesMap.put(PsiType.INT.getCanonicalText(), (PsiPrimitiveType)PsiType.INT);
- ourPrimitiveTypesMap.put(PsiType.LONG.getCanonicalText(), (PsiPrimitiveType)PsiType.LONG);
- ourPrimitiveTypesMap.put(PsiType.SHORT.getCanonicalText(), (PsiPrimitiveType)PsiType.SHORT);
- ourPrimitiveTypesMap.put(PsiType.BOOLEAN.getCanonicalText(), (PsiPrimitiveType)PsiType.BOOLEAN);
- ourPrimitiveTypesMap.put(PsiType.VOID.getCanonicalText(), (PsiPrimitiveType)PsiType.VOID);
- ourPrimitiveTypesMap.put(PsiType.NULL.getCanonicalText(), (PsiPrimitiveType)PsiType.NULL);
- }
-
- public PsiElementFactoryImpl(PsiManagerEx manager) {
+ public PsiElementFactoryImpl(final PsiManagerEx manager) {
super(manager);
}
@@ -77,32 +63,29 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiClass getArrayClass(@NotNull LanguageLevel languageLevel) {
- try {
- if (languageLevel.compareTo(LanguageLevel.JDK_1_5) < 0) {
- if (ARRAY_CLASS == null) {
- ARRAY_CLASS = createClassFromText("public class __Array__{\n public final int length; \n public Object clone(){}\n}", null).getInnerClasses()[0];
- }
- return ARRAY_CLASS;
- }
- else {
- if (ARRAY_CLASS15 == null) {
- ARRAY_CLASS15 = createClassFromText("public class __Array__{\n public final int length; \n public T[] clone(){}\n}", null).getInnerClasses()[0];
- }
- return ARRAY_CLASS15;
+ public PsiClass getArrayClass(@NotNull final LanguageLevel languageLevel) {
+ if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_5)) {
+ if (myArrayClass == null) {
+ final String body = "public class __Array__{\n public final int length;\n public Object clone() {}\n}";
+ myArrayClass = createClassFromText(body, null).getInnerClasses()[0];
}
+ return myArrayClass;
}
- catch (IncorrectOperationException e) {
- LOG.error(e);
- return null;
+ else {
+ if (myArrayClass15 == null) {
+ final String body = "public class __Array__{\n public final int length;\n public T[] clone() {}\n}";
+ myArrayClass15 = createClassFromText(body, null).getInnerClasses()[0];
+ }
+ return myArrayClass15;
}
}
@NotNull
- public PsiClassType getArrayClassType(@NotNull PsiType componentType, @NotNull final LanguageLevel languageLevel) {
- PsiClass arrayClass = getArrayClass(languageLevel);
+ public PsiClassType getArrayClassType(@NotNull final PsiType componentType, @NotNull final LanguageLevel languageLevel) {
+ final PsiClass arrayClass = getArrayClass(languageLevel);
+ final PsiTypeParameter[] typeParameters = arrayClass.getTypeParameters();
+
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
- PsiTypeParameter[] typeParameters = arrayClass.getTypeParameters();
if (typeParameters.length == 1) {
substitutor = substitutor.put(typeParameters[0], componentType);
}
@@ -111,305 +94,227 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor) {
+ public PsiClassType createType(@NotNull final PsiClass resolve, @NotNull final PsiSubstitutor substitutor) {
return new PsiImmediateClassType(resolve, substitutor);
}
@NotNull
- public PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor, @NotNull LanguageLevel languageLevel) {
+ public PsiClassType createType(@NotNull final PsiClass resolve,
+ @NotNull final PsiSubstitutor substitutor,
+ @NotNull final LanguageLevel languageLevel) {
return new PsiImmediateClassType(resolve, substitutor, languageLevel);
}
@NotNull
- public PsiClassType createType(@NotNull PsiClass resolve,
- @NotNull PsiSubstitutor substitutor,
- @NotNull LanguageLevel languageLevel,
- @NotNull PsiAnnotation[] annotations) {
+ public PsiClassType createType(@NotNull final PsiClass resolve,
+ @NotNull final PsiSubstitutor substitutor,
+ @NotNull final LanguageLevel languageLevel,
+ @NotNull final PsiAnnotation[] annotations) {
return new PsiImmediateClassType(resolve, substitutor, languageLevel, annotations);
}
@NotNull
- public PsiClass createClass(@NotNull String name) throws IncorrectOperationException {
- PsiUtil.checkIsIdentifier(myManager, name);
- @NonNls String text = "public class " + name + "{ }";
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiClass[] classes = aFile.getClasses();
- if (classes.length != 1) {
- throw new IncorrectOperationException();
- }
- return classes[0];
+ public PsiClass createClass(@NotNull final String name) throws IncorrectOperationException {
+ return createClassInner("class", name);
}
@NotNull
- public PsiClass createInterface(@NotNull String name) throws IncorrectOperationException {
- PsiUtil.checkIsIdentifier(myManager, name);
- @NonNls String text = "public interface " + name + "{ }";
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiClass[] classes = aFile.getClasses();
- if (classes.length != 1) {
- throw new IncorrectOperationException();
- }
- return classes[0];
+ public PsiClass createInterface(@NotNull final String name) throws IncorrectOperationException {
+ return createClassInner("interface", name);
}
+ @NotNull
public PsiClass createEnum(@NotNull final String name) throws IncorrectOperationException {
+ return createClassInner("enum", name);
+ }
+
+ private PsiClass createClassInner(final String type, final String name) {
PsiUtil.checkIsIdentifier(myManager, name);
- @NonNls String text = "public enum " + name + "{ }";
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiClass[] classes = aFile.getClasses();
+ final PsiJavaFile aFile = createDummyJavaFile(join("public ", type, " ", name, " { }"));
+ final PsiClass[] classes = aFile.getClasses();
if (classes.length != 1) {
- throw new IncorrectOperationException();
+ throw new IncorrectOperationException("Incorrect " + type + " name \"" + name + "\".");
}
return classes[0];
}
@NotNull
- public PsiTypeElement createTypeElement(@NotNull PsiType psiType) {
+ public PsiTypeElement createTypeElement(@NotNull final PsiType psiType) {
final LightTypeElement element = new LightTypeElement(myManager, psiType);
CodeEditUtil.setNodeGenerated(element.getNode(), true);
return element;
}
@NotNull
- public PsiJavaCodeReferenceElement createReferenceElementByType(@NotNull PsiClassType type) {
+ public PsiJavaCodeReferenceElement createReferenceElementByType(@NotNull final PsiClassType type) {
if (type instanceof PsiClassReferenceType) {
return ((PsiClassReferenceType)type).getReference();
}
final PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
- return new LightClassReference(myManager, type.getPresentableText(), resolveResult.getElement(), resolveResult.getSubstitutor());
+ final PsiClass refClass = resolveResult.getElement();
+ assert refClass != null : type;
+ return new LightClassReference(myManager, type.getPresentableText(), refClass, resolveResult.getSubstitutor());
}
@NotNull
- public PsiField createField(@NotNull String name, @NotNull PsiType type) throws IncorrectOperationException {
+ public PsiField createField(@NotNull final String name, @NotNull final PsiType type) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(myManager, name);
if (PsiType.NULL.equals(type)) {
- throw new IncorrectOperationException("Cannot create field with type \"\".");
+ throw new IncorrectOperationException("Cannot create field with type \"null\".");
}
- TreeElement typeCopy = ChangeUtil.copyToElement(createTypeElement(type));
- typeCopy.acceptTree(new GeneratedMarkerVisitor());
- @NonNls String text = "class _Dummy_ {private int " + name + ";}";
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiClass aClass = aFile.getClasses()[0];
- PsiField field = aClass.getFields()[0];
- SourceTreeToPsiMap.psiElementToTree(field).replaceChild(SourceTreeToPsiMap.psiElementToTree(field.getTypeElement()), typeCopy);
- ChangeUtil.decodeInformation((TreeElement)SourceTreeToPsiMap.psiElementToTree(field));
+
+ final PsiJavaFile aFile = createDummyJavaFile(join("class _Dummy_ { private ", type.getCanonicalText(), " ", name, "; }"));
+ final PsiField field = aFile.getClasses()[0].getFields()[0];
+ JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(field);
return (PsiField)CodeStyleManager.getInstance(myManager.getProject()).reformat(field);
}
@NotNull
- public PsiMethod createMethod(@NotNull String name, PsiType returnType) throws IncorrectOperationException {
+ public PsiMethod createMethod(@NotNull final String name, final PsiType returnType) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(myManager, name);
if (PsiType.NULL.equals(returnType)) {
- throw new IncorrectOperationException("Cannot create field with type \"\".");
+ throw new IncorrectOperationException("Cannot create method with type \"null\".");
}
- @NonNls String text = "class _Dummy_ {\n public " + returnType.getCanonicalText() + " " + name + "(){}\n}";
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiClass aClass = aFile.getClasses()[0];
- PsiMethod method = aClass.getMethods()[0];
+
+ final PsiJavaFile aFile = createDummyJavaFile(join("class _Dummy_ { public " + returnType.getCanonicalText(), " ", name, "() {} }"));
+ final PsiMethod method = aFile.getClasses()[0].getMethods()[0];
JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(method);
return (PsiMethod)CodeStyleManager.getInstance(myManager.getProject()).reformat(method);
}
@NotNull
public PsiMethod createConstructor() {
- try {
- @NonNls String text = "class _Dummy_ {\n public _Dummy_(){}\n}";
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiClass aClass = aFile.getClasses()[0];
- PsiMethod method = aClass.getMethods()[0];
- return (PsiMethod)CodeStyleManager.getInstance(myManager.getProject()).reformat(method);
- }
- catch (IncorrectOperationException e) {
- LOG.assertTrue(false);
- return null;
- }
+ final PsiJavaFile aFile = createDummyJavaFile("class _Dummy_ { public _Dummy_() {} }");
+ final PsiMethod method = aFile.getClasses()[0].getMethods()[0];
+ return (PsiMethod)CodeStyleManager.getInstance(myManager.getProject()).reformat(method);
}
@NotNull
public PsiClassInitializer createClassInitializer() throws IncorrectOperationException {
- @NonNls String text = "class _Dummy_ { {} }";
- final PsiJavaFile aFile = createDummyJavaFile(text);
- final PsiClass aClass = aFile.getClasses()[0];
- final PsiClassInitializer psiClassInitializer = aClass.getInitializers()[0];
- return (PsiClassInitializer)CodeStyleManager.getInstance(myManager.getProject()).reformat(psiClassInitializer);
+ final PsiJavaFile aFile = createDummyJavaFile("class _Dummy_ { {} }");
+ final PsiClassInitializer classInitializer = aFile.getClasses()[0].getInitializers()[0];
+ return (PsiClassInitializer)CodeStyleManager.getInstance(myManager.getProject()).reformat(classInitializer);
}
@NotNull
- public PsiParameter createParameter(@NotNull String name, @NotNull PsiType type) throws IncorrectOperationException {
+ public PsiParameter createParameter(@NotNull final String name, @NotNull final PsiType type) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(myManager, name);
if (PsiType.NULL.equals(type)) {
- throw new IncorrectOperationException("Cannot create field with type \"\".");
+ throw new IncorrectOperationException("Cannot create parameter with type \"null\".");
}
- final FileElement treeHolder = DummyHolderFactory.createHolder(myManager, null).getTreeElement();
- final String text = type.getCanonicalText() + " " + name;
- final CompositeElement treeElement = getJavaParsingContext(treeHolder).getDeclarationParsing().parseParameterText(text);
- if (treeElement == null) {
- throw new AssertionError("Null element for text = " + text);
- }
- treeHolder.rawAddChildren(treeElement);
- CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myManager.getProject());
- PsiParameter parameter = (PsiParameter)SourceTreeToPsiMap.treeElementToPsi(treeElement);
- PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_PARAMETERS);
- treeElement.acceptTree(new GeneratedMarkerVisitor());
+ final String text = join(type.getCanonicalText() + " " + name);
+ final PsiParameter parameter = createParameterFromText(text, null);
+ final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myManager.getProject());
+ PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL,
+ CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_PARAMETERS);
+ markGenerated(parameter);
JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(parameter);
return (PsiParameter)codeStyleManager.reformat(parameter);
}
@NotNull
public PsiCodeBlock createCodeBlock() {
- try {
- PsiCodeBlock block = createCodeBlockFromText("{}", null);
- return (PsiCodeBlock)CodeStyleManager.getInstance(myManager.getProject()).reformat(block);
- }
- catch (IncorrectOperationException e) {
- LOG.error(e);
- return null;
- }
+ final PsiCodeBlock block = createCodeBlockFromText("{}", null);
+ return (PsiCodeBlock)CodeStyleManager.getInstance(myManager.getProject()).reformat(block);
}
@NotNull
- public PsiClassType createType(@NotNull PsiClass aClass) {
+ public PsiClassType createType(@NotNull final PsiClass aClass) {
return new PsiImmediateClassType(aClass, aClass instanceof PsiTypeParameter ? PsiSubstitutor.EMPTY : createRawSubstitutor(aClass));
}
@NotNull
- public PsiClassType createType(@NotNull PsiJavaCodeReferenceElement classReference) {
+ public PsiClassType createType(@NotNull final PsiJavaCodeReferenceElement classReference) {
return new PsiClassReferenceType(classReference, null);
}
@NotNull
- public PsiClassType createType(@NotNull PsiClass aClass, PsiType parameter) {
- PsiTypeParameter[] typeParameters = aClass.getTypeParameters();
- assert typeParameters.length == 1;
-
- Map map = Collections.singletonMap(typeParameters[0], parameter);
+ public PsiClassType createType(@NotNull final PsiClass aClass, final PsiType parameter) {
+ final PsiTypeParameter[] typeParameters = aClass.getTypeParameters();
+ assert typeParameters.length == 1 : aClass;
+ final Map map = Collections.singletonMap(typeParameters[0], parameter);
return createType(aClass, createSubstitutor(map));
}
@NotNull
- public PsiClassType createType(@NotNull PsiClass aClass, PsiType... parameters) {
- PsiTypeParameter[] typeParameters = aClass.getTypeParameters();
+ public PsiClassType createType(@NotNull final PsiClass aClass, final PsiType... parameters) {
+ final PsiTypeParameter[] typeParameters = aClass.getTypeParameters();
assert parameters.length == typeParameters.length;
- Map map = new java.util.HashMap();
+ final Map map = new java.util.HashMap();
for (int i = 0; i < parameters.length; i++) {
map.put(typeParameters[i], parameters[i]);
}
-
return createType(aClass, createSubstitutor(map));
}
- private static class TypeDetacher extends PsiTypeVisitor {
- public static final TypeDetacher INSTANCE = new TypeDetacher();
-
- public PsiType visitType(PsiType type) {
- return type;
- }
-
- public PsiType visitWildcardType(PsiWildcardType wildcardType) {
- final PsiType bound = wildcardType.getBound();
- if (bound == null) {
- return wildcardType;
- }
- else {
- return PsiWildcardType.changeBound(wildcardType, bound.accept(this));
- }
- }
-
- public PsiType visitArrayType(PsiArrayType arrayType) {
- final PsiType componentType = arrayType.getComponentType();
- final PsiType detachedComponentType = componentType.accept(this);
- if (detachedComponentType == componentType) return arrayType; // optimization
- return detachedComponentType.createArrayType();
- }
-
- public PsiType visitClassType(PsiClassType classType) {
- final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
- final PsiClass aClass = resolveResult.getElement();
- if (aClass == null) return classType;
- final HashMap map = new HashMap();
- for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable(aClass)) {
- PsiType type = resolveResult.getSubstitutor().substitute(parameter);
- if (type != null) {
- type = type.accept(this);
- }
- map.put(parameter, type);
- }
- return new PsiImmediateClassType(aClass, PsiSubstitutorImpl.createSubstitutor(map));
- }
- }
-
-
@NotNull
- public PsiType detachType(@NotNull PsiType type) {
- return type.accept(TypeDetacher.INSTANCE);
+ public PsiType detachType(@NotNull final PsiType type) {
+ return type;
}
@NotNull
- public PsiSubstitutor createRawSubstitutor(@NotNull PsiTypeParameterListOwner owner) {
- Map substMap = null;
+ public PsiSubstitutor createRawSubstitutor(@NotNull final PsiTypeParameterListOwner owner) {
+ Map substitutorMap = null;
for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable(owner)) {
- if (substMap == null) substMap = new HashMap();
- substMap.put(parameter, null);
+ if (substitutorMap == null) substitutorMap = new HashMap();
+ substitutorMap.put(parameter, null);
}
- return PsiSubstitutorImpl.createSubstitutor(substMap);
- }
- @NotNull
- public PsiSubstitutor createRawSubstitutor(@NotNull PsiSubstitutor baseSubstitutor, @NotNull PsiTypeParameter[] typeParameters) {
- Map substMap = null;
- for (PsiTypeParameter parameter : typeParameters) {
- if (substMap == null) substMap = new HashMap();
- substMap.put(parameter, null);
- }
- return baseSubstitutor.putAll(PsiSubstitutorImpl.createSubstitutor(substMap));
+ return PsiSubstitutorImpl.createSubstitutor(substitutorMap);
}
@NotNull
- public PsiElement createDummyHolder(@NotNull String text, @NotNull IElementType type, @Nullable PsiElement context) {
+ public PsiSubstitutor createRawSubstitutor(@NotNull final PsiSubstitutor baseSubstitutor, @NotNull final PsiTypeParameter[] typeParameters) {
+ Map substitutorMap = null;
+ for (PsiTypeParameter parameter : typeParameters) {
+ if (substitutorMap == null) substitutorMap = new HashMap();
+ substitutorMap.put(parameter, null);
+ }
+ return baseSubstitutor.putAll(PsiSubstitutorImpl.createSubstitutor(substitutorMap));
+ }
+
+ @NotNull
+ public PsiElement createDummyHolder(@NotNull final String text, @NotNull final IElementType type, @Nullable final PsiElement context) {
final DummyHolder result = DummyHolderFactory.createHolder(myManager, context);
final FileElement holder = result.getTreeElement();
final Language language = type.getLanguage();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
- if (parserDefinition == null) {
- throw new AssertionError("No parser definition for language " + language);
- }
+ assert parserDefinition != null : "No parser definition for language " + language;
final Project project = myManager.getProject();
final Lexer lexer = parserDefinition.createLexer(project);
final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, holder, lexer, language, text);
final ASTNode node = parserDefinition.createParser(project).parse(type, builder);
holder.rawAddChildren((TreeElement)node);
- return node.getPsi();
+ final PsiElement psi = node.getPsi();
+ assert psi != null : text;
+ return psi;
}
@NotNull
- public PsiSubstitutor createSubstitutor(@NotNull Map map) {
+ public PsiSubstitutor createSubstitutor(@NotNull final Map map) {
return PsiSubstitutorImpl.createSubstitutor(map);
}
@Nullable
- public PsiPrimitiveType createPrimitiveType(@NotNull String text) {
- return getPrimitiveType(text);
- }
-
- public static PsiPrimitiveType getPrimitiveType(final String text) {
- return ourPrimitiveTypesMap.get(text);
+ public PsiPrimitiveType createPrimitiveType(@NotNull final String text) {
+ return PsiJavaParserFacadeImpl.getPrimitiveType(text);
}
@NotNull
- public PsiClassType createTypeByFQClassName(@NotNull String qName) {
+ public PsiClassType createTypeByFQClassName(@NotNull final String qName) {
return createTypeByFQClassName(qName, GlobalSearchScope.allScope(myManager.getProject()));
}
@NotNull
- public PsiClassType createTypeByFQClassName(@NotNull String qName, @NotNull GlobalSearchScope resolveScope) {
+ public PsiClassType createTypeByFQClassName(@NotNull final String qName, @NotNull final GlobalSearchScope resolveScope) {
return new PsiClassReferenceType(createReferenceElementByFQClassName(qName, resolveScope), null);
}
@NotNull
- public PsiJavaCodeReferenceElement createClassReferenceElement(@NotNull PsiClass aClass) {
+ public PsiJavaCodeReferenceElement createClassReferenceElement(@NotNull final PsiClass aClass) {
final String text;
if (aClass instanceof PsiAnonymousClass) {
text = ((PsiAnonymousClass)aClass).getBaseClassType().getPresentableText();
@@ -421,19 +326,20 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiJavaCodeReferenceElement createReferenceElementByFQClassName(@NotNull String qName, @NotNull GlobalSearchScope resolveScope) {
- String shortName = PsiNameHelper.getShortClassName(qName);
+ public PsiJavaCodeReferenceElement createReferenceElementByFQClassName(@NotNull final String qName,
+ @NotNull final GlobalSearchScope resolveScope) {
+ final String shortName = PsiNameHelper.getShortClassName(qName);
return new LightClassReference(myManager, shortName, qName, resolveScope);
}
@NotNull
- public PsiJavaCodeReferenceElement createFQClassNameReferenceElement(@NotNull String qName, @NotNull GlobalSearchScope resolveScope) {
+ public PsiJavaCodeReferenceElement createFQClassNameReferenceElement(@NotNull final String qName,
+ @NotNull final GlobalSearchScope resolveScope) {
return new LightClassReference(myManager, qName, qName, resolveScope);
}
@NotNull
- public PsiJavaCodeReferenceElement createPackageReferenceElement(@NotNull PsiPackage aPackage)
- throws IncorrectOperationException {
+ public PsiJavaCodeReferenceElement createPackageReferenceElement(@NotNull final PsiPackage aPackage) throws IncorrectOperationException {
if (aPackage.getQualifiedName().length() == 0) {
throw new IncorrectOperationException("Cannot create reference to default package.");
}
@@ -441,18 +347,20 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiPackageStatement createPackageStatement(@NotNull String name) throws IncorrectOperationException {
- final PsiJavaFile javaFile = (PsiJavaFile)PsiFileFactory.getInstance(myManager.getProject()).createFileFromText("dummy.java", "package " + name + ";");
- final PsiPackageStatement stmt = javaFile.getPackageStatement();
- if (stmt == null) throw new IncorrectOperationException("Incorrect package name: " + name);
+ public PsiPackageStatement createPackageStatement(@NotNull final String name) throws IncorrectOperationException {
+ final PsiJavaFile aFile = createDummyJavaFile(join("package ", name, ";"));
+ final PsiPackageStatement stmt = aFile.getPackageStatement();
+ if (stmt == null) {
+ throw new IncorrectOperationException("Incorrect package name: " + name);
+ }
return stmt;
}
@NotNull
- public PsiJavaCodeReferenceCodeFragment createReferenceCodeFragment(@NotNull String text,
- PsiElement context,
- boolean isPhysical,
- boolean isClassesAccepted) {
+ public PsiJavaCodeReferenceCodeFragment createReferenceCodeFragment(@NotNull final String text,
+ final PsiElement context,
+ final boolean isPhysical,
+ final boolean isClassesAccepted) {
final PsiJavaCodeReferenceCodeFragmentImpl result =
new PsiJavaCodeReferenceCodeFragmentImpl(myManager.getProject(), isPhysical, "fragment.java", text, isClassesAccepted);
result.setContext(context);
@@ -460,51 +368,54 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiImportStaticStatement createImportStaticStatement(@NotNull PsiClass aClass, @NotNull String memberName) throws IncorrectOperationException {
+ public PsiImportStaticStatement createImportStaticStatement(@NotNull final PsiClass aClass,
+ @NotNull final String memberName) throws IncorrectOperationException {
if (aClass instanceof PsiAnonymousClass) {
throw new IncorrectOperationException("Cannot create import statement for anonymous class.");
}
else if (aClass.getParent() instanceof PsiDeclarationStatement) {
throw new IncorrectOperationException("Cannot create import statement for local class.");
}
- @NonNls String text = "import static " + aClass.getQualifiedName() + "." + memberName + ";";
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiImportStaticStatement statement = aFile.getImportList().getImportStaticStatements()[0];
+
+ final PsiJavaFile aFile = createDummyJavaFile(join("import static ", aClass.getQualifiedName(), ".", memberName, ";"));
+ final PsiImportStatementBase statement = extractImport(aFile, true);
return (PsiImportStaticStatement)CodeStyleManager.getInstance(myManager.getProject()).reformat(statement);
}
@NotNull
- public PsiParameterList createParameterList(@NotNull String[] names, @NotNull PsiType[] types) throws IncorrectOperationException {
- @NonNls String text = "void method(";
- String sep = "";
- for (int i = 0; i < names.length; i++) {
- final String name = names[i];
- PsiType type = types[i];
- text += sep + type.getCanonicalText() + " " + name;
- sep = ",";
+ public PsiParameterList createParameterList(@NotNull final String[] names, @NotNull final PsiType[] types) throws IncorrectOperationException {
+ final StringBuilder builder = StringBuilderSpinAllocator.alloc();
+ try {
+ builder.append("void method(");
+ for (int i = 0; i < names.length; i++) {
+ if (i > 0) builder.append(", ");
+ builder.append(types[i].getCanonicalText()).append(' ').append(names[i]);
+ }
+ return createMethodFromText(builder.toString(), null).getParameterList();
+ }
+ finally {
+ StringBuilderSpinAllocator.dispose(builder);
}
- text += "){}";
- PsiMethod method = createMethodFromText(text, null);
- return method.getParameterList();
}
@NotNull
- public PsiReferenceList createReferenceList(@NotNull PsiJavaCodeReferenceElement[] references) throws IncorrectOperationException {
- @NonNls String text = "void method() ";
- if (references.length > 0) text += "throws ";
- String sep = "";
- for (final PsiJavaCodeReferenceElement reference : references) {
- text += sep + reference.getCanonicalText();
- sep = ",";
+ public PsiReferenceList createReferenceList(@NotNull final PsiJavaCodeReferenceElement[] references) throws IncorrectOperationException {
+ final StringBuilder builder = StringBuilderSpinAllocator.alloc();
+ try {
+ builder.append("void method() throws ");
+ for (int i = 0; i < references.length; i++) {
+ if (i > 0) builder.append(", ");
+ builder.append(references[i].getCanonicalText());
+ }
+ return createMethodFromText(builder.toString(), null).getThrowsList();
+ }
+ finally {
+ StringBuilderSpinAllocator.dispose(builder);
}
- text += "{}";
- PsiMethod method = createMethodFromText(text, null);
- return method.getThrowsList();
}
@NotNull
- public PsiJavaCodeReferenceElement createPackageReferenceElement(@NotNull String packageName)
- throws IncorrectOperationException {
+ public PsiJavaCodeReferenceElement createPackageReferenceElement(@NotNull final String packageName) throws IncorrectOperationException {
if (packageName.length() == 0) {
throw new IncorrectOperationException("Cannot create reference to default package.");
}
@@ -512,8 +423,8 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiReferenceExpression createReferenceExpression(@NotNull PsiClass aClass) throws IncorrectOperationException {
- String text;
+ public PsiReferenceExpression createReferenceExpression(@NotNull final PsiClass aClass) throws IncorrectOperationException {
+ final String text;
if (aClass instanceof PsiAnonymousClass) {
text = ((PsiAnonymousClass)aClass).getBaseClassType().getPresentableText();
}
@@ -524,7 +435,7 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiReferenceExpression createReferenceExpression(@NotNull PsiPackage aPackage) throws IncorrectOperationException {
+ public PsiReferenceExpression createReferenceExpression(@NotNull final PsiPackage aPackage) throws IncorrectOperationException {
if (aPackage.getQualifiedName().length() == 0) {
throw new IncorrectOperationException("Cannot create reference to default package.");
}
@@ -532,13 +443,13 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiIdentifier createIdentifier(@NotNull String text) throws IncorrectOperationException {
+ public PsiIdentifier createIdentifier(@NotNull final String text) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(myManager, text);
return new LightIdentifier(myManager, text);
}
@NotNull
- public PsiKeyword createKeyword(@NotNull String text) throws IncorrectOperationException {
+ public PsiKeyword createKeyword(@NotNull final String text) throws IncorrectOperationException {
if (!JavaPsiFacade.getInstance(myManager.getProject()).getNameHelper().isKeyword(text)) {
throw new IncorrectOperationException("\"" + text + "\" is not a keyword.");
}
@@ -546,21 +457,21 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiImportStatement createImportStatement(@NotNull PsiClass aClass) throws IncorrectOperationException {
+ public PsiImportStatement createImportStatement(@NotNull final PsiClass aClass) throws IncorrectOperationException {
if (aClass instanceof PsiAnonymousClass) {
throw new IncorrectOperationException("Cannot create import statement for anonymous class.");
}
else if (aClass.getParent() instanceof PsiDeclarationStatement) {
throw new IncorrectOperationException("Cannot create import statement for local class.");
}
- @NonNls String text = "import " + aClass.getQualifiedName() + ";";
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiImportStatement statement = aFile.getImportList().getImportStatements()[0];
+
+ final PsiJavaFile aFile = createDummyJavaFile(join("import ", aClass.getQualifiedName(), ";"));
+ final PsiImportStatementBase statement = extractImport(aFile, false);
return (PsiImportStatement)CodeStyleManager.getInstance(myManager.getProject()).reformat(statement);
}
@NotNull
- public PsiImportStatement createImportStatementOnDemand(@NotNull String packageName) throws IncorrectOperationException {
+ public PsiImportStatement createImportStatementOnDemand(@NotNull final String packageName) throws IncorrectOperationException {
if (packageName.length() == 0) {
throw new IncorrectOperationException("Cannot create import statement for default package.");
}
@@ -568,102 +479,103 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
throw new IncorrectOperationException("Incorrect package name: \"" + packageName + "\".");
}
- @NonNls String text = "import " + packageName + ".*;";
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiImportStatement statement = aFile.getImportList().getImportStatements()[0];
+ final PsiJavaFile aFile = createDummyJavaFile(join("import ", packageName, ".*;"));
+ final PsiImportStatementBase statement = extractImport(aFile, false);
return (PsiImportStatement)CodeStyleManager.getInstance(myManager.getProject()).reformat(statement);
}
@NotNull
- public PsiDeclarationStatement createVariableDeclarationStatement(@NotNull String name, @NotNull PsiType type, PsiExpression initializer)
- throws IncorrectOperationException {
+ public PsiDeclarationStatement createVariableDeclarationStatement(@NotNull final String name,
+ @NotNull final PsiType type,
+ final PsiExpression initializer) throws IncorrectOperationException {
if (!JavaPsiFacade.getInstance(myManager.getProject()).getNameHelper().isIdentifier(name)) {
throw new IncorrectOperationException("\"" + name + "\" is not an identifier.");
}
if (PsiType.NULL.equals(type)) {
- throw new IncorrectOperationException("Cannot create field with type \"\".");
+ throw new IncorrectOperationException("Cannot create variable with type \"null\".");
}
- @NonNls StringBuilder buffer = new StringBuilder();
- buffer.append("X ");
- buffer.append(name);
+
+ final StringBuilder builder = StringBuilderSpinAllocator.alloc();
+ builder.append("X ").append(name);
if (initializer != null) {
- buffer.append("=x");
+ builder.append(" = x");
}
- buffer.append(";");
- PsiDeclarationStatement statement = (PsiDeclarationStatement)createStatementFromText(buffer.toString(), null);
- PsiVariable variable = (PsiVariable)statement.getDeclaredElements()[0];
- variable.getTypeElement().replace(createTypeElement(type));
- PsiUtil.setModifierProperty(variable, PsiModifier.FINAL, CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_LOCALS);
+ builder.append(';');
+ final String text = builder.toString();
+ StringBuilderSpinAllocator.dispose(builder);
+
+ final PsiDeclarationStatement statement = (PsiDeclarationStatement)createStatementFromText(text, null);
+ final PsiVariable variable = (PsiVariable)statement.getDeclaredElements()[0];
+ replace(variable.getTypeElement(), createTypeElement(type), text);
+ PsiUtil.setModifierProperty(variable, PsiModifier.FINAL,
+ CodeStyleSettingsManager.getSettings(myManager.getProject()).GENERATE_FINAL_LOCALS);
if (initializer != null) {
- variable.getInitializer().replace(initializer);
+ replace(variable.getInitializer(), initializer, text);
}
markGenerated(statement);
return statement;
-
}
@NotNull
- public PsiDocTag createParamTag(@NotNull String parameterName, @NonNls String description) throws IncorrectOperationException {
- @NonNls StringBuilder buffer = new StringBuilder();
- buffer.append(" * @param ");
- buffer.append(parameterName);
- buffer.append(" ");
- final String[] strings = description.split("\\n");
- for (int i = 0; i < strings.length; i++) {
- String string = strings[i];
- if (i > 0) buffer.append("\n * ");
- buffer.append(string);
+ public PsiDocTag createParamTag(@NotNull final String parameterName, @NonNls final String description) throws IncorrectOperationException {
+ final StringBuilder builder = StringBuilderSpinAllocator.alloc();
+ try {
+ builder.append(" * @param ");
+ builder.append(parameterName);
+ builder.append(" ");
+ final String[] strings = description.split("\\n");
+ for (int i = 0; i < strings.length; i++) {
+ if (i > 0) builder.append("\n * ");
+ builder.append(strings[i]);
+ }
+ return createDocTagFromText(builder.toString());
+ }
+ finally {
+ StringBuilderSpinAllocator.dispose(builder);
}
- return createDocTagFromText(buffer.toString(), null);
}
@NotNull
- public PsiExpressionCodeFragment createExpressionCodeFragment(@NotNull String text,
- PsiElement context,
+ public PsiExpressionCodeFragment createExpressionCodeFragment(@NotNull final String text,
+ final PsiElement context,
final PsiType expectedType,
- boolean isPhysical) {
- final PsiExpressionCodeFragmentImpl result = new PsiExpressionCodeFragmentImpl(
- myManager.getProject(), isPhysical, "fragment.java", text, expectedType);
+ final boolean isPhysical) {
+ final PsiExpressionCodeFragmentImpl result =
+ new PsiExpressionCodeFragmentImpl(myManager.getProject(), isPhysical, "fragment.java", text, expectedType);
result.setContext(context);
return result;
}
@NotNull
- public JavaCodeFragment createCodeBlockCodeFragment(@NotNull String text, PsiElement context, boolean isPhysical) {
- final PsiCodeFragmentImpl result = new PsiCodeFragmentImpl(myManager.getProject(), JavaElementType.STATEMENTS,
- isPhysical,
- "fragment.java",
- text);
+ public JavaCodeFragment createCodeBlockCodeFragment(@NotNull final String text, final PsiElement context, final boolean isPhysical) {
+ final PsiCodeFragmentImpl result =
+ new PsiCodeFragmentImpl(myManager.getProject(), JavaElementType.STATEMENTS, isPhysical, "fragment.java", text);
result.setContext(context);
return result;
}
@NotNull
- public PsiTypeCodeFragment createTypeCodeFragment(@NotNull String text, PsiElement context, boolean isPhysical) {
-
+ public PsiTypeCodeFragment createTypeCodeFragment(@NotNull final String text, final PsiElement context, final boolean isPhysical) {
return createTypeCodeFragment(text, context, false, isPhysical, false);
}
@NotNull
- public PsiTypeCodeFragment createTypeCodeFragment(@NotNull String text,
- PsiElement context,
- boolean isVoidValid,
- boolean isPhysical) {
+ public PsiTypeCodeFragment createTypeCodeFragment(@NotNull final String text,
+ final PsiElement context,
+ final boolean isVoidValid,
+ final boolean isPhysical) {
return createTypeCodeFragment(text, context, true, isPhysical, false);
}
@NotNull
- public PsiTypeCodeFragment createTypeCodeFragment(@NotNull String text,
- PsiElement context,
- boolean isVoidValid,
- boolean isPhysical,
- boolean allowEllipsis) {
- final PsiTypeCodeFragmentImpl result = new PsiTypeCodeFragmentImpl(myManager.getProject(),
- isPhysical,
- allowEllipsis,
- "fragment.java",
- text);
+ public PsiTypeCodeFragment createTypeCodeFragment(@NotNull final String text,
+ final PsiElement context,
+ final boolean isVoidValid,
+ final boolean isPhysical,
+ final boolean allowEllipsis) {
+ final PsiTypeCodeFragmentImpl result
+ = new PsiTypeCodeFragmentImpl(myManager.getProject(), isPhysical, allowEllipsis, "fragment.java", text);
result.setContext(context);
if (isVoidValid) {
result.putUserData(PsiUtil.VALID_VOID_TYPE_IN_CODE_FRAGMENT, Boolean.TRUE);
@@ -671,7 +583,6 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
return result;
}
-
@NotNull
public PsiAnnotation createAnnotationFromText(@NotNull final String annotationText, final PsiElement context) throws IncorrectOperationException {
final PsiAnnotation psiAnnotation = super.createAnnotationFromText(annotationText, context);
@@ -727,8 +638,8 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiTypeParameter createTypeParameterFromText(@NotNull final String text, final PsiElement context) throws
- IncorrectOperationException {
+ public PsiTypeParameter createTypeParameterFromText(@NotNull final String text,
+ final PsiElement context) throws IncorrectOperationException {
final PsiTypeParameter typeParameter = super.createTypeParameterFromText(text, context);
markGenerated(typeParameter);
return typeParameter;
@@ -742,18 +653,18 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
}
@NotNull
- public PsiMethod createMethodFromText(@NotNull final String text, final PsiElement context, final LanguageLevel level) throws
- IncorrectOperationException {
+ public PsiMethod createMethodFromText(@NotNull final String text,
+ final PsiElement context,
+ final LanguageLevel level) throws IncorrectOperationException {
final PsiMethod method = super.createMethodFromText(text, context, level);
markGenerated(method);
return method;
}
-
@NotNull
public PsiCatchSection createCatchSection(@NotNull final PsiClassType exceptionType,
- @NotNull final String exceptionName, final PsiElement context) throws
- IncorrectOperationException {
+ @NotNull final String exceptionName,
+ final PsiElement context) throws IncorrectOperationException {
final PsiCatchSection psiCatchSection = super.createCatchSection(exceptionType, exceptionName, context);
markGenerated(psiCatchSection);
return psiCatchSection;
@@ -762,4 +673,25 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
private static void markGenerated(final PsiElement element) {
((TreeElement)element.getNode()).acceptTree(new GeneratedMarkerVisitor());
}
+
+ private static PsiImportStatementBase extractImport(final PsiJavaFile aFile, final boolean isStatic) {
+ final PsiImportList importList = aFile.getImportList();
+ assert importList != null : aFile;
+ final PsiImportStatementBase[] statements = isStatic ? importList.getImportStaticStatements() : importList.getImportStatements();
+ assert statements.length == 1 : aFile.getText();
+ return statements[0];
+ }
+
+ private static void replace(final PsiElement original, final PsiElement replacement, final String message) {
+ assert original != null : message;
+ original.replace(replacement);
+ }
+
+ /**
+ * @deprecated use {@link PsiJavaParserFacadeImpl#getPrimitiveType(String)} (remove in IDEA 11).
+ */
+ @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
+ public static PsiPrimitiveType getPrimitiveType(final String text) {
+ return PsiJavaParserFacadeImpl.getPrimitiveType(text);
+ }
}
diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java b/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java
index 79bf4d8f2303..acc40b73b1a5 100644
--- a/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java
+++ b/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java
@@ -14,14 +14,13 @@
* limitations under the License.
*/
-/*
- * @author max
- */
package com.intellij.psi.impl;
import com.intellij.ide.fileTemplates.FileTemplate;
import com.intellij.ide.fileTemplates.FileTemplateManager;
import com.intellij.ide.fileTemplates.JavaTemplateUtil;
+import com.intellij.lang.PsiBuilder;
+import com.intellij.lang.java.parser.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
@@ -29,79 +28,154 @@ import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
+import com.intellij.psi.impl.source.DummyHolder;
import com.intellij.psi.impl.source.DummyHolderFactory;
+import com.intellij.psi.impl.source.JavaDummyElement;
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
-import com.intellij.psi.impl.source.parsing.DeclarationParsing;
-import com.intellij.psi.impl.source.parsing.ExpressionParsing;
-import com.intellij.psi.impl.source.parsing.JavaParsingContext;
-import com.intellij.psi.impl.source.parsing.Parsing;
-import com.intellij.psi.impl.source.tree.CompositeElement;
-import com.intellij.psi.impl.source.tree.FileElement;
-import com.intellij.psi.impl.source.tree.JavaElementType;
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.PsiUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.HashMap;
-import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Properties;
+import static com.intellij.openapi.util.text.StringUtil.join;
+
+/*
+ * @author max
+ */
public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJavaParserFacade {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.PsiJavaParserFacadeImpl");
- protected static final Map ourPrimitiveTypesMap = new HashMap();
- protected PsiJavaFile myDummyJavaFile;
+ private static final JavaParserUtil.ParserWrapper ANNOTATION = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ DeclarationParser.parseAnnotation(builder);
+ }
+ };
- public PsiJavaParserFacadeImpl(PsiManagerEx manager) {
+ private static final JavaParserUtil.ParserWrapper PARAMETER = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ DeclarationParser.parseParameter(builder, true);
+ }
+ };
+
+ private static final JavaParserUtil.ParserWrapper TYPE = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ ReferenceParser.parseType(builder, ReferenceParser.EAT_LAST_DOT | ReferenceParser.ELLIPSIS | ReferenceParser.WILDCARD);
+ }
+ };
+
+ private static final JavaParserUtil.ParserWrapper TYPE_PARAMETER = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ ReferenceParser.parseTypeParameter(builder);
+ }
+ };
+
+ private static final JavaParserUtil.ParserWrapper DECLARATION = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ DeclarationParser.parse(builder, DeclarationParser.Context.CLASS);
+ }
+ };
+
+ private static final JavaParserUtil.ParserWrapper CODE_BLOCK = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ StatementParser.parseCodeBlockDeep(builder, true);
+ }
+ };
+
+ private static final JavaParserUtil.ParserWrapper STATEMENT = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ StatementParser.parseStatement(builder);
+ }
+ };
+
+ private static final JavaParserUtil.ParserWrapper EXPRESSION = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ ExpressionParser.parse(builder);
+ }
+ };
+
+ private static final JavaParserUtil.ParserWrapper ENUM_CONSTANT = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ DeclarationParser.parseEnumConstant(builder);
+ }
+ };
+
+ private static final JavaParserUtil.ParserWrapper CATCH_SECTION = new JavaParserUtil.ParserWrapper() {
+ @Override
+ public void parse(final PsiBuilder builder) {
+ StatementParser.parseCatchBlock(builder);
+ }
+ };
+
+ private static final Map PRIMITIVE_TYPES;
+ static {
+ PRIMITIVE_TYPES = new HashMap();
+ PRIMITIVE_TYPES.put(PsiType.BYTE.getCanonicalText(), PsiType.BYTE);
+ PRIMITIVE_TYPES.put(PsiType.CHAR.getCanonicalText(), PsiType.CHAR);
+ PRIMITIVE_TYPES.put(PsiType.DOUBLE.getCanonicalText(), PsiType.DOUBLE);
+ PRIMITIVE_TYPES.put(PsiType.FLOAT.getCanonicalText(), PsiType.FLOAT);
+ PRIMITIVE_TYPES.put(PsiType.INT.getCanonicalText(), PsiType.INT);
+ PRIMITIVE_TYPES.put(PsiType.LONG.getCanonicalText(), PsiType.LONG);
+ PRIMITIVE_TYPES.put(PsiType.SHORT.getCanonicalText(), PsiType.SHORT);
+ PRIMITIVE_TYPES.put(PsiType.BOOLEAN.getCanonicalText(), PsiType.BOOLEAN);
+ PRIMITIVE_TYPES.put(PsiType.VOID.getCanonicalText(), PsiType.VOID);
+ PRIMITIVE_TYPES.put(PsiType.NULL.getCanonicalText(), PsiType.NULL);
+ }
+
+ public PsiJavaParserFacadeImpl(final PsiManagerEx manager) {
super(manager);
}
@NotNull
- public PsiAnnotation createAnnotationFromText(@NotNull String annotationText, PsiElement context) throws IncorrectOperationException {
- final FileElement holderElement = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- CompositeElement annotationElement = getJavaParsingContext(holderElement).getDeclarationParsing().parseAnnotationFromText(myManager, annotationText, getLanguageLevel(context));
- if (annotationElement == null || annotationElement.getElementType() != JavaElementType.ANNOTATION) {
- throw new IncorrectOperationException("Incorrect annotation \"" + annotationText + "\".");
+ public PsiAnnotation createAnnotationFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ANNOTATION, false), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiAnnotation)) {
+ throw new IncorrectOperationException("Incorrect annotation \"" + text + "\".");
}
- holderElement.rawAddChildren(annotationElement);
- return (PsiAnnotation)SourceTreeToPsiMap.treeElementToPsi(annotationElement);
- }
-
- private LanguageLevel getLanguageLevel(final PsiElement context) {
- if (context == null) {
- return LanguageLevelProjectExtension.getInstance(myManager.getProject()).getLanguageLevel();
- }
- return PsiUtil.getLanguageLevel(context);
+ return (PsiAnnotation)element;
}
@NotNull
- public PsiDocTag createDocTagFromText(@NotNull String docTagText, PsiElement context) throws IncorrectOperationException {
- StringBuilder buffer = new StringBuilder();
- buffer.append("/**\n");
- buffer.append(docTagText);
- buffer.append("\n */");
- PsiDocComment comment = createDocCommentFromText(buffer.toString(), context);
- return comment.getTags()[0];
+ public PsiDocTag createDocTagFromText(@NotNull final String text) throws IncorrectOperationException {
+ return createDocCommentFromText(join("/**\n", text, "\n */")).getTags()[0];
}
@NotNull
- public PsiDocComment createDocCommentFromText(@NotNull String docCommentText, PsiElement context) throws IncorrectOperationException {
- @NonNls StringBuilder buffer = new StringBuilder();
- buffer.append(docCommentText);
- buffer.append("void m();");
- final PsiMethod method = createMethodFromText(buffer.toString(), null);
- return method.getDocComment();
+ public PsiDocTag createDocTagFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ return createDocTagFromText(text);
}
@NotNull
- public PsiClass createClassFromText(@NotNull String body, PsiElement context) throws IncorrectOperationException {
- @NonNls String fileText = "class _Dummy_ { " + body + " }";
- PsiJavaFile aFile = createDummyJavaFile(fileText);
- PsiClass[] classes = aFile.getClasses();
+ public PsiDocComment createDocCommentFromText(@NotNull final String text) throws IncorrectOperationException {
+ final PsiMethod method = createMethodFromText(join(text, "void m();"), null);
+ final PsiDocComment comment = method.getDocComment();
+ assert comment != null : text;
+ return comment;
+ }
+
+ @NotNull
+ public PsiDocComment createDocCommentFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ return createDocCommentFromText(text);
+ }
+
+ @NotNull
+ public PsiClass createClassFromText(@NotNull final String body, final PsiElement context) throws IncorrectOperationException {
+ final PsiJavaFile aFile = createDummyJavaFile(join("class _Dummy_ { ", body, " }"));
+ final PsiClass[] classes = aFile.getClasses();
if (classes.length != 1) {
throw new IncorrectOperationException("Incorrect class \"" + body + "\".");
}
@@ -109,211 +183,186 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
}
@NotNull
- public PsiField createFieldFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException {
- final FileElement holderElement = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- TreeElement decl = getJavaParsingContext(holderElement).getDeclarationParsing().parseDeclarationText(myManager, LanguageLevelProjectExtension
- .getInstance(myManager.getProject()).getLanguageLevel(), text, DeclarationParsing.Context.CLASS_CONTEXT);
- if (decl == null || decl.getElementType() != JavaElementType.FIELD) {
+ public PsiField createFieldFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, false), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiField)) {
throw new IncorrectOperationException("Incorrect field \"" + text + "\".");
}
- holderElement.rawAddChildren(decl);
- return (PsiField)SourceTreeToPsiMap.treeElementToPsi(decl);
- }
-
- protected JavaParsingContext getJavaParsingContext (FileElement holderElement) {
- return new JavaParsingContext(holderElement.getCharTable(), LanguageLevelProjectExtension.getInstance(myManager.getProject()).getLanguageLevel());
- }
-
- private static JavaParsingContext getJavaParsingContext (FileElement holderElement, LanguageLevel languageLevel) {
- return new JavaParsingContext(holderElement.getCharTable(), languageLevel);
+ return (PsiField)element;
}
@NotNull
- public PsiMethod createMethodFromText(@NotNull String text, PsiElement context, LanguageLevel level) throws IncorrectOperationException {
- final FileElement holderElement = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- TreeElement decl = getJavaParsingContext(holderElement, level).getDeclarationParsing().parseDeclarationText(myManager, level, text,
- DeclarationParsing.Context.CLASS_CONTEXT);
- if (decl == null || decl.getElementType() != JavaElementType.METHOD) {
- throw new IncorrectOperationException("Incorrect method '" + text + "'. Context:"+context+"; Level:"+level+"; parsed: "+(decl == null ? null : DebugUtil.treeToString(decl, false)));
+ public PsiMethod createMethodFromText(@NotNull final String text, final PsiElement context, final LanguageLevel level)
+ throws IncorrectOperationException {
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, false, level), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiMethod)) {
+ throw new IncorrectOperationException("Incorrect method \"" + text + "\".");
}
- holderElement.rawAddChildren(decl);
- return (PsiMethod)SourceTreeToPsiMap.treeElementToPsi(decl);
+ return (PsiMethod)element;
}
@NotNull
- public final PsiMethod createMethodFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException {
- return createMethodFromText(text, context, LanguageLevelProjectExtension.getInstance(myManager.getProject()).getLanguageLevel());
+ public final PsiMethod createMethodFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final LanguageLevel level = LanguageLevelProjectExtension.getInstance(myManager.getProject()).getLanguageLevel();
+ return createMethodFromText(text, context, level);
}
@NotNull
- public PsiParameter createParameterFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException {
- final FileElement holderElement = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- CompositeElement param = getJavaParsingContext(holderElement).getDeclarationParsing().parseParameterText(text);
- if (param == null) {
+ public PsiParameter createParameterFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, PARAMETER, false), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiParameter)) {
throw new IncorrectOperationException("Incorrect parameter \"" + text + "\".");
}
- holderElement.rawAddChildren(param);
- return (PsiParameter)SourceTreeToPsiMap.treeElementToPsi(param);
+ return (PsiParameter)element;
}
@NotNull
- public PsiType createTypeFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException {
+ public PsiType createTypeFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
return createTypeInner(text, context, false);
}
- protected PsiType createTypeInner(final String text, final PsiElement context, boolean markAsCopy) throws IncorrectOperationException {
- PsiPrimitiveType primitiveType = ourPrimitiveTypesMap.get(text);
+ protected PsiType createTypeInner(final String text, final PsiElement context, final boolean markAsCopy) throws IncorrectOperationException {
+ final PsiPrimitiveType primitiveType = PRIMITIVE_TYPES.get(text);
if (primitiveType != null) return primitiveType;
- final FileElement holderElement = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- CompositeElement typeElement = Parsing.parseTypeText(myManager, text, 0, text.length(), holderElement.getCharTable());
- if (typeElement == null) {
- throw new IncorrectOperationException("Incorrect type \"" + text + "\"");
+
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE, false), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiTypeElement)) {
+ throw new IncorrectOperationException("Incorrect type \"" + text + "\".");
}
- holderElement.rawAddChildren(typeElement);
+
if (markAsCopy) {
- holderElement.acceptTree(new GeneratedMarkerVisitor());
+ holder.getTreeElement().acceptTree(new GeneratedMarkerVisitor());
}
- PsiTypeElement psiTypeElement = (PsiTypeElement)SourceTreeToPsiMap.treeElementToPsi(typeElement);
- if (psiTypeElement == null) {
- throw new IncorrectOperationException("PSI is null for element "+typeElement);
- }
- return psiTypeElement.getType();
+
+ return ((PsiTypeElement)element).getType();
}
@NotNull
- public PsiCodeBlock createCodeBlockFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException {
- final FileElement holderElement = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- CompositeElement treeElement = getJavaParsingContext(holderElement).getStatementParsing().parseCodeBlockText(myManager, text);
- if (treeElement == null) {
+ public PsiCodeBlock createCodeBlockFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CODE_BLOCK, true), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiCodeBlock)) {
throw new IncorrectOperationException("Incorrect code block \"" + text + "\".");
}
- holderElement.rawAddChildren(treeElement);
- return (PsiCodeBlock)SourceTreeToPsiMap.treeElementToPsi(treeElement);
+ return (PsiCodeBlock)element;
}
@NotNull
- public PsiStatement createStatementFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException {
- final FileElement treeHolder = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- TreeElement treeElement = getJavaParsingContext(treeHolder).getStatementParsing().parseStatementText(text);
- if (treeElement == null) {
+ public PsiStatement createStatementFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, STATEMENT, false), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiStatement)) {
throw new IncorrectOperationException("Incorrect statement \"" + text + "\".");
}
- treeHolder.rawAddChildren(treeElement);
- return (PsiStatement)SourceTreeToPsiMap.treeElementToPsi(treeElement);
+ return (PsiStatement)element;
}
@NotNull
- public PsiExpression createExpressionFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException {
- final FileElement treeHolder = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- final CompositeElement treeElement = ExpressionParsing.parseExpressionText(myManager, text, 0,
- text.length(), treeHolder.getCharTable());
- if (treeElement == null) {
+ public PsiExpression createExpressionFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, EXPRESSION, false), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiExpression)) {
throw new IncorrectOperationException("Incorrect expression \"" + text + "\".");
}
- treeHolder.rawAddChildren(treeElement);
- return (PsiExpression)SourceTreeToPsiMap.treeElementToPsi(treeElement);
+ return (PsiExpression)element;
}
- protected PsiJavaFile createDummyJavaFile(String text) {
- String ext = StdFileTypes.JAVA.getDefaultExtension();
- @NonNls String fileName = "_Dummy_." + ext;
- FileType type = StdFileTypes.JAVA;
-
+ protected PsiJavaFile createDummyJavaFile(final String text) {
+ final String fileName = "_Dummy_." + StdFileTypes.JAVA.getDefaultExtension();
+ final FileType type = StdFileTypes.JAVA;
return (PsiJavaFile)PsiFileFactory.getInstance(myManager.getProject()).createFileFromText(type, fileName, text, 0, text.length());
}
@NotNull
- public PsiTypeParameter createTypeParameterFromText(@NotNull String text, PsiElement context)
- throws IncorrectOperationException {
- final FileElement holderElement = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- TreeElement treeElement = getJavaParsingContext(holderElement).getDeclarationParsing().parseTypeParameterText(text);
- if (treeElement == null) {
- throw new IncorrectOperationException("Incorrect type parameter \"" + text + "\"");
+ public PsiTypeParameter createTypeParameterFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE_PARAMETER, false), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiTypeParameter)) {
+ throw new IncorrectOperationException("Incorrect type parameter \"" + text + "\".");
}
- holderElement.rawAddChildren(treeElement);
- return (PsiTypeParameter)SourceTreeToPsiMap.treeElementToPsi(treeElement);
+ return (PsiTypeParameter)element;
}
@NotNull
- public PsiComment createCommentFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException {
- PsiJavaFile aFile = createDummyJavaFile(text);
- PsiElement[] children = aFile.getChildren();
- for (PsiElement aChildren : children) {
+ public PsiComment createCommentFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final PsiJavaFile aFile = createDummyJavaFile(text);
+ for (PsiElement aChildren : aFile.getChildren()) {
if (aChildren instanceof PsiComment) {
if (!aChildren.getText().equals(text)) {
- throw new IncorrectOperationException("Incorrect comment \"" + text + "\".");
+ break;
}
- PsiComment comment = (PsiComment)aChildren;
+ final PsiComment comment = (PsiComment)aChildren;
DummyHolderFactory.createHolder(myManager, (TreeElement)SourceTreeToPsiMap.psiElementToTree(comment), context);
return comment;
}
}
+
throw new IncorrectOperationException("Incorrect comment \"" + text + "\".");
}
@NotNull
- public PsiEnumConstant createEnumConstantFromText(@NotNull String text, PsiElement context) throws IncorrectOperationException {
- final FileElement holderElement = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- TreeElement decl = getJavaParsingContext(holderElement).getDeclarationParsing().parseEnumConstantText(text);
- if (decl == null || decl.getElementType() != JavaElementType.ENUM_CONSTANT) {
- throw new IncorrectOperationException("Incorrect enum constant text \"" + text + "\".");
+ public PsiEnumConstant createEnumConstantFromText(@NotNull final String text, final PsiElement context) throws IncorrectOperationException {
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ENUM_CONSTANT, false), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiEnumConstant)) {
+ throw new IncorrectOperationException("Incorrect enum constant \"" + text + "\".");
}
- holderElement.rawAddChildren(decl);
- return (PsiEnumConstant)SourceTreeToPsiMap.treeElementToPsi(decl);
+ return (PsiEnumConstant)element;
}
@NotNull
- public PsiCatchSection createCatchSection(@NotNull PsiClassType exceptionType,
- @NotNull String exceptionName,
- PsiElement context) throws IncorrectOperationException {
- @NonNls StringBuilder buffer = new StringBuilder();
- buffer.append("catch (");
- buffer.append(exceptionType.getCanonicalText());
- buffer.append(" ").append(exceptionName).append("){}");
- String catchSectionText = buffer.toString();
- final FileElement holderElement = DummyHolderFactory.createHolder(myManager, context).getTreeElement();
- TreeElement catchSection = getJavaParsingContext(holderElement).getStatementParsing().parseCatchSectionText(catchSectionText);
- if (catchSection == null || catchSection.getElementType() != JavaElementType.CATCH_SECTION) {
- LOG.error(catchSectionText + "\nPSI:" + (catchSection == null ? null : DebugUtil.treeToString(catchSection, false)));
+ public PsiCatchSection createCatchSection(@NotNull final PsiClassType exceptionType, @NotNull final String exceptionName,
+ final PsiElement context) throws IncorrectOperationException {
+ final String text = join("catch (", exceptionType.getCanonicalText(), " ", exceptionName, ") {}");
+ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CATCH_SECTION, false), context);
+ final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
+ if (!(element instanceof PsiCatchSection)) {
+ throw new IncorrectOperationException("Incorrect catch section \"" + text + "\".");
}
- holderElement.rawAddChildren(catchSection);
- PsiCatchSection psiCatchSection = (PsiCatchSection)SourceTreeToPsiMap.treeElementToPsi(catchSection);
-
- setupCatchBlock(exceptionName, context, psiCatchSection);
- return (PsiCatchSection)myManager.getCodeStyleManager().reformat(psiCatchSection);
+ setupCatchBlock(exceptionName, context, (PsiCatchSection)element);
+ return (PsiCatchSection)myManager.getCodeStyleManager().reformat(element);
}
- private void setupCatchBlock(String exceptionName, PsiElement context, PsiCatchSection psiCatchSection)
- throws IncorrectOperationException {
- FileTemplate catchBodyTemplate = FileTemplateManager.getInstance().getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
+ private void setupCatchBlock(final String exceptionName, final PsiElement context, final PsiCatchSection psiCatchSection)
+ throws IncorrectOperationException {
+ final FileTemplate catchBodyTemplate = FileTemplateManager.getInstance().getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
LOG.assertTrue(catchBodyTemplate != null);
- Properties props = new Properties();
+ final Properties props = new Properties();
props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION, exceptionName);
if (context != null && context.isPhysical()) {
- PsiDirectory directory = context.getContainingFile().getContainingDirectory();
+ final PsiDirectory directory = context.getContainingFile().getContainingDirectory();
if (directory != null) {
JavaTemplateUtil.setPackageNameAttribute(props, directory);
}
}
- PsiCodeBlock codeBlockFromText;
+
+ final PsiCodeBlock codeBlockFromText;
try {
- String catchBody = catchBodyTemplate.getText(props);
- codeBlockFromText = createCodeBlockFromText("{\n" + catchBody + "\n}", null);
+ codeBlockFromText = createCodeBlockFromText("{\n" + catchBodyTemplate.getText(props) + "\n}", null);
}
catch (ProcessCanceledException ce) {
throw ce;
}
catch (Exception e) {
- throw new IncorrectOperationException("Incorrect file template",e);
+ throw new IncorrectOperationException("Incorrect file template", e);
}
psiCatchSection.getCatchBlock().replace(codeBlockFromText);
}
- public PsiType createPrimitiveType(@NotNull String text, @NotNull PsiAnnotation[] annotations) {
- if (annotations.length == 0) {
- return PsiElementFactoryImpl.getPrimitiveType(text);//todo
+ public PsiType createPrimitiveType(@NotNull final String text, @NotNull final PsiAnnotation[] annotations) throws IncorrectOperationException {
+ final PsiPrimitiveType primitiveType = getPrimitiveType(text);
+ if (primitiveType == null) {
+ throw new IncorrectOperationException("Incorrect primitive type \"" + text + "\".");
}
- return new PsiPrimitiveType(text, annotations);
+ return annotations.length == 0 ? primitiveType : new PsiPrimitiveType(text, annotations);
+ }
+
+ public static PsiPrimitiveType getPrimitiveType(final String text) {
+ return PRIMITIVE_TYPES.get(text);
}
}
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/JavaDummyElement.java b/java/java-impl/src/com/intellij/psi/impl/source/JavaDummyElement.java
new file mode 100644
index 000000000000..c54c4e18eba8
--- /dev/null
+++ b/java/java-impl/src/com/intellij/psi/impl/source/JavaDummyElement.java
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+package com.intellij.psi.impl.source;
+
+import com.intellij.lang.java.parser.JavaParserUtil;
+import com.intellij.pom.java.LanguageLevel;
+import com.intellij.psi.impl.source.tree.FileElement;
+import com.intellij.psi.impl.source.tree.JavaElementType;
+import com.intellij.psi.impl.source.tree.TreeElement;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Dummy file element for using together with DummyHolder.
+ * See {@link com.intellij.psi.impl.PsiJavaParserFacadeImpl} for details.
+ */
+public class JavaDummyElement extends FileElement {
+ @NotNull private final JavaParserUtil.ParserWrapper myParser;
+ private final boolean myConsumeAll;
+ @NotNull private final LanguageLevel myLanguageLevel;
+
+ public JavaDummyElement(@Nullable final CharSequence text, @NotNull final JavaParserUtil.ParserWrapper parser, final boolean consumeAll) {
+ this(text, parser, consumeAll, LanguageLevel.HIGHEST);
+ }
+
+ public JavaDummyElement(@Nullable final CharSequence text,
+ @NotNull final JavaParserUtil.ParserWrapper parser,
+ final boolean consumeAll,
+ @NotNull final LanguageLevel level) {
+ super(JavaElementType.DUMMY_ELEMENT, text);
+ myParser = parser;
+ myConsumeAll = consumeAll;
+ myLanguageLevel = level;
+ }
+
+ @NotNull
+ public JavaParserUtil.ParserWrapper getParser() {
+ return myParser;
+ }
+
+ public boolean consumeAll() {
+ return myConsumeAll;
+ }
+
+ @NotNull
+ public LanguageLevel getLanguageLevel() {
+ return myLanguageLevel;
+ }
+
+ @Override
+ public TreeElement getFirstChildNode() {
+ try {
+ return super.getFirstChildNode();
+ }
+ catch (AssertionError e) {
+ return null; // masquerade parser errors
+ }
+ }
+
+ @Override
+ public TreeElement getLastChildNode() {
+ try {
+ return super.getLastChildNode();
+ }
+ catch (AssertionError e) {
+ return null; // masquerade parser errors
+ }
+ }
+}
\ No newline at end of file
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/ClassBodyParsing.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/ClassBodyParsing.java
index af3dcdf38783..5261951b12a6 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/ClassBodyParsing.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/ClassBodyParsing.java
@@ -25,7 +25,7 @@ import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.psi.tree.IElementType;
/**
- *
+ * @deprecated old Java parser is deprecated in favor of PSI builder-based one (see com.intellij.lang.java.parser.*) (to remove in IDEA 11).
*/
public class ClassBodyParsing extends Parsing {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.parsing.ClassBodyParsing");
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/DeclarationParsing.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/DeclarationParsing.java
index a220b14d694a..10899f2551ef 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/DeclarationParsing.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/DeclarationParsing.java
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
- *
+ * @deprecated old Java parser is deprecated in favor of PSI builder-based one (see com.intellij.lang.java.parser.*) (to remove in IDEA 11).
*/
public class DeclarationParsing extends Parsing {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.parsing.DeclarationParsing");
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/ExpressionParsing.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/ExpressionParsing.java
index fc27fc95ca14..fb96293d27e0 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/ExpressionParsing.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/ExpressionParsing.java
@@ -34,6 +34,9 @@ import com.intellij.psi.tree.TokenSet;
import com.intellij.util.CharTable;
import org.jetbrains.annotations.NotNull;
+/**
+ * @deprecated old Java parser is deprecated in favor of PSI builder-based one (see com.intellij.lang.java.parser.*) (to remove in IDEA 11).
+ */
public class ExpressionParsing extends Parsing {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.parsing.ExpressionParsing");
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/FileTextParsing.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/FileTextParsing.java
index 50bdf945ddd0..93035892410e 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/FileTextParsing.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/FileTextParsing.java
@@ -31,7 +31,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
- *
+ * @deprecated old Java parser is deprecated in favor of PSI builder-based one (see com.intellij.lang.java.parser.*) (to remove in IDEA 11).
*/
public class FileTextParsing extends Parsing {
public FileTextParsing(JavaParsingContext context) {
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/ImportsTextParsing.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/ImportsTextParsing.java
index 2a24d49bd43a..bae311297dba 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/ImportsTextParsing.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/ImportsTextParsing.java
@@ -28,7 +28,7 @@ import com.intellij.psi.TokenType;
import org.jetbrains.annotations.Nullable;
/**
- *
+ * @deprecated old Java parser is deprecated in favor of PSI builder-based one (see com.intellij.lang.java.parser.*) (to remove in IDEA 11).
*/
public class ImportsTextParsing extends Parsing {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.parsing.ImportsTextParsing");
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/JavadocParsing.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/JavadocParsing.java
index 0617588c385b..b43a2b70755d 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/JavadocParsing.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/JavadocParsing.java
@@ -33,6 +33,9 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NonNls;
+/**
+ * todo[r.sh] rewrite and deprecate
+ */
public class JavadocParsing extends Parsing {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.parsing.JavadocParsing");
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/Parsing.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/Parsing.java
index b9a38cba114a..a93645b172a5 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/Parsing.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/Parsing.java
@@ -33,6 +33,9 @@ import com.intellij.util.CharTable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+/**
+ * @deprecated old Java parser is deprecated in favor of PSI builder-based one (see com.intellij.lang.java.parser.*) (to remove in IDEA 11).
+ */
public class Parsing {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.parsing.Parsing");
protected static final boolean DEEP_PARSE_BLOCKS_IN_STATEMENTS = false;
@@ -198,8 +201,8 @@ public class Parsing {
return type;
}
- public CompositeElement parseTypeWithEllipsis(Lexer lexer, boolean eatLastDot, boolean allowWilcard) {
- CompositeElement type = parseType(lexer, eatLastDot, allowWilcard, false);
+ public CompositeElement parseTypeWithEllipsis(Lexer lexer, boolean eatLastDot, boolean allowWildcard) {
+ CompositeElement type = parseType(lexer, eatLastDot, allowWildcard, false);
if (type == null) return null;
if (lexer.getTokenType() == JavaTokenType.ELLIPSIS) {
CompositeElement type1 = ASTFactory.composite(JavaElementType.TYPE);
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/StatementParsing.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/StatementParsing.java
index 6e4f8feade39..c45036a40403 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/StatementParsing.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/StatementParsing.java
@@ -33,6 +33,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
+/**
+ * @deprecated old Java parser is deprecated in favor of PSI builder-based one (see com.intellij.lang.java.parser.*) (to remove in IDEA 11).
+ */
public class StatementParsing extends Parsing {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.parsing.StatementParsing");
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/PsiDocTagValueManipulator.java b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/PsiDocTagValueManipulator.java
index 66fd5a77ae72..4388efd53c9c 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/PsiDocTagValueManipulator.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/manipulators/PsiDocTagValueManipulator.java
@@ -36,7 +36,7 @@ public class PsiDocTagValueManipulator extends AbstractElementManipulator parseContents(final LighterLazyParseableNode chameleon) {
final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
StatementParser.parseCodeBlockDeep(builder, true);
@@ -194,6 +198,8 @@ public interface JavaElementType {
ILazyParseableElementType CODE_BLOCK = JavaParserDefinition.USE_NEW_PARSER ? new ICodeBlockNewElementType() : new ICodeBlockElementType();
IElementType STATEMENTS = new ICodeFragmentElementType("STATEMENTS", StdLanguages.JAVA) {
+ @Nullable
+ @Override
public ASTNode parseContents(final ASTNode chameleon) {
if (JavaParserDefinition.USE_NEW_PARSER) {
return JavaParserUtil.parseFragment(chameleon,
@@ -213,6 +219,8 @@ public interface JavaElementType {
};
IElementType EXPRESSION_TEXT = new ICodeFragmentElementType("EXPRESSION_TEXT", StdLanguages.JAVA) {
+ @Nullable
+ @Override
public ASTNode parseContents(final ASTNode chameleon) {
if (JavaParserDefinition.USE_NEW_PARSER) {
return JavaParserUtil.parseFragment(chameleon,
@@ -231,6 +239,8 @@ public interface JavaElementType {
};
IElementType REFERENCE_TEXT = new ICodeFragmentElementType("REFERENCE_TEXT", StdLanguages.JAVA) {
+ @Nullable
+ @Override
public ASTNode parseContents(final ASTNode chameleon) {
if (JavaParserDefinition.USE_NEW_PARSER) {
return JavaParserUtil.parseFragment(chameleon,
@@ -248,6 +258,8 @@ public interface JavaElementType {
};
IElementType TYPE_TEXT = new ICodeFragmentElementType("TYPE_TEXT", StdLanguages.JAVA) {
+ @Nullable
+ @Override
public ASTNode parseContents(final ASTNode chameleon) {
if (JavaParserDefinition.USE_NEW_PARSER) {
return JavaParserUtil.parseFragment(chameleon,
@@ -264,4 +276,14 @@ public interface JavaElementType {
SharedImplUtil.findCharTableByTree(chameleon));
}
};
+
+ IElementType DUMMY_ELEMENT = new ILazyParseableElementType("DUMMY_ELEMENT", StdLanguages.JAVA) {
+ @Nullable
+ @Override
+ public ASTNode parseContents(final ASTNode chameleon) {
+ assert chameleon instanceof JavaDummyElement : chameleon;
+ final JavaDummyElement dummyElement = (JavaDummyElement)chameleon;
+ return JavaParserUtil.parseFragment(chameleon, dummyElement.getParser(), dummyElement.consumeAll(), dummyElement.getLanguageLevel());
+ }
+ };
}
diff --git a/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java b/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java
index f834fb0292b4..19f0c1df49c4 100644
--- a/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java
@@ -395,7 +395,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
final CodeStyleManager codeStyleManager = manager.getCodeStyleManager();
@NonNls final StringBuilder fieldBuffer = new StringBuilder();
final String delegateVisibility = calculateDelegateVisibility();
- fieldBuffer.append(delegateVisibility).append(' ');
+ if (delegateVisibility.length() > 0) fieldBuffer.append(delegateVisibility).append(' ');
fieldBuffer.append("final ");
final String fullyQualifiedName = StringUtil.getQualifiedName(newPackageName, newClassName);
fieldBuffer.append(fullyQualifiedName);
@@ -408,8 +408,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
}
fieldBuffer.append(' ');
fieldBuffer.append(delegateFieldName);
- fieldBuffer.append('=');
- fieldBuffer.append("new ").append(fullyQualifiedName);
+ fieldBuffer.append(" = new ").append(fullyQualifiedName);
if (!typeParams.isEmpty()) {
fieldBuffer.append('<');
for (PsiTypeParameter typeParameter : typeParams) {
diff --git a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java
index 2b5749a0eef2..ca4042a25a18 100644
--- a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java
@@ -312,8 +312,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
}
if (compatibleParamObjectConstructor != null) {
- PsiDocComment psiDocComment =
- JavaPsiFacade.getElementFactory(myProject).createDocCommentFromText("/**\n*/", compatibleParamObjectConstructor);
+ PsiDocComment psiDocComment = JavaPsiFacade.getElementFactory(myProject).createDocCommentFromText("/**\n*/");
psiDocComment = (PsiDocComment)compatibleParamObjectConstructor.addBefore(psiDocComment, compatibleParamObjectConstructor.getFirstChild());
for (PsiDocTag tag : mergedTags) {
diff --git a/java/java-impl/src/com/intellij/refactoring/util/RefactoringHierarchyUtil.java b/java/java-impl/src/com/intellij/refactoring/util/RefactoringHierarchyUtil.java
index 573eeffbc369..257f978adc0a 100644
--- a/java/java-impl/src/com/intellij/refactoring/util/RefactoringHierarchyUtil.java
+++ b/java/java-impl/src/com/intellij/refactoring/util/RefactoringHierarchyUtil.java
@@ -38,7 +38,8 @@ import java.util.*;
public class RefactoringHierarchyUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.util.RefactoringHierarchyUtil");
- private static final List PRIMITIVE_TYPES = Arrays.asList(
+
+ private static final List extends PsiType> PRIMITIVE_TYPES = Arrays.asList(
PsiType.BYTE, PsiType.CHAR, PsiType.SHORT, PsiType.INT, PsiType.LONG, PsiType.FLOAT, PsiType.DOUBLE
);
diff --git a/java/java-impl/src/com/intellij/util/xml/PsiClassConverter.java b/java/java-impl/src/com/intellij/util/xml/PsiClassConverter.java
index df16f85a8abd..32785e7a44c3 100644
--- a/java/java-impl/src/com/intellij/util/xml/PsiClassConverter.java
+++ b/java/java-impl/src/com/intellij/util/xml/PsiClassConverter.java
@@ -97,7 +97,7 @@ public class PsiClassConverter extends Converter implements CustomRefe
@Nullable
protected GlobalSearchScope getScope(final GenericDomValue domValue) {
final Module module = domValue.getModule();
- return module == null ? null : GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
+ return module == null ? null : GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
}
public static class AnnotationType extends PsiClassConverter {
diff --git a/java/java-tests/testData/codeInsight/completion/normal/MethodWithLeftParTailType2_after.java b/java/java-tests/testData/codeInsight/completion/normal/MethodWithLeftParTailType2_after.java
index 82b0a037822d..b4b5c16848e6 100644
--- a/java/java-tests/testData/codeInsight/completion/normal/MethodWithLeftParTailType2_after.java
+++ b/java/java-tests/testData/codeInsight/completion/normal/MethodWithLeftParTailType2_after.java
@@ -3,6 +3,6 @@ class MyClass {
void foo(int a) {}
{
- foo()
+ foo();
}
}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/completion/smartType/ConstructorNoPairBracketSemicolon-out.java b/java/java-tests/testData/codeInsight/completion/smartType/ConstructorNoPairBracketSemicolon-out.java
new file mode 100644
index 000000000000..b1b9a92a066c
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/completion/smartType/ConstructorNoPairBracketSemicolon-out.java
@@ -0,0 +1,5 @@
+class A {
+ {
+ String c = new String();
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/completion/smartType/ConstructorNoPairBracketSemicolon.java b/java/java-tests/testData/codeInsight/completion/smartType/ConstructorNoPairBracketSemicolon.java
new file mode 100644
index 000000000000..f05c0210cb13
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/completion/smartType/ConstructorNoPairBracketSemicolon.java
@@ -0,0 +1,5 @@
+class A {
+ {
+ String c = new Stri
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/completion/smartType/MethodNoPairBracketComma-out.java b/java/java-tests/testData/codeInsight/completion/smartType/MethodNoPairBracketComma-out.java
new file mode 100644
index 000000000000..883ef9b8a8f8
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/completion/smartType/MethodNoPairBracketComma-out.java
@@ -0,0 +1,8 @@
+class A {
+ void foo(String bar, int a) {}
+ String zoo(int b) {}
+
+ {
+ foo(zoo(), )
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/completion/smartType/MethodNoPairBracketComma.java b/java/java-tests/testData/codeInsight/completion/smartType/MethodNoPairBracketComma.java
new file mode 100644
index 000000000000..ab1e7d370306
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/completion/smartType/MethodNoPairBracketComma.java
@@ -0,0 +1,8 @@
+class A {
+ void foo(String bar, int a) {}
+ String zoo(int b) {}
+
+ {
+ foo(zo)
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java
index d00328d0b1b7..156c4d9f8b4f 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java
@@ -477,28 +477,26 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testSameNamedFieldAndLocal() throws Throwable { doTest(); }
- public void testNoTailWhenNoPairBracket() throws Throwable {
- doTestNoPairBracket();
- }
+ public void testNoTailWhenNoPairBracket() throws Throwable { doTestNoPairBracket(Lookup.NORMAL_SELECT_CHAR); }
- public void testNoTailWhenNoPairBracket2() throws Throwable {
- doTestNoPairBracket();
- }
+ public void testNoTailWhenNoPairBracket2() throws Throwable { doTestNoPairBracket(Lookup.NORMAL_SELECT_CHAR); }
- private void doTestNoPairBracket() throws Exception {
+ private void doTestNoPairBracket(final char c) throws Exception {
boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET;
CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false;
try {
- doTest();
+ doTest(c);
}
finally {
CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old;
}
}
- public void testNoConstructorTailWhenNoPairBracket() throws Throwable {
- doTestNoPairBracket();
- }
+ public void testNoConstructorTailWhenNoPairBracket() throws Throwable { doTestNoPairBracket(Lookup.NORMAL_SELECT_CHAR); }
+
+ public void testConstructorNoPairBracketSemicolon() throws Throwable { doTestNoPairBracket(';'); }
+
+ public void testMethodNoPairBracketComma() throws Throwable { doTestNoPairBracket(','); }
public void testAbstractClassTwice() throws Throwable {
configureByTestName();
diff --git a/java/openapi/src/com/intellij/psi/PsiElementFactory.java b/java/openapi/src/com/intellij/psi/PsiElementFactory.java
index 0ac50882572e..d74a242b882b 100644
--- a/java/openapi/src/com/intellij/psi/PsiElementFactory.java
+++ b/java/openapi/src/com/intellij/psi/PsiElementFactory.java
@@ -58,8 +58,7 @@ public interface PsiElementFactory extends PsiJavaParserFacade {
* @return the created enum instance.
* @throws IncorrectOperationException if name is not a valid Java identifier.
*/
-
- PsiClass createEnum(@NotNull @NonNls String name) throws IncorrectOperationException;
+ @NotNull PsiClass createEnum(@NotNull @NonNls String name) throws IncorrectOperationException;
/**
* Creates a field with the specified name and type.
@@ -158,7 +157,7 @@ public interface PsiElementFactory extends PsiJavaParserFacade {
*
* @param type the type to detach.
* @return the detached type.
- * @deprecated Optimization method, do not use if you do not understand what it does.
+ * @deprecated does nothing (remove in IDEA 11)
*/
@NotNull PsiType detachType(@NotNull PsiType type);
@@ -189,9 +188,10 @@ public interface PsiElementFactory extends PsiJavaParserFacade {
@Nullable PsiPrimitiveType createPrimitiveType(@NotNull String text);
/**
- * The same as {@link #createTypeByFQClassName(String, GlobalSearchScope)} with {@link GlobalSearchScope#allScope()}
+ * The same as {@link #createTypeByFQClassName(String, GlobalSearchScope)}
+ * with {@link GlobalSearchScope#allScope(com.intellij.openapi.project.Project)}.
*
- * @param qName the full-qualified name of the class to create the reference to.
+ * @param qName the full-qualified name of the class to create the reference to.
* @return the class type instance.
*/
@NotNull PsiClassType createTypeByFQClassName(@NotNull @NonNls String qName);
@@ -419,6 +419,7 @@ public interface PsiElementFactory extends PsiJavaParserFacade {
/**
* Returns a synthetic Java class containing methods which are defined on Java arrays.
*
+ * @param languageLevel language level used to construct array class.
* @return the array synthetic class.
*/
@NotNull PsiClass getArrayClass(@NotNull LanguageLevel languageLevel);
@@ -428,7 +429,7 @@ public interface PsiElementFactory extends PsiJavaParserFacade {
* are defined on Java arrays with the specified element type.
*
* @param componentType the component type of the array for which the class type is returned.
- * @param languageLevel
+ * @param languageLevel language level used to construct array class.
* @return the class type the array synthetic class.
*/
@NotNull PsiClassType getArrayClassType(@NotNull PsiType componentType, @NotNull final LanguageLevel languageLevel);
diff --git a/java/openapi/src/com/intellij/psi/PsiJavaParserFacade.java b/java/openapi/src/com/intellij/psi/PsiJavaParserFacade.java
index a52c7e26dc0f..676de126bfba 100644
--- a/java/openapi/src/com/intellij/psi/PsiJavaParserFacade.java
+++ b/java/openapi/src/com/intellij/psi/PsiJavaParserFacade.java
@@ -14,9 +14,6 @@
* limitations under the License.
*/
-/*
- * @author max
- */
package com.intellij.psi;
import com.intellij.pom.java.LanguageLevel;
@@ -26,28 +23,41 @@ import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
+/*
+ * @author max
+ */
public interface PsiJavaParserFacade extends PsiParserFacade {
/**
* Creates a JavaDoc tag from the specified text.
*
* @param docTagText the text of the JavaDoc tag.
- * @param context ignored; no longer used
* @return the created tag.
* @throws com.intellij.util.IncorrectOperationException if the text of the tag is not valid.
*/
@NotNull
- PsiDocTag createDocTagFromText(@NotNull String docTagText, @Deprecated PsiElement context) throws IncorrectOperationException;
+ PsiDocTag createDocTagFromText(@NotNull String docTagText) throws IncorrectOperationException;
+
+ /**
+ * @deprecated use {@link #createDocTagFromText(String)} (to remove in IDEA 11)
+ */
+ @NotNull
+ PsiDocTag createDocTagFromText(@NotNull String docTagText, PsiElement context) throws IncorrectOperationException;
/**
* Creates a JavaDoc comment from the specified text.
*
* @param docCommentText the text of the JavaDoc comment.
- * @param context ignored; no longer used
* @return the created comment.
* @throws com.intellij.util.IncorrectOperationException if the text of the comment is not valid.
*/
@NotNull
- PsiDocComment createDocCommentFromText(@NotNull String docCommentText, @Deprecated PsiElement context) throws IncorrectOperationException;
+ PsiDocComment createDocCommentFromText(@NotNull String docCommentText) throws IncorrectOperationException;
+
+ /**
+ * @deprecated use {@link #createDocCommentFromText(String)} (to remove in IDEA 11)
+ */
+ @NotNull
+ PsiDocComment createDocCommentFromText(@NotNull String docCommentText, PsiElement context) throws IncorrectOperationException;
/**
* Creates a Java class from the specified text.
@@ -110,7 +120,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* Creates a Java type from the specified text.
*
* @param text the text of the type to create (for example, a primitive type keyword, an array
- * declaration or the name of a class)
+ * declaration or the name of a class).
* @param context the PSI element used as context for resolving the reference.
* @return the created type instance.
* @throws com.intellij.util.IncorrectOperationException if the text does not specify a valid type.
@@ -193,7 +203,7 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
* type and name.
*
* @param exceptionType the type of the exception to catch.
- * @param exceptionName the name of the variable in which the caught exception is stored (may be an empty string)
+ * @param exceptionName the name of the variable in which the caught exception is stored (may be an empty string).
* @param context the context for resolving references.
* @return the created catch section instance.
* @throws IncorrectOperationException if some of the parameters are not valid.
@@ -201,5 +211,13 @@ public interface PsiJavaParserFacade extends PsiParserFacade {
@NotNull PsiCatchSection createCatchSection(@NotNull PsiClassType exceptionType, @NotNull String exceptionName, PsiElement context)
throws IncorrectOperationException;
- PsiType createPrimitiveType(@NotNull String text, @NotNull PsiAnnotation[] annotations);
+ /**
+ * Creates a Java type from the specified text.
+ *
+ * @param text the text of the type to create (a primitive type keyword).
+ * @param annotations array (possible empty) of annotations to annotate the created type.
+ * @return the created type instance.
+ * @throws IncorrectOperationException if some of the parameters are not valid.
+ */
+ PsiType createPrimitiveType(@NotNull String text, @NotNull PsiAnnotation[] annotations) throws IncorrectOperationException;
}
diff --git a/java/openapi/src/com/intellij/psi/PsiType.java b/java/openapi/src/com/intellij/psi/PsiType.java
index 7d62a6f7ca91..5c70c8a21576 100644
--- a/java/openapi/src/com/intellij/psi/PsiType.java
+++ b/java/openapi/src/com/intellij/psi/PsiType.java
@@ -27,16 +27,17 @@ import org.jetbrains.annotations.Nullable;
* Representation of Java type (primitive type, array or class type).
*/
public abstract class PsiType implements PsiAnnotationOwner {
- public static final PsiType BYTE = new PsiPrimitiveType("byte", "java.lang.Byte");
- public static final PsiType CHAR = new PsiPrimitiveType("char", "java.lang.Character");
- public static final PsiType DOUBLE = new PsiPrimitiveType("double", "java.lang.Double");
- public static final PsiType FLOAT = new PsiPrimitiveType("float", "java.lang.Float");
- public static final PsiType INT = new PsiPrimitiveType("int", "java.lang.Integer");
- public static final PsiType LONG = new PsiPrimitiveType("long", "java.lang.Long");
- public static final PsiType SHORT = new PsiPrimitiveType("short", "java.lang.Short");
- public static final PsiType BOOLEAN = new PsiPrimitiveType("boolean", "java.lang.Boolean");
- public static final PsiType VOID = new PsiPrimitiveType("void", "java.lang.Void");
- public static final PsiType NULL = new PsiPrimitiveType("null", (String)null);
+ public static final PsiPrimitiveType BYTE = new PsiPrimitiveType("byte", "java.lang.Byte");
+ public static final PsiPrimitiveType CHAR = new PsiPrimitiveType("char", "java.lang.Character");
+ public static final PsiPrimitiveType DOUBLE = new PsiPrimitiveType("double", "java.lang.Double");
+ public static final PsiPrimitiveType FLOAT = new PsiPrimitiveType("float", "java.lang.Float");
+ public static final PsiPrimitiveType INT = new PsiPrimitiveType("int", "java.lang.Integer");
+ public static final PsiPrimitiveType LONG = new PsiPrimitiveType("long", "java.lang.Long");
+ public static final PsiPrimitiveType SHORT = new PsiPrimitiveType("short", "java.lang.Short");
+ public static final PsiPrimitiveType BOOLEAN = new PsiPrimitiveType("boolean", "java.lang.Boolean");
+ public static final PsiPrimitiveType VOID = new PsiPrimitiveType("void", "java.lang.Void");
+ public static final PsiPrimitiveType NULL = new PsiPrimitiveType("null", (String)null);
+
public static final PsiType[] EMPTY_ARRAY = new PsiType[0];
private final PsiAnnotation[] myAnnotations;
diff --git a/java/openapi/src/com/intellij/util/xml/DomJavaUtil.java b/java/openapi/src/com/intellij/util/xml/DomJavaUtil.java
index 47171693c07d..c21fd2278d4f 100644
--- a/java/openapi/src/com/intellij/util/xml/DomJavaUtil.java
+++ b/java/openapi/src/com/intellij/util/xml/DomJavaUtil.java
@@ -41,7 +41,7 @@ public class DomJavaUtil {
if (searchScope == null) {
if (module != null) {
- scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
+ scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
}
else {
scope = file.getResolveScope();
diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java
index 3b45c626de31..e60ee0a4902a 100644
--- a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java
+++ b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.codeInsight.intention.IntentionManager;
import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionToolProvider;
@@ -33,13 +34,19 @@ import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.ex.ToolsImpl;
import com.intellij.ide.startup.StartupManagerEx;
import com.intellij.ide.startup.impl.StartupManagerImpl;
+import com.intellij.lang.ExternalAnnotatorsFilter;
+import com.intellij.lang.LanguageAnnotators;
+import com.intellij.lang.StdLanguages;
import com.intellij.lang.annotation.HighlightSeverity;
+import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Result;
+import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.startup.StartupManager;
@@ -57,15 +64,19 @@ import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.*;
import com.intellij.psi.impl.JavaPsiFacadeEx;
+import com.intellij.psi.impl.search.IndexPatternBuilder;
+import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.psi.impl.source.tree.TreeUtil;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.UsageSearchContext;
+import com.intellij.psi.xml.XmlFileNSInfoProvider;
import com.intellij.testFramework.ExpectedHighlightingData;
import com.intellij.testFramework.FileTreeAccessFilter;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
import com.intellij.util.IncorrectOperationException;
+import com.intellij.xml.XmlSchemaProvider;
import gnu.trove.THashMap;
import gnu.trove.TIntArrayList;
import org.jetbrains.annotations.NonNls;
@@ -160,6 +171,21 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
myRunCommandForTest = !annotatedWith(DoNotWrapInCommand.class);
+
+ if (isPerformanceTest()) {
+ IntentionManager.getInstance().getAvailableIntentionActions(); // hack to avoid slowdowns in PyExtensionFactory
+ PathManagerEx.getTestDataPath(); // to cache stuff
+ ReferenceProvidersRegistry.getInstance(getProject()); // preload tons of classes
+ InjectedLanguageManager.getInstance(getProject()); // zillion of Dom Sem classes
+ LanguageAnnotators.INSTANCE.allForLanguage(StdLanguages.JAVA); // pile of annotator classes loads
+ LanguageAnnotators.INSTANCE.allForLanguage(StdLanguages.XML);
+ ProblemHighlightFilter.EP_NAME.getExtensions();
+ Extensions.getExtensions(ImplicitUsageProvider.EP_NAME);
+ Extensions.getExtensions(XmlSchemaProvider.EP_NAME);
+ Extensions.getExtensions(XmlFileNSInfoProvider.EP_NAME);
+ Extensions.getExtensions(ExternalAnnotatorsFilter.EXTENSION_POINT_NAME);
+ Extensions.getExtensions(IndexPatternBuilder.EP_NAME);
+ }
}
@Override
diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementBuilder.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementBuilder.java
index f49c58ced67c..14fa3f686dc3 100644
--- a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementBuilder.java
+++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementBuilder.java
@@ -235,6 +235,11 @@ public class LookupElementBuilder extends LookupElement {
return true;
}
+ @Override
+ public String toString() {
+ return "LookupElementBuilder: string=" + getLookupString() + "; handler=" + myInsertHandler;
+ }
+
@Override
public int hashCode() {
int result = 0;
diff --git a/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadAssistant.java b/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadAssistant.java
index 5d1676e0e255..61340ad030c0 100644
--- a/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadAssistant.java
+++ b/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadAssistant.java
@@ -11,6 +11,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
+import com.intellij.util.net.HttpConfigurable;
import com.intellij.util.xmlb.XmlSerializationException;
import com.intellij.util.xmlb.XmlSerializer;
import org.jetbrains.annotations.NotNull;
@@ -46,11 +47,17 @@ public class LibrariesDownloadAssistant {
final String serviceUrl = LibrariesDownloadConnectionService.getInstance().getServiceUrl();
if (StringUtil.isNotEmpty(serviceUrl)) {
try {
- return new URL(serviceUrl + "/" + id + "/");
+ final String url = serviceUrl + "/" + id + "/";
+ HttpConfigurable.getInstance().prepareURL(url);
+
+ return new URL(url);
}
catch (MalformedURLException e) {
LOG.error(e);
}
+ catch (IOException e) {
+ LOG.error(e);
+ }
}
return null;
diff --git a/platform/lang-api/src/com/intellij/facet/frameworks/ui/LibrariesDownloadUiUtil.java b/platform/lang-api/src/com/intellij/facet/frameworks/ui/LibrariesDownloadUiUtil.java
new file mode 100644
index 000000000000..1dc9652b80d3
--- /dev/null
+++ b/platform/lang-api/src/com/intellij/facet/frameworks/ui/LibrariesDownloadUiUtil.java
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+package com.intellij.facet.frameworks.ui;
+
+import com.intellij.facet.frameworks.LibrariesDownloadAssistant;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ModalityState;
+import com.intellij.ui.CollectionComboBoxModel;
+import com.intellij.util.ui.update.Activatable;
+import com.intellij.util.ui.update.UiNotifyConnector;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class LibrariesDownloadUiUtil {
+
+ private LibrariesDownloadUiUtil() {
+ }
+
+ public static JComboBox createVersionsCombobox(@NotNull final String groupId, final URL... localUrls) {
+ final JComboBox jComboBox = new JComboBox();
+
+ initAsyncComboBoxModel(jComboBox, groupId, localUrls);
+
+ return jComboBox;
+ }
+
+ public static void initAsyncComboBoxModel(@NotNull final JComboBox jComboBox,
+ @NotNull final String groupId,
+ final URL... localUrls) {
+ final List