diff options
author | Tor Norbye <tnorbye@google.com> | 2013-06-07 11:05:24 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-06-07 11:05:24 -0700 |
commit | 28d9ee094b1d352884aaf5b66b85b30335165c03 (patch) | |
tree | 0d244ca64930b7b7cb92b260747c6e6d4616fe9c /java/java-impl | |
parent | ec3fb1e06285c0467a7a20360ca80453bc7635d4 (diff) | |
download | idea-28d9ee094b1d352884aaf5b66b85b30335165c03.tar.gz |
Snapshot 621d3b6adc5a7cb6f13e27610aa33af48f13da27 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I3e2f8acd6054389626ab7c0f9065c8d905e99436
Diffstat (limited to 'java/java-impl')
69 files changed, 1825 insertions, 372 deletions
diff --git a/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsManagerImpl.java b/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsManagerImpl.java index c4c156c6d963..c3f9778677cc 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsManagerImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsManagerImpl.java @@ -80,9 +80,8 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.io.IOException; -import java.util.ArrayList; +import java.util.*; import java.util.List; -import java.util.Set; /** * @author anna @@ -397,30 +396,40 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM } final String externalName = getExternalName(listOwner, false); final String oldExternalName = getNormalizedExternalName(listOwner); - for (final XmlTag tag : rootTag.getSubTags()) { - final String className = StringUtil.unescapeXml(tag.getAttributeValue("name")); + + final List<XmlTag> tagsToProcess = new ArrayList<XmlTag>(); + for (XmlTag tag : rootTag.getSubTags()) { + String className = StringUtil.unescapeXml(tag.getAttributeValue("name")); if (!Comparing.strEqual(className, externalName) && !Comparing.strEqual(className, oldExternalName)) { continue; } - for (final XmlTag annotationTag : tag.getSubTags()) { + for (XmlTag annotationTag : tag.getSubTags()) { if (!Comparing.strEqual(annotationTag.getAttributeValue("name"), annotationFQN)) { continue; } - CommandProcessor.getInstance().executeCommand(myPsiManager.getProject(), new Runnable() { - @Override - public void run() { - try { - annotationTagProcessor.process(annotationTag); - commitChanges(file); - } - catch (IncorrectOperationException e) { - LOG.error(e); - } - } - }, ExternalAnnotationsManagerImpl.class.getName(), null); + tagsToProcess.add(annotationTag); processedAnything = true; } } + if (tagsToProcess.isEmpty()) { + continue; + } + + CommandProcessor.getInstance().executeCommand(myPsiManager.getProject(), new Runnable() { + @Override + public void run() { + PsiDocumentManager.getInstance(myPsiManager.getProject()).commitAllDocuments(); + try { + for (XmlTag annotationTag : tagsToProcess) { + annotationTagProcessor.process(annotationTag); + } + commitChanges(file); + } + catch (IncorrectOperationException e) { + LOG.error(e); + } + } + }, ExternalAnnotationsManagerImpl.class.getName(), null); } notifyAfterAnnotationChanging(listOwner, annotationFQN, processedAnything); return processedAnything; @@ -576,7 +585,43 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM }, ExternalAnnotationsManagerImpl.class.getName(), null); } + private static void sortItems(@NotNull XmlFile xmlFile) { + XmlDocument document = xmlFile.getDocument(); + if (document == null) { + return; + } + XmlTag rootTag = document.getRootTag(); + if (rootTag == null) { + return; + } + + List<XmlTag> itemTags = new ArrayList<XmlTag>(); + for (XmlTag item : rootTag.getSubTags()) { + if (item.getAttributeValue("name") != null) { + itemTags.add(item); + } + else { + item.delete(); + } + } + + Collections.sort(itemTags, new Comparator<XmlTag>() { + @Override + public int compare(XmlTag item1, XmlTag item2) { + String externalName1 = item1.getAttributeValue("name"); + String externalName2 = item2.getAttributeValue("name"); + assert externalName1 != null && externalName2 != null; // null names were not added + return externalName1.compareTo(externalName2); + } + }); + for (XmlTag item : itemTags) { + rootTag.addAfter(item, null); + item.delete(); + } + } + private void commitChanges(XmlFile xmlFile) { + sortItems(xmlFile); Document doc = PsiDocumentManager.getInstance(myPsiManager.getProject()).getDocument(xmlFile); assert doc != null; FileDocumentManager.getInstance().saveDocument(doc); diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java index b98ad7ab4833..083649aeb1a6 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java @@ -381,7 +381,10 @@ public class JavaCompletionContributor extends CompletionContributor { static boolean isClassNamePossible(CompletionParameters parameters) { boolean isSecondCompletion = parameters.getInvocationCount() >= 2; - final PsiElement parent = parameters.getPosition().getParent(); + PsiElement position = parameters.getPosition(); + if (JavaCompletionData.isInstanceofPlace(position)) return false; + + final PsiElement parent = position.getParent(); if (!(parent instanceof PsiJavaCodeReferenceElement)) return isSecondCompletion; if (((PsiJavaCodeReferenceElement)parent).getQualifier() != null) return isSecondCompletion; @@ -406,7 +409,7 @@ public class JavaCompletionContributor extends CompletionContributor { return false; } - if (JavaCompletionData.isAfterPrimitiveOrArrayType(parameters.getPosition())) { + if (JavaCompletionData.isAfterPrimitiveOrArrayType(position)) { return false; } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java index 390ba94dd028..ba8486b69c2a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java @@ -531,8 +531,19 @@ public class JavaCompletionData extends JavaAwareCompletionData { PsiElement prev = PsiTreeUtil.prevVisibleLeaf(position); if (prev == null) return false; - PsiExpression expr = PsiTreeUtil.getParentOfType(prev, PsiExpression.class); - return expr != null && expr.getTextRange().getEndOffset() == prev.getTextRange().getEndOffset(); + PsiElement expr = PsiTreeUtil.getParentOfType(prev, PsiExpression.class); + if (expr != null && expr.getTextRange().getEndOffset() == prev.getTextRange().getEndOffset()) { + return true; + } + + if (position instanceof PsiIdentifier && position.getParent() instanceof PsiLocalVariable) { + PsiType type = ((PsiLocalVariable)position.getParent()).getType(); + if (type instanceof PsiClassType && ((PsiClassType)type).resolve() == null) { + return true; + } + } + + return false; } public static boolean isSuitableForClass(PsiElement position) { diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaNameIdentifierConfidence.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaNameIdentifierConfidence.java deleted file mode 100644 index 08b40b726df4..000000000000 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaNameIdentifierConfidence.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInsight.completion; - -import com.intellij.codeInsight.CodeInsightSettings; -import com.intellij.lang.java.JavaLanguage; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiMember; -import com.intellij.psi.PsiNameIdentifierOwner; -import com.intellij.psi.PsiVariable; -import com.intellij.util.ThreeState; -import org.jetbrains.annotations.NotNull; - -/** - * @author peter - */ -public class JavaNameIdentifierConfidence extends CompletionConfidence { - @NotNull - @Override - public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) { - if (CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS) { - return ThreeState.UNSURE; - } - - final PsiElement position = parameters.getPosition(); - final PsiElement parent = position.getParent(); - if (parent instanceof PsiVariable || parent instanceof PsiMember) { - final PsiElement nameIdentifier = ((PsiNameIdentifierOwner)parent).getNameIdentifier(); - if (parent.getLanguage().isKindOf(JavaLanguage.INSTANCE) && nameIdentifier == position) { - return ThreeState.YES; - } - } - return ThreeState.UNSURE; - } - -} diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaNoVariantsDelegator.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaNoVariantsDelegator.java index cbfde6328f9c..e099338792e3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaNoVariantsDelegator.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaNoVariantsDelegator.java @@ -54,7 +54,8 @@ public class JavaNoVariantsDelegator extends CompletionContributor { } else if (Registry.is("ide.completion.show.all.classes") || Registry.is("ide.completion.show.better.matching.classes")) { if (parameters.getInvocationCount() <= 1 && JavaCompletionContributor.mayStartClassName(result) && - JavaCompletionContributor.isClassNamePossible(parameters)) { + JavaCompletionContributor.isClassNamePossible(parameters) && + !JavaSmartCompletionContributor.AFTER_NEW.accepts(parameters.getPosition())) { if (Registry.is("ide.completion.show.better.matching.classes")) { result = result.withPrefixMatcher(new BetterPrefixMatcher(result.getPrefixMatcher(), BetterPrefixMatcher.getBestMatchingDegree(plainResults))); } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/scope/JavaCompletionProcessor.java b/java/java-impl/src/com/intellij/codeInsight/completion/scope/JavaCompletionProcessor.java index ae1ae2042be0..16fad58d214a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/scope/JavaCompletionProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/scope/JavaCompletionProcessor.java @@ -52,6 +52,7 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme private PsiElement myDeclarationHolder = null; private final Set<Object> myResultNames = new THashSet<Object>(); private final List<CompletionElement> myResults = new ArrayList<CompletionElement>(); + private final List<CompletionElement> myFilteredResults = new ArrayList<CompletionElement>(); private final PsiElement myElement; private final PsiElement myScope; private final ElementFilter myFilter; @@ -200,10 +201,6 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme return true; } - if (!(myElement.getParent() instanceof PsiMethodReferenceExpression) && !isStaticsOk(element)) { - return true; - } - if (element instanceof PsiPackage && myScope instanceof PsiClass && !isQualifiedContext()) { return true; } @@ -211,7 +208,10 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme if (satisfies(element, state) && isAccessible(element)) { CompletionElement element1 = new CompletionElement(element, state.get(PsiSubstitutor.KEY)); if (myResultNames.add(element1.getUniqueId())) { - myResults.add(element1); + StaticProblem sp = myElement.getParent() instanceof PsiMethodReferenceExpression ? StaticProblem.none : getStaticProblem(element); + if (sp != StaticProblem.instanceAfterStatic) { + (sp == StaticProblem.staticAfterInstance ? myFilteredResults : myResults).add(element1); + } } } return true; @@ -222,16 +222,16 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme return elementParent instanceof PsiQualifiedReference && ((PsiQualifiedReference)elementParent).getQualifier() != null; } - private boolean isStaticsOk(PsiElement element) { + private StaticProblem getStaticProblem(PsiElement element) { if (myOptions.showInstanceInStaticContext && !isQualifiedContext()) { - return true; + return StaticProblem.none; } if (element instanceof PsiModifierListOwner) { PsiModifierListOwner modifierListOwner = (PsiModifierListOwner)element; if (myStatic) { if (!(element instanceof PsiClass) && !modifierListOwner.hasModifierProperty(PsiModifier.STATIC)) { // we don't need non static method in static context. - return false; + return StaticProblem.instanceAfterStatic; } } else { @@ -239,11 +239,11 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme && modifierListOwner.hasModifierProperty(PsiModifier.STATIC) && !myMembersFlag) { // according settings we don't need to process such fields/methods - return false; + return StaticProblem.staticAfterInstance; } } } - return true; + return StaticProblem.none; } public boolean satisfies(@NotNull PsiElement element, @NotNull ResolveState state) { @@ -275,12 +275,16 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme } } - public Iterable<CompletionElement> getResults(){ + public Iterable<CompletionElement> getResults() { + if (myResults.isEmpty()) { + return myFilteredResults; + } return myResults; } public void clear() { myResults.clear(); + myFilteredResults.clear(); } @Override @@ -350,4 +354,6 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme return new Options(checkAccess, checkInitialized, filterStaticAfterInstance, showInstanceInStaticContext); } } + + private enum StaticProblem { none, staticAfterInstance, instanceAfterStatic } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index 5ee1703fcb31..1d74a2f3dcf4 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -350,6 +350,7 @@ public class GenericsHighlightUtil { return false; } } + if (psiClass instanceof PsiTypeParameter && psiClass.getExtendsListTypes().length != 0) return false; } if (!type.isRaw()) return true; //allow unchecked conversions in method calls but not in type declaration @@ -1261,5 +1262,49 @@ public class GenericsHighlightUtil { } return null; } + + public static HighlightInfo checkCannotPassInner(PsiJavaCodeReferenceElement ref) { + if (ref.getParent() instanceof PsiTypeElement) { + final PsiClass psiClass = PsiTreeUtil.getParentOfType(ref, PsiClass.class); + if (psiClass != null) { + if (PsiTreeUtil.isAncestor(psiClass.getExtendsList(), ref, false) || + PsiTreeUtil.isAncestor(psiClass.getImplementsList(), ref, false)) { + final PsiElement qualifier = ref.getQualifier(); + if (qualifier instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement)qualifier).resolve() == psiClass) { + final PsiElement resolve = ref.resolve(); + if (resolve instanceof PsiClass) { + final PsiClass containingClass = ((PsiClass)resolve).getContainingClass(); + if (containingClass != null) { + if (psiClass.isInheritor(containingClass, true) || + unqualifiedNestedClassReferenceAccessedViaContainingClassInheritance(containingClass, ((PsiClass)resolve).getExtendsList()) || + unqualifiedNestedClassReferenceAccessedViaContainingClassInheritance(containingClass, ((PsiClass)resolve).getImplementsList())) { + return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).descriptionAndTooltip(((PsiClass)resolve).getName() + " is not accessible in current context").range(ref).create(); + } + } + } + } + } + } + } + return null; + } + + private static boolean unqualifiedNestedClassReferenceAccessedViaContainingClassInheritance(PsiClass containingClass, + PsiReferenceList referenceList) { + if (referenceList != null) { + for (PsiJavaCodeReferenceElement referenceElement : referenceList.getReferenceElements()) { + if (!referenceElement.isQualified()) { + final PsiElement superClass = referenceElement.resolve(); + if (superClass instanceof PsiClass) { + final PsiClass superContainingClass = ((PsiClass)superClass).getContainingClass(); + if (superContainingClass != null && containingClass.isInheritor(superContainingClass, true)) { + return true; + } + } + } + } + } + return false; + } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java index 40e1f5779d75..4f6f0996ad29 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java @@ -835,7 +835,7 @@ public class HighlightClassUtil { } if (place instanceof PsiModifierListOwner) { final PsiModifierList modifierList = ((PsiModifierListOwner)place).getModifierList(); - if (modifierList != null && modifierList.hasExplicitModifier(PsiModifier.STATIC)) { + if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.STATIC)) { return false; } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 1f92c4226261..1c0e2ecf342b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -929,6 +929,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkSelectStaticClassFromParameterizedType(resolved, ref)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkParameterizedReferenceTypeArguments(resolved, ref, result.getSubstitutor())); + if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkCannotPassInner(ref)); if (resolved != null && parent instanceof PsiReferenceList) { if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkElementInReferenceList(ref, (PsiReferenceList)parent, result)); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ExtendsListFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ExtendsListFix.java index 77eaa6a575a2..0b987facaea6 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ExtendsListFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ExtendsListFix.java @@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -51,7 +52,7 @@ public class ExtendsListFix extends LocalQuickFixAndIntentionActionOnPsiElement super(aClass); myClassToExtendFrom = classToExtendFrom; myToAdd = toAdd; - myTypeToExtendFrom = typeToExtendFrom; + myTypeToExtendFrom = (PsiClassType)GenericsUtil.eliminateWildcards(typeToExtendFrom); @NonNls final String messageKey; if (classToExtendFrom != null && aClass.isInterface() == classToExtendFrom.isInterface()) { @@ -171,6 +172,6 @@ public class ExtendsListFix extends LocalQuickFixAndIntentionActionOnPsiElement } list = (PsiReferenceList) element.getParent(); } - return list; + return (PsiReferenceList)JavaCodeStyleManager.getInstance(extendsList.getProject()).shortenClassReferences(list); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java index 3e045a31e613..e34ad1820c89 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java @@ -44,12 +44,14 @@ import com.intellij.psi.search.PsiShortNamesCache; import com.intellij.psi.util.InheritanceUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.util.containers.ContainerUtil; +import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -60,9 +62,10 @@ import java.util.regex.PatternSyntaxException; public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiReference> implements HintAction, HighPriorityAction { @NotNull private final T myElement; + @NotNull private final R myRef; - protected ImportClassFixBase(@NotNull T elem, R ref) { + protected ImportClassFixBase(@NotNull T elem, @NotNull R ref) { myElement = elem; myRef = ref; } @@ -149,9 +152,33 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe classList = filtered; } + filterAlreadyImportedButUnresolved(classList); return classList; } + private void filterAlreadyImportedButUnresolved(@NotNull List<PsiClass> list) { + PsiElement element = myRef.getElement(); + PsiFile containingFile = element == null ? null : element.getContainingFile(); + if (!(containingFile instanceof PsiJavaFile)) return; + PsiJavaFile javaFile = (PsiJavaFile)containingFile; + PsiImportList importList = javaFile.getImportList(); + PsiImportStatementBase[] importStatements = importList == null ? PsiImportStatementBase.EMPTY_ARRAY : importList.getAllImportStatements(); + Set<String> importedNames = new THashSet<String>(importStatements.length); + for (PsiImportStatementBase statement : importStatements) { + PsiJavaCodeReferenceElement ref = statement.getImportReference(); + String name = ref == null ? null : ref.getReferenceName(); + if (name != null && ref.resolve() == null) importedNames.add(name); + } + + for (int i = list.size() - 1; i >= 0; i--) { + PsiClass aClass = list.get(i); + String className = aClass.getName(); + if (className != null && importedNames.contains(className)) { + list.remove(i); + } + } + } + @Nullable protected String getRequiredMemberName(T reference) { return null; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReplaceInaccessibleFieldWithGetterSetterFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReplaceInaccessibleFieldWithGetterSetterFix.java index 97c7acd38a60..8e0621898dfc 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReplaceInaccessibleFieldWithGetterSetterFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReplaceInaccessibleFieldWithGetterSetterFix.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInsight.daemon.impl.quickfix; +import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement; import com.intellij.openapi.editor.Editor; @@ -44,6 +45,7 @@ public class ReplaceInaccessibleFieldWithGetterSetterFix extends LocalQuickFixAn @NotNull PsiElement startElement, @NotNull PsiElement endElement) { PsiReferenceExpression place = (PsiReferenceExpression)startElement; + if (!FileModificationService.getInstance().preparePsiElementForWrite(place)) return; String qualifier = null; final PsiExpression qualifierExpression = place.getQualifierExpression(); if (qualifierExpression != null) { diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java index 25eec5f4999a..5a8eea42ae5f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java @@ -128,6 +128,7 @@ public class GenerateMembersUtil { */ public static void positionCaret(@NotNull Editor editor, @NotNull PsiElement firstMember, boolean toEditMethodBody) { LOG.assertTrue(firstMember.isValid()); + Project project = firstMember.getProject(); if (toEditMethodBody) { PsiMethod method = (PsiMethod)firstMember; @@ -167,9 +168,9 @@ public class GenerateMembersUtil { } else if (adjustLineIndent) { Document document = editor.getDocument(); RangeMarker marker = document.createRangeMarker(start, start); - PsiDocumentManager.getInstance(body.getProject()).doPostponedOperationsAndUnblockDocument(document); + PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document); if (marker.isValid()) { - CodeStyleManager.getInstance(body.getProject()).adjustLineIndent(document, marker.getStartOffset()); + CodeStyleManager.getInstance(project).adjustLineIndent(document, marker.getStartOffset()); } } return; diff --git a/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java b/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java index feeeb5d9be9a..424c5c55ff2c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java @@ -337,7 +337,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc } } } - return result.toArray(new CandidateInfo[result.size()]); + return result.isEmpty() ? candidates : result.toArray(new CandidateInfo[result.size()]); } else { assert call instanceof PsiEnumConstant; diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java index 5f4fb9c081eb..e60743c0ae71 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java @@ -16,6 +16,7 @@ package com.intellij.codeInsight.intention.impl; import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.editor.Editor; @@ -63,6 +64,10 @@ public class SurroundAutoCloseableAction extends PsiElementBaseIntentionAction { @Override public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException { + if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) { + return; + } + final PsiLocalVariable variable = PsiTreeUtil.getParentOfType(element, PsiLocalVariable.class); if (variable == null) return; final PsiExpression initializer = variable.getInitializer(); diff --git a/java/java-impl/src/com/intellij/codeInsight/navigation/JavaGotoSuperHandler.java b/java/java-impl/src/com/intellij/codeInsight/navigation/JavaGotoSuperHandler.java index b23209ae5fd0..94ddb7ae863e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/navigation/JavaGotoSuperHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/navigation/JavaGotoSuperHandler.java @@ -64,15 +64,21 @@ public class JavaGotoSuperHandler implements CodeInsightActionHandler { } @Nullable - private static PsiElement[] findSuperElements(PsiFile file, int offset) { + private PsiElement[] findSuperElements(PsiFile file, int offset) { + PsiNameIdentifierOwner parent = getElement(file, offset); + if (parent == null) return null; + + return FindSuperElementsHelper.findSuperElements(parent); + } + + protected PsiNameIdentifierOwner getElement(PsiFile file, int offset) { PsiElement element = file.findElementAt(offset); if (element == null) return null; PsiNameIdentifierOwner parent = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiClass.class); if (parent == null) return null; - - return FindSuperElementsHelper.findSuperElements(parent); + return parent; } @Override diff --git a/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java b/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java index fe67af7da906..f65d58051522 100644 --- a/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java @@ -83,10 +83,10 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{ } @Override - public void runInspection(final AnalysisScope scope, - final InspectionManager manager, - final GlobalInspectionContext globalContext, - final ProblemDescriptionsProcessor problemDescriptionsProcessor) { + public void runInspection(@NotNull final AnalysisScope scope, + @NotNull final InspectionManager manager, + @NotNull final GlobalInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor problemDescriptionsProcessor) { globalContext.getRefManager().iterate(new RefJavaVisitor() { @Override public void visitClass(@NotNull RefClass refClass) { if (!globalContext.shouldCheck(refClass, RedundantSuppressInspection.this)) return; @@ -110,13 +110,13 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{ } @Nullable - private CommonProblemDescriptor[] checkElement(RefClass refEntity, InspectionManager manager, final Project project) { + private CommonProblemDescriptor[] checkElement(@NotNull RefClass refEntity, @NotNull InspectionManager manager, @NotNull Project project) { final PsiClass psiClass = refEntity.getElement(); if (psiClass == null) return null; return checkElement(psiClass, manager, project); } - public CommonProblemDescriptor[] checkElement(@NotNull final PsiElement psiElement, InspectionManager manager, Project project) { + public CommonProblemDescriptor[] checkElement(@NotNull final PsiElement psiElement, @NotNull InspectionManager manager, @NotNull Project project) { final Map<PsiElement, Collection<String>> suppressedScopes = new THashMap<PsiElement, Collection<String>>(); psiElement.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitModifierList(PsiModifierList list) { @@ -302,7 +302,7 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{ @Override @Nullable - public String getHint(final QuickFix fix) { + public String getHint(@NotNull final QuickFix fix) { if (myQuickFixes != null) { final List<String> list = myQuickFixes.getKeysByValue(fix); if (list != null) { diff --git a/java/java-impl/src/com/intellij/codeInspection/canBeFinal/CanBeFinalAnnotator.java b/java/java-impl/src/com/intellij/codeInspection/canBeFinal/CanBeFinalAnnotator.java index 6f5d3a8f3c9e..3b322ff616ee 100644 --- a/java/java-impl/src/com/intellij/codeInspection/canBeFinal/CanBeFinalAnnotator.java +++ b/java/java-impl/src/com/intellij/codeInspection/canBeFinal/CanBeFinalAnnotator.java @@ -20,6 +20,7 @@ import com.intellij.codeInspection.reference.*; import com.intellij.psi.*; import com.intellij.psi.controlFlow.*; import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; @@ -34,7 +35,7 @@ class CanBeFinalAnnotator extends RefGraphAnnotatorEx { private final RefManager myManager; public static int CAN_BE_FINAL_MASK; - public CanBeFinalAnnotator(RefManager manager) { + public CanBeFinalAnnotator(@NotNull RefManager manager) { myManager = manager; } diff --git a/java/java-impl/src/com/intellij/codeInspection/canBeFinal/CanBeFinalInspection.java b/java/java-impl/src/com/intellij/codeInspection/canBeFinal/CanBeFinalInspection.java index b274e5b138f4..35a997fc3b9c 100644 --- a/java/java-impl/src/com/intellij/codeInspection/canBeFinal/CanBeFinalInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/canBeFinal/CanBeFinalInspection.java @@ -125,18 +125,18 @@ public class CanBeFinalInspection extends GlobalJavaInspectionTool { @Override @Nullable - public RefGraphAnnotator getAnnotator(final RefManager refManager) { + public RefGraphAnnotator getAnnotator(@NotNull final RefManager refManager) { return new CanBeFinalAnnotator(refManager); } @Override @Nullable - public CommonProblemDescriptor[] checkElement(final RefEntity refEntity, - final AnalysisScope scope, - final InspectionManager manager, - final GlobalInspectionContext globalContext, - final ProblemDescriptionsProcessor processor) { + public CommonProblemDescriptor[] checkElement(@NotNull final RefEntity refEntity, + @NotNull final AnalysisScope scope, + @NotNull final InspectionManager manager, + @NotNull final GlobalInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor processor) { if (refEntity instanceof RefJavaElement) { final RefJavaElement refElement = (RefJavaElement)refEntity; if (refElement instanceof RefParameter) return null; @@ -177,8 +177,8 @@ public class CanBeFinalInspection extends GlobalJavaInspectionTool { } @Override - protected boolean queryExternalUsagesRequests(final RefManager manager, final GlobalJavaInspectionContext globalContext, - final ProblemDescriptionsProcessor problemsProcessor) { + protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor problemsProcessor) { for (RefElement entryPoint : globalContext.getEntryPointsManager(manager).getEntryPoints()) { problemsProcessor.ignoreElement(entryPoint); } diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java index 29112c09b1a3..dff5d41fe135 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java @@ -34,7 +34,7 @@ public class DummyEntryPointsTool extends FilteringInspectionTool { private final UnusedDeclarationInspection myOwner; private QuickFixAction[] myQuickFixActions; - public DummyEntryPointsTool(UnusedDeclarationInspection owner) { + public DummyEntryPointsTool(@NotNull UnusedDeclarationInspection owner) { myOwner = owner; } diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/RefUnreachableFilter.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/RefUnreachableFilter.java index b6ca8f42ec67..650e7c527edf 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/RefUnreachableFilter.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/RefUnreachableFilter.java @@ -27,11 +27,12 @@ package com.intellij.codeInspection.deadCode; import com.intellij.codeInspection.ex.InspectionTool; import com.intellij.codeInspection.reference.*; import com.intellij.codeInspection.util.RefFilter; +import org.jetbrains.annotations.NotNull; public class RefUnreachableFilter extends RefFilter { protected InspectionTool myTool; - public RefUnreachableFilter(final InspectionTool tool) { + public RefUnreachableFilter(@NotNull InspectionTool tool) { myTool = tool; } diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnreferencedFilter.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnreferencedFilter.java index b82c6fa0fc29..32dc52252e95 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnreferencedFilter.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnreferencedFilter.java @@ -26,9 +26,10 @@ package com.intellij.codeInspection.deadCode; import com.intellij.codeInspection.ex.InspectionTool; import com.intellij.codeInspection.reference.*; +import org.jetbrains.annotations.NotNull; public class UnreferencedFilter extends RefUnreachableFilter { - public UnreferencedFilter(final InspectionTool tool) { + public UnreferencedFilter(@NotNull InspectionTool tool) { super(tool); } diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java index e4086d5b864a..70f22c0765fc 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java @@ -528,7 +528,7 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { } private static class WeakUnreferencedFilter extends UnreferencedFilter { - private WeakUnreferencedFilter(final InspectionTool tool) { + private WeakUnreferencedFilter(@NotNull InspectionTool tool) { super(tool); } @@ -770,7 +770,8 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { if (descriptor instanceof ProblemDescriptor) { if (DELETE.equals(hint)) { return new PermanentDeleteFix(((ProblemDescriptor)descriptor).getPsiElement()); - } else if (COMMENT.equals(hint)) { + } + if (COMMENT.equals(hint)) { return new CommentOutFix(((ProblemDescriptor)descriptor).getPsiElement()); } } diff --git a/java/java-impl/src/com/intellij/codeInspection/emptyMethod/EmptyMethodInspection.java b/java/java-impl/src/com/intellij/codeInspection/emptyMethod/EmptyMethodInspection.java index 08f1e42e3039..479272842951 100644 --- a/java/java-impl/src/com/intellij/codeInspection/emptyMethod/EmptyMethodInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/emptyMethod/EmptyMethodInspection.java @@ -63,11 +63,11 @@ public class EmptyMethodInspection extends GlobalJavaInspectionTool { @Override @Nullable - public CommonProblemDescriptor[] checkElement(RefEntity refEntity, - AnalysisScope scope, - InspectionManager manager, - GlobalInspectionContext globalContext, - ProblemDescriptionsProcessor processor) { + public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, + @NotNull AnalysisScope scope, + @NotNull InspectionManager manager, + @NotNull GlobalInspectionContext globalContext, + @NotNull ProblemDescriptionsProcessor processor) { if (!(refEntity instanceof RefMethod)) { return null; } @@ -202,8 +202,8 @@ public class EmptyMethodInspection extends GlobalJavaInspectionTool { } @Override - protected boolean queryExternalUsagesRequests(final RefManager manager, final GlobalJavaInspectionContext context, - final ProblemDescriptionsProcessor descriptionsProcessor) { + protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext context, + @NotNull final ProblemDescriptionsProcessor descriptionsProcessor) { manager.iterate(new RefJavaVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { if (refEntity instanceof RefElement && descriptionsProcessor.getDescriptions(refEntity) != null) { @@ -266,7 +266,7 @@ public class EmptyMethodInspection extends GlobalJavaInspectionTool { } @Override - public String getHint(final QuickFix fix) { + public String getHint(@NotNull final QuickFix fix) { final List<Boolean> list = myQuickFixes.getKeysByValue(fix); if (list != null) { LOG.assertTrue(list.size() == 1); diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefClassImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefClassImpl.java index 13020923b013..8c9cda6eb582 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefClassImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefClassImpl.java @@ -265,7 +265,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass { } @Override - public void accept(final RefVisitor visitor) { + public void accept(@NotNull final RefVisitor visitor) { if (visitor instanceof RefJavaVisitor) { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefFieldImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefFieldImpl.java index 7e2bef09d30f..35262e3e725c 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefFieldImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefFieldImpl.java @@ -100,7 +100,7 @@ public class RefFieldImpl extends RefJavaElementImpl implements RefField { } @Override - public void accept(final RefVisitor visitor) { + public void accept(@NotNull final RefVisitor visitor) { if (visitor instanceof RefJavaVisitor) { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefImplicitConstructorImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefImplicitConstructorImpl.java index d47b5a0d0281..5d9bd6c2fa1a 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefImplicitConstructorImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefImplicitConstructorImpl.java @@ -29,6 +29,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.Computable; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiModifierListOwner; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class RefImplicitConstructorImpl extends RefMethodImpl implements RefImplicitConstructor { @@ -47,6 +48,7 @@ public class RefImplicitConstructorImpl extends RefMethodImpl implements RefImpl return ((RefClassImpl)getOwnerClass()).isSuspicious(); } + @NotNull @Override public String getName() { return InspectionsBundle.message("inspection.reference.implicit.constructor.name", getOwnerClass().getName()); diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaElementImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaElementImpl.java index 6b79741b9d98..c0cd71eda18a 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaElementImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaElementImpl.java @@ -48,7 +48,7 @@ public abstract class RefJavaElementImpl extends RefElementImpl implements RefJa private static final int IS_USES_DEPRECATION_MASK = 0x200; private static final int IS_SYNTHETIC_JSP_ELEMENT = 0x400; - protected RefJavaElementImpl(String name, RefJavaElement owner) { + protected RefJavaElementImpl(String name, @NotNull RefJavaElement owner) { super(name, owner); String am = owner.getAccessModifier(); doSetAccessModifier(am); diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java index b8fea07a1847..d094a1896461 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java @@ -35,6 +35,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import gnu.trove.THashMap; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -53,7 +54,7 @@ public class RefJavaManagerImpl extends RefJavaManager { private PsiElementVisitor myProjectIterator; private EntryPointsManager myEntryPointsManager; - public RefJavaManagerImpl(RefManagerImpl manager) { + public RefJavaManagerImpl(@NotNull RefManagerImpl manager) { myRefManager = manager; final Project project = manager.getProject(); final PsiManager psiManager = PsiManager.getInstance(project); @@ -174,7 +175,7 @@ public class RefJavaManagerImpl extends RefJavaManager { @Override - public void iterate(final RefVisitor visitor) { + public void iterate(@NotNull final RefVisitor visitor) { if (myPackages != null) { for (RefPackage refPackage : myPackages.values()) { refPackage.accept(visitor); diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java index e7802173c3e4..bca7bd179d03 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java @@ -68,7 +68,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod { } // To be used only from RefImplicitConstructor. - protected RefMethodImpl(String name, RefClass ownerClass) { + protected RefMethodImpl(String name, @NotNull RefClass ownerClass) { super(name, ownerClass); myOwnerClass = ownerClass; ((RefClassImpl)ownerClass).add(this); @@ -325,7 +325,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod { } @Override - public void accept(final RefVisitor visitor) { + public void accept(@NotNull final RefVisitor visitor) { if (visitor instanceof RefJavaVisitor) { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override @@ -417,6 +417,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod { return (RefClass) getOwner(); } + @NotNull @Override public String getName() { if (isValid()) { diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefPackageImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefPackageImpl.java index 5fb00bf12dc7..32649b924a25 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefPackageImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefPackageImpl.java @@ -26,6 +26,7 @@ package com.intellij.codeInspection.reference; import com.intellij.openapi.application.ApplicationManager; import com.intellij.util.PlatformIcons; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -33,24 +34,25 @@ import javax.swing.*; public class RefPackageImpl extends RefEntityImpl implements RefPackage { private final String myQualifiedName; - public RefPackageImpl(String name, RefManager refManager) { + public RefPackageImpl(@NotNull String name, @NotNull RefManager refManager) { super(getPackageSuffix(name), refManager); myQualifiedName = name; } + @NotNull @Override public String getQualifiedName() { return myQualifiedName; } - private static String getPackageSuffix(String fullName) { + private static String getPackageSuffix(@NotNull String fullName) { int dotIndex = fullName.lastIndexOf('.'); return (dotIndex >= 0) ? fullName.substring(dotIndex + 1) : fullName; } @Override - public void accept(final RefVisitor visitor) { + public void accept(@NotNull final RefVisitor visitor) { if (visitor instanceof RefJavaVisitor) { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java index 403d26db4b79..f33145fa070e 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java @@ -29,6 +29,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.psi.*; import com.intellij.psi.util.PsiFormatUtil; import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class RefParameterImpl extends RefJavaElementImpl implements RefParameter { @@ -83,7 +84,7 @@ public class RefParameterImpl extends RefJavaElementImpl implements RefParameter } @Override - public void accept(final RefVisitor visitor) { + public void accept(@NotNull final RefVisitor visitor) { if (visitor instanceof RefJavaVisitor) { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override diff --git a/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java b/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java index 7e5e07181fd3..59abd75d39a5 100644 --- a/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java @@ -46,8 +46,8 @@ public class SameParameterValueInspection extends GlobalJavaInspectionTool { @Override @Nullable - public CommonProblemDescriptor[] checkElement(RefEntity refEntity, AnalysisScope scope, InspectionManager manager, GlobalInspectionContext globalContext, - ProblemDescriptionsProcessor processor) { + public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext, + @NotNull ProblemDescriptionsProcessor processor) { ArrayList<ProblemDescriptor> problems = null; if (refEntity instanceof RefMethod) { final RefMethod refMethod = (RefMethod)refEntity; @@ -75,8 +75,8 @@ public class SameParameterValueInspection extends GlobalJavaInspectionTool { @Override - protected boolean queryExternalUsagesRequests(final RefManager manager, final GlobalJavaInspectionContext globalContext, - final ProblemDescriptionsProcessor processor) { + protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor processor) { manager.iterate(new RefJavaVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { if (refEntity instanceof RefElement && processor.getDescriptions(refEntity) != null) { @@ -129,7 +129,7 @@ public class SameParameterValueInspection extends GlobalJavaInspectionTool { @Override @Nullable - public String getHint(final QuickFix fix) { + public String getHint(@NotNull final QuickFix fix) { final InlineParameterValueFix valueFix = (InlineParameterValueFix)fix; return valueFix.getParamName() + " " + valueFix.getValue(); } diff --git a/java/java-impl/src/com/intellij/codeInspection/sameReturnValue/SameReturnValueInspection.java b/java/java-impl/src/com/intellij/codeInspection/sameReturnValue/SameReturnValueInspection.java index fd6cf5990a83..7d4c3536b139 100644 --- a/java/java-impl/src/com/intellij/codeInspection/sameReturnValue/SameReturnValueInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/sameReturnValue/SameReturnValueInspection.java @@ -29,8 +29,8 @@ import org.jetbrains.annotations.Nullable; public class SameReturnValueInspection extends GlobalJavaInspectionTool { @Override @Nullable - public CommonProblemDescriptor[] checkElement(RefEntity refEntity, AnalysisScope scope, InspectionManager manager, GlobalInspectionContext globalContext, - ProblemDescriptionsProcessor processor) { + public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext, + @NotNull ProblemDescriptionsProcessor processor) { if (refEntity instanceof RefMethod) { final RefMethod refMethod = (RefMethod)refEntity; @@ -57,8 +57,8 @@ public class SameReturnValueInspection extends GlobalJavaInspectionTool { @Override - protected boolean queryExternalUsagesRequests(final RefManager manager, final GlobalJavaInspectionContext globalContext, - final ProblemDescriptionsProcessor processor) { + protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor processor) { manager.iterate(new RefJavaVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { if (refEntity instanceof RefElement && processor.getDescriptions(refEntity) != null) { diff --git a/java/java-impl/src/com/intellij/codeInspection/ui/EntryPointsNode.java b/java/java-impl/src/com/intellij/codeInspection/ui/EntryPointsNode.java index ddb7cc8813d8..51063602a763 100644 --- a/java/java-impl/src/com/intellij/codeInspection/ui/EntryPointsNode.java +++ b/java/java-impl/src/com/intellij/codeInspection/ui/EntryPointsNode.java @@ -18,6 +18,7 @@ package com.intellij.codeInspection.ui; import com.intellij.codeInspection.deadCode.DummyEntryPointsTool; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.icons.AllIcons; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -25,7 +26,7 @@ import javax.swing.*; * @author max */ public class EntryPointsNode extends InspectionNode { - public EntryPointsNode(UnusedDeclarationInspection tool) { + public EntryPointsNode(@NotNull UnusedDeclarationInspection tool) { super(new DummyEntryPointsTool(tool)); getTool().updateContent(); } diff --git a/java/java-impl/src/com/intellij/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyInspection.java b/java/java-impl/src/com/intellij/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyInspection.java index 049811978cc9..87e99c553b36 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyInspection.java @@ -28,12 +28,12 @@ import java.util.Set; public class UnnecessaryModuleDependencyInspection extends GlobalInspectionTool { @Override - public RefGraphAnnotator getAnnotator(final RefManager refManager) { + public RefGraphAnnotator getAnnotator(@NotNull final RefManager refManager) { return new UnnecessaryModuleDependencyAnnotator(refManager); } @Override - public CommonProblemDescriptor[] checkElement(RefEntity refEntity, AnalysisScope scope, InspectionManager manager, final GlobalInspectionContext globalContext) { + public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull final GlobalInspectionContext globalContext) { if (refEntity instanceof RefModule){ final RefModule refModule = (RefModule)refEntity; final Module module = refModule.getModule(); diff --git a/java/java-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrows.java b/java/java-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrows.java index 7c748affc607..6b3ebe0defdd 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrows.java +++ b/java/java-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrows.java @@ -51,11 +51,11 @@ public class RedundantThrows extends GlobalJavaInspectionTool { @Override @Nullable - public CommonProblemDescriptor[] checkElement(RefEntity refEntity, - AnalysisScope scope, - InspectionManager manager, - GlobalInspectionContext globalContext, - ProblemDescriptionsProcessor processor) { + public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, + @NotNull AnalysisScope scope, + @NotNull InspectionManager manager, + @NotNull GlobalInspectionContext globalContext, + @NotNull ProblemDescriptionsProcessor processor) { if (refEntity instanceof RefMethod) { final RefMethod refMethod = (RefMethod)refEntity; if (refMethod.isSyntheticJSP()) return null; @@ -123,8 +123,8 @@ public class RedundantThrows extends GlobalJavaInspectionTool { @Override - protected boolean queryExternalUsagesRequests(final RefManager manager, final GlobalJavaInspectionContext globalContext, - final ProblemDescriptionsProcessor processor) { + protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor processor) { manager.iterate(new RefJavaVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { if (processor.getDescriptions(refEntity) != null) { @@ -184,7 +184,7 @@ public class RedundantThrows extends GlobalJavaInspectionTool { @Override @Nullable - public String getHint(final QuickFix fix) { + public String getHint(@NotNull final QuickFix fix) { final List<String> hints = myQuickFixes.getKeysByValue(fix); LOG.assertTrue(hints != null && hints.size() == 1); return hints.get(0); diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java b/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java index b26e43fca402..ea832d151cf0 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/unusedParameters/UnusedParametersInspection.java @@ -58,11 +58,11 @@ public class UnusedParametersInspection extends GlobalJavaInspectionTool { @Override @Nullable - public CommonProblemDescriptor[] checkElement(final RefEntity refEntity, - final AnalysisScope scope, - final InspectionManager manager, - final GlobalInspectionContext globalContext, - final ProblemDescriptionsProcessor processor) { + public CommonProblemDescriptor[] checkElement(@NotNull final RefEntity refEntity, + @NotNull final AnalysisScope scope, + @NotNull final InspectionManager manager, + @NotNull final GlobalInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor processor) { if (refEntity instanceof RefMethod) { final RefMethod refMethod = (RefMethod)refEntity; @@ -103,15 +103,15 @@ public class UnusedParametersInspection extends GlobalJavaInspectionTool { } @Override - protected boolean queryExternalUsagesRequests(final RefManager manager, final GlobalJavaInspectionContext globalContext, - final ProblemDescriptionsProcessor processor) { + protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor processor) { final Project project = manager.getProject(); for (RefElement entryPoint : globalContext.getEntryPointsManager(manager).getEntryPoints()) { processor.ignoreElement(entryPoint); } final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(project); - final AnalysisScope scope = manager.getScope(); + final AnalysisScope scope = ((RefManagerImpl)manager).getScope(); manager.iterate(new RefJavaVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { @@ -162,7 +162,7 @@ public class UnusedParametersInspection extends GlobalJavaInspectionTool { @Override @Nullable - public String getHint(final QuickFix fix) { + public String getHint(@NotNull final QuickFix fix) { return ((AcceptSuggested)fix).getHint(); } @@ -173,7 +173,7 @@ public class UnusedParametersInspection extends GlobalJavaInspectionTool { } @Override - public void compose(final StringBuffer buf, final RefEntity refEntity, final HTMLComposer composer) { + public void compose(@NotNull final StringBuffer buf, @NotNull final RefEntity refEntity, @NotNull final HTMLComposer composer) { if (refEntity instanceof RefMethod) { final RefMethod refMethod = (RefMethod)refEntity; final HTMLJavaHTMLComposer javaComposer = composer.getExtension(HTMLJavaHTMLComposer.COMPOSER); diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java b/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java index 31a414d83a31..2bfbdf833c93 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java +++ b/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java @@ -48,11 +48,11 @@ public class UnusedReturnValue extends GlobalJavaInspectionTool{ @Override @Nullable - public CommonProblemDescriptor[] checkElement(RefEntity refEntity, - AnalysisScope scope, - InspectionManager manager, - GlobalInspectionContext globalContext, - ProblemDescriptionsProcessor processor) { + public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, + @NotNull AnalysisScope scope, + @NotNull InspectionManager manager, + @NotNull GlobalInspectionContext globalContext, + @NotNull ProblemDescriptionsProcessor processor) { if (refEntity instanceof RefMethod) { final RefMethod refMethod = (RefMethod)refEntity; @@ -90,8 +90,8 @@ public class UnusedReturnValue extends GlobalJavaInspectionTool{ } @Override - protected boolean queryExternalUsagesRequests(final RefManager manager, final GlobalJavaInspectionContext globalContext, - final ProblemDescriptionsProcessor processor) { + protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor processor) { manager.iterate(new RefJavaVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { if (refEntity instanceof RefElement && processor.getDescriptions(refEntity) != null) { diff --git a/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java b/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java index 65745a9d212f..112c379b712c 100644 --- a/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/visibility/VisibilityInspection.java @@ -143,11 +143,11 @@ public class VisibilityInspection extends GlobalJavaInspectionTool { @Override @Nullable - public CommonProblemDescriptor[] checkElement(final RefEntity refEntity, - final AnalysisScope scope, - final InspectionManager manager, - final GlobalInspectionContext globalContext, - final ProblemDescriptionsProcessor processor) { + public CommonProblemDescriptor[] checkElement(@NotNull final RefEntity refEntity, + @NotNull final AnalysisScope scope, + @NotNull final InspectionManager manager, + @NotNull final GlobalInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor processor) { if (refEntity instanceof RefJavaElement) { final RefJavaElement refElement = (RefJavaElement)refEntity; @@ -403,8 +403,8 @@ public class VisibilityInspection extends GlobalJavaInspectionTool { @Override - protected boolean queryExternalUsagesRequests(final RefManager manager, final GlobalJavaInspectionContext globalContext, - final ProblemDescriptionsProcessor processor) { + protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor processor) { final EntryPointsManager entryPointsManager = globalContext.getEntryPointsManager(manager); for (RefElement entryPoint : entryPointsManager.getEntryPoints()) { ignoreElement(processor, entryPoint); @@ -516,7 +516,7 @@ public class VisibilityInspection extends GlobalJavaInspectionTool { } @Override - public void compose(final StringBuffer buf, final RefEntity refEntity, final HTMLComposer composer) { + public void compose(@NotNull final StringBuffer buf, @NotNull final RefEntity refEntity, @NotNull final HTMLComposer composer) { composer.appendElementInReferences(buf, (RefElement)refEntity); } @@ -528,7 +528,7 @@ public class VisibilityInspection extends GlobalJavaInspectionTool { @Override @Nullable - public String getHint(final QuickFix fix) { + public String getHint(@NotNull final QuickFix fix) { return ((AcceptSuggestedAccess)fix).getHint(); } diff --git a/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java b/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java index c4d13696308f..fd624b1322d2 100644 --- a/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java +++ b/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java @@ -64,8 +64,8 @@ public class JavaFileHighlighter extends SyntaxHighlighterBase { ourMap1.put(StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN, JavaHighlightingColors.INVALID_STRING_ESCAPE); ourMap1.put(JavaTokenType.CHARACTER_LITERAL, JavaHighlightingColors.STRING); - ourMap1.put(JavaTokenType.LPARENTH, JavaHighlightingColors.PARENTHS); - ourMap1.put(JavaTokenType.RPARENTH, JavaHighlightingColors.PARENTHS); + ourMap1.put(JavaTokenType.LPARENTH, JavaHighlightingColors.PARENTHESES); + ourMap1.put(JavaTokenType.RPARENTH, JavaHighlightingColors.PARENTHESES); ourMap1.put(JavaTokenType.LBRACE, JavaHighlightingColors.BRACES); ourMap1.put(JavaTokenType.RBRACE, JavaHighlightingColors.BRACES); @@ -97,7 +97,7 @@ public class JavaFileHighlighter extends SyntaxHighlighterBase { } } - private final LanguageLevel myLanguageLevel; + protected final LanguageLevel myLanguageLevel; public JavaFileHighlighter() { this(LanguageLevel.HIGHEST); diff --git a/java/java-impl/src/com/intellij/ide/highlighter/JavaHighlightingColors.java b/java/java-impl/src/com/intellij/ide/highlighter/JavaHighlightingColors.java index 9d169ed7c0ad..324c0a1257cd 100644 --- a/java/java-impl/src/com/intellij/ide/highlighter/JavaHighlightingColors.java +++ b/java/java-impl/src/com/intellij/ide/highlighter/JavaHighlightingColors.java @@ -23,7 +23,7 @@ import com.intellij.openapi.editor.colors.TextAttributesKey; * * @author Rustam Vishnyakov */ -@SuppressWarnings("deprecation") // Later SyntaxHighlighterColors will be moved here. +@SuppressWarnings("deprecation") public class JavaHighlightingColors { public static final TextAttributesKey LINE_COMMENT = SyntaxHighlighterColors.LINE_COMMENT; public static final TextAttributesKey JAVA_BLOCK_COMMENT = SyntaxHighlighterColors.JAVA_BLOCK_COMMENT; @@ -32,7 +32,7 @@ public class JavaHighlightingColors { public static final TextAttributesKey NUMBER = SyntaxHighlighterColors.NUMBER; public static final TextAttributesKey STRING = SyntaxHighlighterColors.STRING; public static final TextAttributesKey OPERATION_SIGN = SyntaxHighlighterColors.OPERATION_SIGN; - public static final TextAttributesKey PARENTHS = SyntaxHighlighterColors.PARENTHS; + public static final TextAttributesKey PARENTHESES = SyntaxHighlighterColors.PARENTHS; public static final TextAttributesKey BRACKETS = SyntaxHighlighterColors.BRACKETS; public static final TextAttributesKey BRACES = SyntaxHighlighterColors.BRACES; public static final TextAttributesKey COMMA = SyntaxHighlighterColors.COMMA; @@ -42,4 +42,8 @@ public class JavaHighlightingColors { public static final TextAttributesKey DOC_COMMENT_MARKUP = SyntaxHighlighterColors.DOC_COMMENT_MARKUP; public static final TextAttributesKey VALID_STRING_ESCAPE = SyntaxHighlighterColors.VALID_STRING_ESCAPE; public static final TextAttributesKey INVALID_STRING_ESCAPE = SyntaxHighlighterColors.INVALID_STRING_ESCAPE; + + /** @deprecated use {@link #PARENTHESES} (to remove in IDEA 14) */ + @SuppressWarnings("SpellCheckingInspection") + public static final TextAttributesKey PARENTHS = PARENTHESES; } diff --git a/java/java-impl/src/com/intellij/lexer/EscapedJavaLexer.java b/java/java-impl/src/com/intellij/lexer/EscapedJavaLexer.java deleted file mode 100644 index badc086e01c5..000000000000 --- a/java/java-impl/src/com/intellij/lexer/EscapedJavaLexer.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright 2000-2009 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.lexer; - -import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.JavaTokenType; -import com.intellij.psi.tree.IElementType; - -/** - * Used to process scriptlet code in JSP attribute values like this: - * attribute="<%=texts.get(\"Blabla\")%>" - */ -public class EscapedJavaLexer extends LexerBase { - private char mySurroundingQuote; - private final JavaLexer myJavaLexer; - - private CharSequence myBuffer; - private int myBufferEnd; - private int myCurOffset; - private IElementType myTokenType = null; - private int myTokenEnd; - - public EscapedJavaLexer(char surroundingQuote, LanguageLevel languageLevel) { - mySurroundingQuote = surroundingQuote; - myJavaLexer = new JavaLexer(languageLevel); - } - - public char getSurroundingQuote() { - return mySurroundingQuote; - } - - public void setSurroundingQuote(char surroundingQuote) { - mySurroundingQuote = surroundingQuote; - } - - public void start(CharSequence buffer, int startOffset, int endOffset, int state) { - myBuffer = buffer; - myCurOffset = startOffset; - myTokenEnd = startOffset; - myBufferEnd = endOffset; - myTokenType = null; - } - - public CharSequence getBufferSequence() { - return myBuffer; - } - - public int getState() { - return 0; - } - - public IElementType getTokenType() { - locateToken(); - return myTokenType; - } - - public final int getTokenStart(){ - locateToken(); - return myCurOffset; - } - - public final int getTokenEnd(){ - locateToken(); - return myTokenEnd; - } - - public final void advance(){ - locateToken(); - myTokenType = null; - myCurOffset = myTokenEnd; - } - - public final int getBufferEnd(){ - return myBufferEnd; - } - - private void locateToken() { - if (myTokenType != null) return; - if (myCurOffset >= myBufferEnd) return; - - boolean esc = false; - int offset = myCurOffset; - int state = 0; // 0 -- start/end - // 1 -- inside string - // 2 -- after escape (/) in string literal - - char literalStarter = 0; - do { - if (offset >= myBufferEnd) break; - - char c = myBuffer.charAt(offset); - boolean wasEsc = esc; - esc = false; - if (c == '\\') { - if (!wasEsc) { - esc = true; - } - else { - state = 2; - } - } - else if (state == 0) { - if (c == '\'' || c == '\"') { - literalStarter = c; - state = 1; - } - } - else if (state == 1) { - if (c == literalStarter) { - state = 0; - offset++; - break; - } - } - else if (state == 2) { - state = 1; - } - - if (!esc && state == 0) { - break; - } - - offset++; - } - while (true); - - if(offset >= myBufferEnd - 1) state = 0; - switch (state){ - case 0: - if(offset == myCurOffset){ - myJavaLexer.start(myBuffer, myCurOffset, myBufferEnd); - myTokenType = myJavaLexer.getTokenType(); - myTokenEnd = myJavaLexer.getTokenEnd(); - } - else { - myTokenType = literalStarter == '\"' ? JavaTokenType.STRING_LITERAL : JavaTokenType.CHARACTER_LITERAL; - myTokenEnd = offset; - } - break; - - case 1: - myTokenType = literalStarter == '\"' ? JavaTokenType.STRING_LITERAL : JavaTokenType.CHARACTER_LITERAL; - myTokenEnd = offset; - break; - - default: - myTokenType = JavaTokenType.BAD_CHARACTER; - myTokenEnd = offset; - break; - } - } -} diff --git a/java/java-impl/src/com/intellij/lexer/JavaHighlightingLexer.java b/java/java-impl/src/com/intellij/lexer/JavaHighlightingLexer.java index 316420c953fd..c058e576a479 100644 --- a/java/java-impl/src/com/intellij/lexer/JavaHighlightingLexer.java +++ b/java/java-impl/src/com/intellij/lexer/JavaHighlightingLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +15,26 @@ */ package com.intellij.lexer; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.JavaDocTokenType; import com.intellij.psi.JavaTokenType; import com.intellij.psi.impl.source.tree.JavaDocElementType; import com.intellij.psi.tree.IElementType; - /** * @author max */ public class JavaHighlightingLexer extends LayeredLexer { public JavaHighlightingLexer(LanguageLevel languageLevel) { - super(new JavaLexer(languageLevel)); + super(JavaParserDefinition.createLexer(languageLevel)); registerSelfStoppingLayer(new StringLiteralLexer('\"', JavaTokenType.STRING_LITERAL), new IElementType[]{JavaTokenType.STRING_LITERAL}, IElementType.EMPTY_ARRAY); registerSelfStoppingLayer(new StringLiteralLexer('\'', JavaTokenType.STRING_LITERAL), new IElementType[]{JavaTokenType.CHARACTER_LITERAL}, IElementType.EMPTY_ARRAY); - LayeredLexer docLexer = new LayeredLexer(new JavaDocLexer(languageLevel.isAtLeast(LanguageLevel.JDK_1_5))); + LayeredLexer docLexer = new LayeredLexer(JavaParserDefinition.createDocLexer(languageLevel)); HtmlHighlightingLexer lexer = new HtmlHighlightingLexer(); lexer.setHasNoEmbeddments(true); diff --git a/java/java-impl/src/com/intellij/openapi/options/colors/pages/JavaColorSettingsPage.java b/java/java-impl/src/com/intellij/openapi/options/colors/pages/JavaColorSettingsPage.java index 8697b8b37558..5f5eb6757553 100644 --- a/java/java-impl/src/com/intellij/openapi/options/colors/pages/JavaColorSettingsPage.java +++ b/java/java-impl/src/com/intellij/openapi/options/colors/pages/JavaColorSettingsPage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ public class JavaColorSettingsPage implements ColorSettingsPage, InspectionColor new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.invalid.escape.in.string"), JavaHighlightingColors.INVALID_STRING_ESCAPE), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.operator.sign"), JavaHighlightingColors.OPERATION_SIGN), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.parentheses"), JavaHighlightingColors.PARENTHS), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.parentheses"), JavaHighlightingColors.PARENTHESES), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.braces"), JavaHighlightingColors.BRACES), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.brackets"), JavaHighlightingColors.BRACKETS), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.comma"), JavaHighlightingColors.COMMA), diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java index 868b98106996..e81e167d3c45 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package com.intellij.psi.formatter.java; import com.intellij.formatting.Spacing; import com.intellij.lang.ASTNode; import com.intellij.lang.java.JavaLanguage; -import com.intellij.lexer.JavaLexer; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.lexer.Lexer; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; @@ -1613,7 +1613,7 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor { if (res == null) { if (!checkToken(token1) || !checkToken(token2)) return true; String text = token1.getText() + token2.getText(); - Lexer lexer = new JavaLexer(LanguageLevel.HIGHEST); + Lexer lexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST); lexer.start(text); boolean canMerge = lexer.getTokenType() == type1; lexer.advance(); @@ -1625,7 +1625,7 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor { } private static boolean checkToken(final ASTNode token1) { - Lexer lexer = new JavaLexer(LanguageLevel.HIGHEST); + Lexer lexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST); final String text = token1.getText(); lexer.start(text); if (lexer.getTokenType() != token1.getElementType()) return false; diff --git a/java/java-impl/src/com/intellij/psi/impl/cache/impl/idCache/JavaIdIndexer.java b/java/java-impl/src/com/intellij/psi/impl/cache/impl/idCache/JavaIdIndexer.java index 1b0898a48e52..d4ff75acee52 100644 --- a/java/java-impl/src/com/intellij/psi/impl/cache/impl/idCache/JavaIdIndexer.java +++ b/java/java-impl/src/com/intellij/psi/impl/cache/impl/idCache/JavaIdIndexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ package com.intellij.psi.impl.cache.impl.idCache; -import com.intellij.lexer.JavaLexer; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.lexer.Lexer; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.impl.cache.impl.OccurrenceConsumer; @@ -28,7 +28,7 @@ public class JavaIdIndexer extends LexerBasedIdIndexer { } public static Lexer createIndexingLexer(OccurrenceConsumer consumer) { - final JavaLexer javaLexer = new JavaLexer(LanguageLevel.JDK_1_3); + Lexer javaLexer = JavaParserDefinition.createLexer(LanguageLevel.JDK_1_3); return new JavaFilterLexer(javaLexer, consumer); } } diff --git a/java/java-impl/src/com/intellij/psi/impl/search/JavaIndexPatternBuilder.java b/java/java-impl/src/com/intellij/psi/impl/search/JavaIndexPatternBuilder.java index dda8720f2cec..d93136ce8f88 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/JavaIndexPatternBuilder.java +++ b/java/java-impl/src/com/intellij/psi/impl/search/JavaIndexPatternBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ package com.intellij.psi.impl.search; -import com.intellij.lexer.JavaLexer; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.lexer.Lexer; import com.intellij.psi.JavaDocTokenType; import com.intellij.psi.JavaTokenType; @@ -40,7 +40,7 @@ public class JavaIndexPatternBuilder implements IndexPatternBuilder { @Nullable public Lexer getIndexingLexer(final PsiFile file) { if (file instanceof PsiJavaFile && !(file instanceof JspFile)) { - return new JavaLexer(((PsiJavaFile)file).getLanguageLevel()); + return JavaParserDefinition.createLexer(((PsiJavaFile)file).getLanguageLevel()); } return null; } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java index f1072ea571d7..4a379e02abb2 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java @@ -32,6 +32,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; @@ -278,7 +279,12 @@ public class JavaClassReference extends GenericReference implements PsiJavaRefer } } - final PsiClass[] classes = aPackage.getClasses(scope); + final List<PsiClass> classes = ContainerUtil.filter(aPackage.getClasses(scope), new Condition<PsiClass>() { + @Override + public boolean value(PsiClass psiClass) { + return StringUtil.isNotEmpty(psiClass.getName()); + } + }); final Map<CustomizableReferenceProvider.CustomizationKey, Object> options = getOptions(); if (options != null) { final boolean instantiatable = JavaClassReferenceProvider.INSTANTIATABLE.getBooleanValue(options); @@ -294,7 +300,7 @@ public class JavaClassReference extends GenericReference implements PsiJavaRefer } } else { - ContainerUtil.addAll(list, classes); + list.addAll(classes); } return list.toArray(); } diff --git a/java/java-impl/src/com/intellij/psi/util/proximity/ExplicitlyImportedWeigher.java b/java/java-impl/src/com/intellij/psi/util/proximity/ExplicitlyImportedWeigher.java index 6e418fe42040..a7bf21b4104d 100644 --- a/java/java-impl/src/com/intellij/psi/util/proximity/ExplicitlyImportedWeigher.java +++ b/java/java-impl/src/com/intellij/psi/util/proximity/ExplicitlyImportedWeigher.java @@ -21,6 +21,7 @@ import com.intellij.openapi.util.NullableLazyKey; import com.intellij.psi.*; import com.intellij.psi.util.ProximityLocation; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.NullableFunction; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -70,6 +71,8 @@ public class ExplicitlyImportedWeigher extends ProximityWeigher { return 0; } + PsiUtilCore.ensureValid(position); + final PsiFile elementFile = element.getContainingFile(); final PsiFile positionFile = position.getContainingFile(); if (positionFile != null && elementFile != null && positionFile.getOriginalFile().equals(elementFile.getOriginalFile())) { @@ -81,6 +84,7 @@ public class ExplicitlyImportedWeigher extends ProximityWeigher { if (qname != null) { final PsiJavaFile psiJavaFile = PsiTreeUtil.getContextOfType(position, PsiJavaFile.class, false); if (psiJavaFile != null) { + PsiUtilCore.ensureValid(psiJavaFile); final PsiImportList importList = psiJavaFile.getImportList(); if (importList != null) { for (final PsiImportStatement importStatement : importList.getImportStatements()) { diff --git a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassDialog.java b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassDialog.java index b8d1f1770cd6..d803d5daecff 100644 --- a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassDialog.java @@ -51,6 +51,8 @@ class CopyClassDialog extends DialogWrapper{ private final Project myProject; private final boolean myDoClone; private final PsiDirectory myDefaultTargetDirectory; + private final JCheckBox myOpenInEditorCb = CopyFilesOrDirectoriesDialog.createOpenInEditorCB(); + private final DestinationFolderComboBox myDestinationCB = new DestinationFolderComboBox() { @Override public String getTargetPackage() { @@ -117,11 +119,14 @@ class CopyClassDialog extends DialogWrapper{ label.setVisible(!myDoClone && isMultipleSourceRoots); label.setLabelFor(myDestinationCB); + final JPanel panel = new JPanel(new BorderLayout()); + panel.add(myOpenInEditorCb, BorderLayout.EAST); return FormBuilder.createFormBuilder() .addComponent(myInformationLabel) .addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNameField, UIUtil.LARGE_VGAP) .addLabeledComponent(myPackageLabel, myTfPackage) .addLabeledComponent(label, myDestinationCB) + .addComponent(panel) .getPanel(); } @@ -143,6 +148,10 @@ class CopyClassDialog extends DialogWrapper{ public String getClassName() { return myNameField.getText(); } + + public boolean openInEditor() { + return myOpenInEditorCb.isSelected(); + } protected void doOKAction(){ final String packageName = myTfPackage.getText(); @@ -179,6 +188,7 @@ class CopyClassDialog extends DialogWrapper{ myNameField.requestFocusInWindow(); return; } + CopyFilesOrDirectoriesDialog.saveOpenInEditorState(myOpenInEditorCb.isSelected()); super.doOKAction(); } diff --git a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java index 2b66afc2545e..a081ff233ca6 100644 --- a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java @@ -181,6 +181,7 @@ public class CopyClassesHandler extends CopyHandlerDelegateBase { Project project = defaultTargetDirectory.getProject(); Object targetDirectory = null; String className = null; + boolean openInEditor = true; if (copyOneClass(classes)) { final String commonPath = ArrayUtil.find(elements, classes.values().iterator().next()) == -1 ? normalizeRelativeMap(relativePathsMap) : null; CopyClassDialog dialog = new CopyClassDialog(classes.values().iterator().next()[0], defaultTargetDirectory, project, false){ @@ -195,6 +196,7 @@ public class CopyClassesHandler extends CopyHandlerDelegateBase { dialog.setTitle(RefactoringBundle.message("copy.handler.copy.class")); dialog.show(); if (dialog.isOK()) { + openInEditor = dialog.openInEditor(); targetDirectory = dialog.getTargetDirectory(); className = dialog.getClassName(); if (className == null || className.length() == 0) return; @@ -218,12 +220,13 @@ public class CopyClassesHandler extends CopyHandlerDelegateBase { if (dialog.isOK()) { targetDirectory = dialog.getTargetDirectory(); className = dialog.getNewName(); + openInEditor = dialog.openInEditor(); } } } if (targetDirectory != null) { copyClassesImpl(className, project, classes, relativePathsMap, targetDirectory, defaultTargetDirectory, RefactoringBundle.message( - "copy.handler.copy.class"), false); + "copy.handler.copy.class"), false, openInEditor); } } @@ -251,7 +254,7 @@ public class CopyClassesHandler extends CopyHandlerDelegateBase { String className = dialog.getClassName(); PsiDirectory targetDirectory = element.getContainingFile().getContainingDirectory(); copyClassesImpl(className, project, Collections.singletonMap(classes[0].getContainingFile(), classes), null, targetDirectory, - targetDirectory, RefactoringBundle.message("copy.handler.clone.class"), true); + targetDirectory, RefactoringBundle.message("copy.handler.clone.class"), true, true); } } @@ -262,7 +265,8 @@ public class CopyClassesHandler extends CopyHandlerDelegateBase { final Object targetDirectory, final PsiDirectory defaultTargetDirectory, final String commandName, - final boolean selectInActivePanel) { + final boolean selectInActivePanel, + final boolean openInEditor) { final boolean[] result = new boolean[] {false}; Runnable command = new Runnable() { public void run() { @@ -278,7 +282,7 @@ public class CopyClassesHandler extends CopyHandlerDelegateBase { PsiElement newElement = doCopyClasses(classes, map, copyClassName, target, project); if (newElement != null) { CopyHandler.updateSelectionInActiveProjectView(newElement, project, selectInActivePanel); - EditorHelper.openInEditor(newElement); + if (openInEditor) EditorHelper.openInEditor(newElement); result[0] = true; } diff --git a/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpHelper.java b/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpHelper.java index 95c826f18897..c7c8c7f194c5 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpHelper.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpHelper.java @@ -215,6 +215,19 @@ public class PullUpHelper extends BaseRefactoringProcessor{ for (MemberInfo info : myMembersToMove) { if (info.getMember() instanceof PsiMethod) { PsiMethod method = (PsiMethod)info.getMember(); + PsiMethod sibling = method; + PsiMethod anchor = null; + while (sibling != null) { + sibling = PsiTreeUtil.getNextSiblingOfType(sibling, PsiMethod.class); + if (sibling != null) { + anchor = MethodSignatureUtil + .findMethodInSuperClassBySignatureInDerived(method.getContainingClass(), myTargetSuperClass, + sibling.getSignature(PsiSubstitutor.EMPTY), false); + if (anchor != null) { + break; + } + } + } PsiMethod methodCopy = (PsiMethod)method.copy(); if (method.findSuperMethods(myTargetSuperClass).length == 0) { deleteOverrideAnnotationIfFound(methodCopy); @@ -227,7 +240,7 @@ public class PullUpHelper extends BaseRefactoringProcessor{ myJavaDocPolicy.processCopiedJavaDoc(methodCopy.getDocComment(), method.getDocComment(), isOriginalMethodAbstract); - final PsiMember movedElement = (PsiMember)myTargetSuperClass.add(methodCopy); + final PsiMember movedElement = anchor != null ? (PsiMember)myTargetSuperClass.addBefore(methodCopy, anchor) : (PsiMember)myTargetSuperClass.add(methodCopy); CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(method.getProject()); if (styleSettings.INSERT_OVERRIDE_ANNOTATION) { if (PsiUtil.isLanguageLevel5OrHigher(mySourceClass) && !myTargetSuperClass.isInterface() || PsiUtil.isLanguageLevel6OrHigher(mySourceClass)) { @@ -258,7 +271,8 @@ public class PullUpHelper extends BaseRefactoringProcessor{ superClassMethod.replace(methodCopy); } else { - final PsiMember movedElement = (PsiMember)myTargetSuperClass.add(methodCopy); + final PsiMember movedElement = + anchor != null ? (PsiMember)myTargetSuperClass.addBefore(methodCopy, anchor) : (PsiMember)myTargetSuperClass.add(methodCopy); myMembersAfterMove.add(movedElement); } method.delete(); diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveJavaMemberHandler.java b/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveJavaMemberHandler.java index 8f0f3d1fb257..ea39904f5a1d 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveJavaMemberHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveJavaMemberHandler.java @@ -112,6 +112,12 @@ public class MoveJavaMemberHandler implements MoveMemberHandler { conflicts.putValue(element, CommonRefactoringUtil.capitalize(message)); } } + } else if (member instanceof PsiField && + usageInfo.reference instanceof PsiExpression && + member.hasModifierProperty(PsiModifier.FINAL) && + PsiUtil.isAccessedForWriting((PsiExpression)usageInfo.reference) && + !RefactoringHierarchyUtil.willBeInTargetClass(usageInfo.reference, membersToMove, targetClass, true)) { + conflicts.putValue(usageInfo.member, "final variable initializer won't be available after move."); } final PsiReference reference = usageInfo.getReference(); diff --git a/java/java-impl/src/com/intellij/spi/SPIAnnotator.java b/java/java-impl/src/com/intellij/spi/SPIAnnotator.java new file mode 100644 index 000000000000..f834542854cb --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/SPIAnnotator.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi; + +import com.intellij.lang.annotation.AnnotationHolder; +import com.intellij.lang.annotation.Annotator; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.util.ClassUtil; +import com.intellij.psi.util.PsiUtilCore; +import com.intellij.spi.psi.SPIProviderElement; +import org.jetbrains.annotations.NotNull; + +/** + * User: anna + */ +public class SPIAnnotator implements Annotator{ + @Override + public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { + final VirtualFile file = PsiUtilCore.getVirtualFile(element); + if (file != null && file.getFileType() instanceof SPIFileType) { + final String serviceProviderName = file.getName(); + final PsiClass psiClass = + ClassUtil.findPsiClass(element.getManager(), serviceProviderName, null, true, element.getContainingFile().getResolveScope()); + if (element instanceof PsiFile) { + if (psiClass == null) { + holder.createErrorAnnotation(element, "No service provider \"" + serviceProviderName + "\' found").setFileLevelAnnotation(true); + } + } else if (element instanceof SPIProviderElement) { + final PsiElement resolve = ((SPIProviderElement)element).resolve(); + if (resolve == null) { + holder.createErrorAnnotation(element, "Cannot resolve symbol " + element.getText()); + } else if (resolve instanceof PsiClass && psiClass != null) { + if (!((PsiClass)resolve).isInheritor(psiClass, true)) { + holder.createErrorAnnotation(element, "Registered extension should implement " + serviceProviderName); + } + } + } + } + } +} diff --git a/java/java-impl/src/com/intellij/spi/SPICommenter.java b/java/java-impl/src/com/intellij/spi/SPICommenter.java new file mode 100644 index 000000000000..0afd9cdd717b --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/SPICommenter.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi; + +import com.intellij.lang.Commenter; +import org.jetbrains.annotations.Nullable; + +/** + * User: anna + */ +public class SPICommenter implements Commenter { + @Nullable + @Override + public String getLineCommentPrefix() { + return "#"; + } + + @Nullable + @Override + public String getBlockCommentPrefix() { + return null; + } + + @Nullable + @Override + public String getBlockCommentSuffix() { + return null; + } + + @Nullable + @Override + public String getCommentedBlockCommentPrefix() { + return null; + } + + @Nullable + @Override + public String getCommentedBlockCommentSuffix() { + return null; + } +} diff --git a/java/java-impl/src/com/intellij/spi/SPIFileType.java b/java/java-impl/src/com/intellij/spi/SPIFileType.java new file mode 100644 index 000000000000..0d4a3bd8e474 --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/SPIFileType.java @@ -0,0 +1,92 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi; + +import com.intellij.icons.AllIcons; +import com.intellij.lang.spi.SPILanguage; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.LanguageFileType; +import com.intellij.openapi.fileTypes.ex.FileTypeIdentifiableByVirtualFile; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vfs.CharsetToolkit; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * User: anna + */ +public class SPIFileType extends LanguageFileType implements FileTypeIdentifiableByVirtualFile { + public static final SPIFileType INSTANCE = new SPIFileType(); + + private SPIFileType() { + super(SPILanguage.INSTANCE); + } + + @Override + public boolean isMyFileType(VirtualFile file) { + VirtualFile parent = file.getParent(); + if (parent != null && "services".equals(parent.getName())) { + final VirtualFile gParent = parent.getParent(); + if (gParent != null && "META-INF".equals(gParent.getName())) { + final String fileName = file.getName(); + for (Object condition : Extensions.getExtensions("com.intellij.vetoSPICondition")) { + if (((Condition<String>)condition).value(fileName)) return false; + } + return true; + } + } + return false; + } + + @NotNull + @Override + public String getName() { + return "SPI"; + } + + @NotNull + @Override + public String getDescription() { + return "Service Provider Interface"; + } + + @NotNull + @Override + public String getDefaultExtension() { + return ""; + } + + @Nullable + @Override + public Icon getIcon() { + return AllIcons.FileTypes.Text; + } + + @Override + public boolean isReadOnly() { + return false; + } + + @Nullable + @Override + public String getCharset(@NotNull VirtualFile file, byte[] content) { + return CharsetToolkit.UTF8; + } +} diff --git a/java/java-impl/src/com/intellij/spi/SPIFileTypeFactory.java b/java/java-impl/src/com/intellij/spi/SPIFileTypeFactory.java new file mode 100644 index 000000000000..ae61295651b4 --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/SPIFileTypeFactory.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi; + +import com.intellij.openapi.fileTypes.FileTypeConsumer; +import com.intellij.openapi.fileTypes.FileTypeFactory; +import org.jetbrains.annotations.NotNull; + +/** + * User: anna + */ +public class SPIFileTypeFactory extends FileTypeFactory { + @Override + public void createFileTypes(@NotNull FileTypeConsumer consumer) { + consumer.consume(SPIFileType.INSTANCE); + } +} diff --git a/java/java-impl/src/com/intellij/spi/SPIGotoSuperHandler.java b/java/java-impl/src/com/intellij/spi/SPIGotoSuperHandler.java new file mode 100644 index 000000000000..a4a01485313d --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/SPIGotoSuperHandler.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi; + +import com.intellij.codeInsight.navigation.JavaGotoSuperHandler; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiNameIdentifierOwner; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.spi.psi.SPIProviderElement; + +/** + * User: anna + */ +public class SPIGotoSuperHandler extends JavaGotoSuperHandler { + @Override + protected PsiNameIdentifierOwner getElement(PsiFile file, int offset) { + final SPIProviderElement providerElement = PsiTreeUtil.getParentOfType(file.findElementAt(offset), SPIProviderElement.class); + if (providerElement != null) { + return (PsiClass)providerElement.resolve(); + } + + return null; + } +} diff --git a/java/java-impl/src/com/intellij/spi/parsing/SPIElementType.java b/java/java-impl/src/com/intellij/spi/parsing/SPIElementType.java new file mode 100644 index 000000000000..9d5c9cb655f9 --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/parsing/SPIElementType.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi.parsing; + +import com.intellij.psi.tree.IElementType; +import com.intellij.lang.spi.SPILanguage; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +/** + * User: anna + */ +public class SPIElementType extends IElementType { + public SPIElementType(@NotNull @NonNls String debugName) { + super(debugName, SPILanguage.INSTANCE); + } +} diff --git a/java/java-impl/src/com/intellij/spi/parsing/SPIElementTypes.java b/java/java-impl/src/com/intellij/spi/parsing/SPIElementTypes.java new file mode 100644 index 000000000000..228a8459d14f --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/parsing/SPIElementTypes.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi.parsing; + +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.IFileElementType; +import com.intellij.psi.tree.TokenSet; +import com.intellij.lang.spi.SPILanguage; + +public interface SPIElementTypes { + + IFileElementType FILE = new IFileElementType(SPILanguage.INSTANCE); + IElementType PROVIDER = new IElementType("PROVIDER", SPILanguage.INSTANCE); + + IElementType PROVIDERS_LIST = new IElementType("ROVIDER_LIST", SPILanguage.INSTANCE); + TokenSet PROVIDERS = TokenSet.create(PROVIDER); +} diff --git a/java/java-impl/src/com/intellij/spi/parsing/SPILexer.java b/java/java-impl/src/com/intellij/spi/parsing/SPILexer.java new file mode 100644 index 000000000000..6a698a9ea5a8 --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/parsing/SPILexer.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.intellij.spi.parsing; + +import com.intellij.lexer.FlexAdapter; + + +public class SPILexer extends FlexAdapter { + public SPILexer() { + super(new _SPILexer()); + } +} diff --git a/java/java-impl/src/com/intellij/spi/parsing/SPIParserDefinition.java b/java/java-impl/src/com/intellij/spi/parsing/SPIParserDefinition.java new file mode 100644 index 000000000000..f32bd37a11d9 --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/parsing/SPIParserDefinition.java @@ -0,0 +1,137 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi.parsing; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.ParserDefinition; +import com.intellij.lang.PsiBuilder; +import com.intellij.lang.PsiParser; +import com.intellij.lexer.Lexer; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; +import com.intellij.psi.*; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.IFileElementType; +import com.intellij.psi.tree.TokenSet; +import com.intellij.psi.util.PsiUtilCore; +import com.intellij.spi.psi.SPIProviderElement; +import com.intellij.spi.psi.SPIProvidersElementList; +import com.intellij.spi.psi.SPIFile; +import com.intellij.lang.spi.SPILanguage; +import org.jetbrains.annotations.NotNull; + +/** + * User: anna + */ +public class SPIParserDefinition implements ParserDefinition { + public static final IFileElementType SPI_FILE_ELEMENT_TYPE = new IFileElementType(SPILanguage.INSTANCE); + + private static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE); + private static final Logger LOG = Logger.getInstance("#" + SPIParserDefinition.class.getName()); + + @NotNull + @Override + public Lexer createLexer(Project project) { + return new SPILexer(); + } + + @Override + public PsiParser createParser(Project project) { + return new PsiParser() { + @NotNull + @Override + public ASTNode parse(IElementType root, PsiBuilder builder) { + final PsiBuilder.Marker rootMarker = builder.mark(); + final PsiBuilder.Marker propertiesList = builder.mark(); + while (!builder.eof()) { + parseProvider(builder); + } + propertiesList.done(SPIElementTypes.PROVIDERS_LIST); + rootMarker.done(root); + return builder.getTreeBuilt(); + } + }; + } + + @Override + public IFileElementType getFileNodeType() { + return SPI_FILE_ELEMENT_TYPE; + } + + @NotNull + @Override + public TokenSet getWhitespaceTokens() { + return WHITE_SPACES; + } + + @NotNull + @Override + public TokenSet getCommentTokens() { + return TokenSet.create(JavaTokenType.END_OF_LINE_COMMENT); + } + + @NotNull + @Override + public TokenSet getStringLiteralElements() { + return TokenSet.EMPTY; + } + + @NotNull + @Override + public PsiElement createElement(ASTNode node) { + final IElementType elementType = node.getElementType(); + if (elementType == SPIElementTypes.PROVIDERS_LIST) { + return new SPIProvidersElementList(node); + } + if (elementType == SPIElementTypes.PROVIDER) { + return new SPIProviderElement(node); + } + return PsiUtilCore.NULL_PSI_ELEMENT; + } + + @Override + public PsiFile createFile(FileViewProvider viewProvider) { + return new SPIFile(viewProvider); + } + + @Override + public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) { + return SpaceRequirements.MAY; + } + + public static void parseProvider(PsiBuilder builder) { + if (builder.getTokenType() == JavaTokenType.IDENTIFIER) { + final PsiBuilder.Marker prop = builder.mark(); + + parseProviderChar(builder); + prop.done(SPIElementTypes.PROVIDER); + } + else { + builder.advanceLexer(); + builder.error("Unexpected token"); + } + } + + private static void parseProviderChar(final PsiBuilder builder) { + LOG.assertTrue(builder.getTokenType() == JavaTokenType.IDENTIFIER); + builder.advanceLexer(); + final IElementType tokenType = builder.getTokenType(); + if (tokenType == JavaTokenType.DOT || tokenType == SPITokenType.DOLLAR) { + builder.advanceLexer(); + parseProviderChar(builder); + } + } +} diff --git a/java/java-impl/src/com/intellij/spi/parsing/SPITokenType.java b/java/java-impl/src/com/intellij/spi/parsing/SPITokenType.java new file mode 100644 index 000000000000..cd8b0e6d4e08 --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/parsing/SPITokenType.java @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi.parsing; + +import com.intellij.psi.JavaTokenType; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.java.IKeywordElementType; + +/** + * User: anna + */ +public interface SPITokenType extends JavaTokenType { + IElementType SHARP = new IKeywordElementType("SHARP"); + IElementType DOLLAR = new IKeywordElementType("DOLLAR"); +} diff --git a/java/java-impl/src/com/intellij/spi/parsing/_SPILexer.flex b/java/java-impl/src/com/intellij/spi/parsing/_SPILexer.flex new file mode 100644 index 000000000000..b49ef5dac14a --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/parsing/_SPILexer.flex @@ -0,0 +1,67 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi.parsing; + +import com.intellij.psi.JavaTokenType; +import com.intellij.psi.tree.IElementType; +import com.intellij.spi.parsing.SPITokenType; +import com.intellij.lexer.FlexLexer; + +@SuppressWarnings({"ALL"}) +%% + +%{ + public _SPILexer() { + this((java.io.Reader)null); + } + + public void goTo(int offset) { + zzCurrentPos = zzMarkedPos = zzStartRead = offset; + zzPushbackPos = 0; + zzAtEOF = offset < zzEndRead; + } +%} + +%unicode +%class _SPILexer +%implements FlexLexer +%function advance +%type IElementType +%eof{ return; +%eof} + +WHITE_SPACE_CHAR=[\ \n\r\t\f] + +IDENTIFIER=[:jletter:] [:jletterdigit:]* + +END_OF_LINE_COMMENT="#"[^\r\n]* + +DIGIT = [0-9] +DIGIT_OR_UNDERSCORE = [_0-9] +DIGITS = {DIGIT} | {DIGIT} {DIGIT_OR_UNDERSCORE}* + +%% + +<YYINITIAL> {WHITE_SPACE_CHAR}+ { return JavaTokenType.WHITE_SPACE; } + +<YYINITIAL> {END_OF_LINE_COMMENT} { return JavaTokenType.END_OF_LINE_COMMENT; } +<YYINITIAL> {IDENTIFIER} { return JavaTokenType.IDENTIFIER; } + +<YYINITIAL> "." { return JavaTokenType.DOT; } + +<YYINITIAL> "$" { return SPITokenType.DOLLAR; } + +<YYINITIAL> . { return JavaTokenType.BAD_CHARACTER; } diff --git a/java/java-impl/src/com/intellij/spi/parsing/_SPILexer.java b/java/java-impl/src/com/intellij/spi/parsing/_SPILexer.java new file mode 100644 index 000000000000..f08e8b295d1e --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/parsing/_SPILexer.java @@ -0,0 +1,603 @@ +/* The following code was generated by JFlex 1.4.3 on 6/5/13 9:20 PM */ + +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi.parsing; + +import com.intellij.psi.JavaTokenType; +import com.intellij.psi.tree.IElementType; +import com.intellij.spi.parsing.SPITokenType; +import com.intellij.lexer.FlexLexer; + +@SuppressWarnings({"ALL"}) + +/** + * This class is a scanner generated by + * <a href="http://www.jflex.de/">JFlex</a> 1.4.3 + * on 6/5/13 9:20 PM from the specification file + * <tt>D:/Projects/IDEA.anna/tools/lexer/../../community/java/java-impl/src/com/intellij/spi/parsing/_SPILexer.flex</tt> + */ +class _SPILexer implements FlexLexer { + /** initial size of the lookahead buffer */ + private static final int ZZ_BUFFERSIZE = 16384; + + /** lexical states */ + public static final int YYINITIAL = 0; + + /** + * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l + * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l + * at the beginning of a line + * l is of the form l = 2*k, k a non negative integer + */ + private static final int ZZ_LEXSTATE[] = { + 0, 0 + }; + + /** + * Translates characters to character classes + */ + private static final String ZZ_CMAP_PACKED = + "\11\3\1\1\1\5\1\0\1\1\1\5\16\3\4\0\1\1\2\0"+ + "\1\4\1\2\11\0\1\6\1\0\12\3\7\0\32\2\4\0\1\2"+ + "\1\0\32\2\4\0\41\3\2\0\4\2\4\0\1\2\2\0\1\3"+ + "\7\0\1\2\4\0\1\2\5\0\27\2\1\0\37\2\1\0\u013f\2"+ + "\31\0\162\2\4\0\14\2\16\0\5\2\11\0\1\2\21\0\130\3"+ + "\5\0\23\3\12\0\1\2\13\0\1\2\1\0\3\2\1\0\1\2"+ + "\1\0\24\2\1\0\54\2\1\0\46\2\1\0\5\2\4\0\202\2"+ + "\1\0\4\3\3\0\105\2\1\0\46\2\2\0\2\2\6\0\20\2"+ + "\41\0\46\2\2\0\1\2\7\0\47\2\11\0\21\3\1\0\27\3"+ + "\1\0\3\3\1\0\1\3\1\0\2\3\1\0\1\3\13\0\33\2"+ + "\5\0\3\2\15\0\4\3\14\0\6\3\13\0\32\2\5\0\13\2"+ + "\16\3\7\0\12\3\4\0\2\2\1\3\143\2\1\0\1\2\10\3"+ + "\1\0\6\3\2\2\2\3\1\0\4\3\2\2\12\3\3\2\2\0"+ + "\1\2\17\0\1\3\1\2\1\3\36\2\33\3\2\0\3\2\60\0"+ + "\46\2\13\3\1\2\u014f\0\3\3\66\2\2\0\1\3\1\2\20\3"+ + "\2\0\1\2\4\3\3\0\12\2\2\3\2\0\12\3\21\0\3\3"+ + "\1\0\10\2\2\0\2\2\2\0\26\2\1\0\7\2\1\0\1\2"+ + "\3\0\4\2\2\0\1\3\1\2\7\3\2\0\2\3\2\0\3\3"+ + "\11\0\1\3\4\0\2\2\1\0\3\2\2\3\2\0\12\3\4\2"+ + "\15\0\3\3\1\0\6\2\4\0\2\2\2\0\26\2\1\0\7\2"+ + "\1\0\2\2\1\0\2\2\1\0\2\2\2\0\1\3\1\0\5\3"+ + "\4\0\2\3\2\0\3\3\13\0\4\2\1\0\1\2\7\0\14\3"+ + "\3\2\14\0\3\3\1\0\11\2\1\0\3\2\1\0\26\2\1\0"+ + "\7\2\1\0\2\2\1\0\5\2\2\0\1\3\1\2\10\3\1\0"+ + "\3\3\1\0\3\3\2\0\1\2\17\0\2\2\2\3\2\0\12\3"+ + "\1\0\1\2\17\0\3\3\1\0\10\2\2\0\2\2\2\0\26\2"+ + "\1\0\7\2\1\0\2\2\1\0\5\2\2\0\1\3\1\2\6\3"+ + "\3\0\2\3\2\0\3\3\10\0\2\3\4\0\2\2\1\0\3\2"+ + "\4\0\12\3\1\0\1\2\20\0\1\3\1\2\1\0\6\2\3\0"+ + "\3\2\1\0\4\2\3\0\2\2\1\0\1\2\1\0\2\2\3\0"+ + "\2\2\3\0\3\2\3\0\10\2\1\0\3\2\4\0\5\3\3\0"+ + "\3\3\1\0\4\3\11\0\1\3\17\0\11\3\11\0\1\2\7\0"+ + "\3\3\1\0\10\2\1\0\3\2\1\0\27\2\1\0\12\2\1\0"+ + "\5\2\4\0\7\3\1\0\3\3\1\0\4\3\7\0\2\3\11\0"+ + "\2\2\4\0\12\3\22\0\2\3\1\0\10\2\1\0\3\2\1\0"+ + "\27\2\1\0\12\2\1\0\5\2\2\0\1\3\1\2\7\3\1\0"+ + "\3\3\1\0\4\3\7\0\2\3\7\0\1\2\1\0\2\2\4\0"+ + "\12\3\22\0\2\3\1\0\10\2\1\0\3\2\1\0\27\2\1\0"+ + "\20\2\4\0\6\3\2\0\3\3\1\0\4\3\11\0\1\3\10\0"+ + "\2\2\4\0\12\3\22\0\2\3\1\0\22\2\3\0\30\2\1\0"+ + "\11\2\1\0\1\2\2\0\7\2\3\0\1\3\4\0\6\3\1\0"+ + "\1\3\1\0\10\3\22\0\2\3\15\0\60\2\1\3\2\2\7\3"+ + "\4\0\10\2\10\3\1\0\12\3\47\0\2\2\1\0\1\2\2\0"+ + "\2\2\1\0\1\2\2\0\1\2\6\0\4\2\1\0\7\2\1\0"+ + "\3\2\1\0\1\2\1\0\1\2\2\0\2\2\1\0\4\2\1\3"+ + "\2\2\6\3\1\0\2\3\1\2\2\0\5\2\1\0\1\2\1\0"+ + "\6\3\2\0\12\3\2\0\2\2\42\0\1\2\27\0\2\3\6\0"+ + "\12\3\13\0\1\3\1\0\1\3\1\0\1\3\4\0\2\3\10\2"+ + "\1\0\42\2\6\0\24\3\1\0\2\3\4\2\4\0\10\3\1\0"+ + "\44\3\11\0\1\3\71\0\42\2\1\0\5\2\1\0\2\2\1\0"+ + "\7\3\3\0\4\3\6\0\12\3\6\0\6\2\4\3\106\0\46\2"+ + "\12\0\51\2\7\0\132\2\5\0\104\2\5\0\122\2\6\0\7\2"+ + "\1\0\77\2\1\0\1\2\1\0\4\2\2\0\7\2\1\0\1\2"+ + "\1\0\4\2\2\0\47\2\1\0\1\2\1\0\4\2\2\0\37\2"+ + "\1\0\1\2\1\0\4\2\2\0\7\2\1\0\1\2\1\0\4\2"+ + "\2\0\7\2\1\0\7\2\1\0\27\2\1\0\37\2\1\0\1\2"+ + "\1\0\4\2\2\0\7\2\1\0\47\2\1\0\23\2\16\0\11\3"+ + "\56\0\125\2\14\0\u026c\2\2\0\10\2\12\0\32\2\5\0\113\2"+ + "\3\0\3\2\17\0\15\2\1\0\4\2\3\3\13\0\22\2\3\3"+ + "\13\0\22\2\2\3\14\0\15\2\1\0\3\2\1\0\2\3\14\0"+ + "\64\2\40\3\3\0\1\2\3\0\2\2\1\3\2\0\12\3\41\0"+ + "\3\3\2\0\12\3\6\0\130\2\10\0\51\2\1\3\126\0\35\2"+ + "\3\0\14\3\4\0\14\3\12\0\12\3\36\2\2\0\5\2\u038b\0"+ + "\154\2\224\0\234\2\4\0\132\2\6\0\26\2\2\0\6\2\2\0"+ + "\46\2\2\0\6\2\2\0\10\2\1\0\1\2\1\0\1\2\1\0"+ + "\1\2\1\0\37\2\2\0\65\2\1\0\7\2\1\0\1\2\3\0"+ + "\3\2\1\0\7\2\3\0\4\2\2\0\6\2\4\0\15\2\5\0"+ + "\3\2\1\0\7\2\17\0\4\3\32\0\5\3\20\0\2\2\23\0"+ + "\1\2\13\0\4\3\6\0\6\3\1\0\1\2\15\0\1\2\40\0"+ + "\22\2\36\0\15\3\4\0\1\3\3\0\6\3\27\0\1\2\4\0"+ + "\1\2\2\0\12\2\1\0\1\2\3\0\5\2\6\0\1\2\1\0"+ + "\1\2\1\0\1\2\1\0\4\2\1\0\3\2\1\0\7\2\3\0"+ + "\3\2\5\0\5\2\26\0\44\2\u0e81\0\3\2\31\0\11\2\6\3"+ + "\1\0\5\2\2\0\5\2\4\0\126\2\2\0\2\3\2\0\3\2"+ + "\1\0\137\2\5\0\50\2\4\0\136\2\21\0\30\2\70\0\20\2"+ + "\u0200\0\u19b6\2\112\0\u51a6\2\132\0\u048d\2\u0773\0\u2ba4\2\u215c\0\u012e\2"+ + "\2\0\73\2\225\0\7\2\14\0\5\2\5\0\1\2\1\3\12\2"+ + "\1\0\15\2\1\0\5\2\1\0\1\2\1\0\2\2\1\0\2\2"+ + "\1\0\154\2\41\0\u016b\2\22\0\100\2\2\0\66\2\50\0\15\2"+ + "\3\0\20\3\20\0\4\3\17\0\2\2\30\0\3\2\31\0\1\2"+ + "\6\0\5\2\1\0\207\2\2\0\1\3\4\0\1\2\13\0\12\3"+ + "\7\0\32\2\4\0\1\2\1\0\32\2\12\0\132\2\3\0\6\2"+ + "\2\0\6\2\2\0\6\2\2\0\3\2\3\0\2\2\3\0\2\2"+ + "\22\0\3\3\4\0"; + + /** + * Translates characters to character classes + */ + private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); + + /** + * Translates DFA states to action switch labels. + */ + private static final int [] ZZ_ACTION = zzUnpackAction(); + + private static final String ZZ_ACTION_PACKED_0 = + "\1\0\1\1\1\2\1\3\1\4\1\5"; + + private static int [] zzUnpackAction() { + int [] result = new int[6]; + int offset = 0; + offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackAction(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + + /** + * Translates a state to a row index in the transition table + */ + private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); + + private static final String ZZ_ROWMAP_PACKED_0 = + "\0\0\0\7\0\16\0\25\0\34\0\7"; + + private static int [] zzUnpackRowMap() { + int [] result = new int[6]; + int offset = 0; + offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackRowMap(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int high = packed.charAt(i++) << 16; + result[j++] = high | packed.charAt(i++); + } + return j; + } + + /** + * The transition table of the DFA + */ + private static final int [] ZZ_TRANS = zzUnpackTrans(); + + private static final String ZZ_TRANS_PACKED_0 = + "\1\2\1\3\1\4\1\2\1\5\1\3\1\6\10\0"+ + "\1\3\3\0\1\3\3\0\2\4\3\0\5\5\1\0"+ + "\1\5"; + + private static int [] zzUnpackTrans() { + int [] result = new int[35]; + int offset = 0; + offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackTrans(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + value--; + do result[j++] = value; while (--count > 0); + } + return j; + } + + + /* error codes */ + private static final int ZZ_UNKNOWN_ERROR = 0; + private static final int ZZ_NO_MATCH = 1; + private static final int ZZ_PUSHBACK_2BIG = 2; + private static final char[] EMPTY_BUFFER = new char[0]; + private static final int YYEOF = -1; + private static java.io.Reader zzReader = null; // Fake + + /* error messages for the codes above */ + private static final String ZZ_ERROR_MSG[] = { + "Unkown internal scanner error", + "Error: could not match input", + "Error: pushback value was too large" + }; + + /** + * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code> + */ + private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); + + private static final String ZZ_ATTRIBUTE_PACKED_0 = + "\1\0\1\11\3\1\1\11"; + + private static int [] zzUnpackAttribute() { + int [] result = new int[6]; + int offset = 0; + offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackAttribute(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + /** the current state of the DFA */ + private int zzState; + + /** the current lexical state */ + private int zzLexicalState = YYINITIAL; + + /** this buffer contains the current text to be matched and is + the source of the yytext() string */ + private CharSequence zzBuffer = ""; + + /** this buffer may contains the current text array to be matched when it is cheap to acquire it */ + private char[] zzBufferArray; + + /** the textposition at the last accepting state */ + private int zzMarkedPos; + + /** the textposition at the last state to be included in yytext */ + private int zzPushbackPos; + + /** the current text position in the buffer */ + private int zzCurrentPos; + + /** startRead marks the beginning of the yytext() string in the buffer */ + private int zzStartRead; + + /** endRead marks the last character in the buffer, that has been read + from input */ + private int zzEndRead; + + /** + * zzAtBOL == true <=> the scanner is currently at the beginning of a line + */ + private boolean zzAtBOL = true; + + /** zzAtEOF == true <=> the scanner is at the EOF */ + private boolean zzAtEOF; + + /** denotes if the user-EOF-code has already been executed */ + private boolean zzEOFDone; + + /* user code: */ + public _SPILexer() { + this((java.io.Reader)null); + } + + public void goTo(int offset) { + zzCurrentPos = zzMarkedPos = zzStartRead = offset; + zzPushbackPos = 0; + zzAtEOF = offset < zzEndRead; + } + + + _SPILexer(java.io.Reader in) { + this.zzReader = in; + } + + /** + * Creates a new scanner. + * There is also java.io.Reader version of this constructor. + * + * @param in the java.io.Inputstream to read input from. + */ + _SPILexer(java.io.InputStream in) { + this(new java.io.InputStreamReader(in)); + } + + /** + * Unpacks the compressed character translation table. + * + * @param packed the packed character translation table + * @return the unpacked character translation table + */ + private static char [] zzUnpackCMap(String packed) { + char [] map = new char[0x10000]; + int i = 0; /* index in packed string */ + int j = 0; /* index in unpacked array */ + while (i < 1666) { + int count = packed.charAt(i++); + char value = packed.charAt(i++); + do map[j++] = value; while (--count > 0); + } + return map; + } + + public final int getTokenStart(){ + return zzStartRead; + } + + public final int getTokenEnd(){ + return getTokenStart() + yylength(); + } + + public void reset(CharSequence buffer, int start, int end,int initialState){ + zzBuffer = buffer; + zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer); + zzCurrentPos = zzMarkedPos = zzStartRead = start; + zzPushbackPos = 0; + zzAtEOF = false; + zzAtBOL = true; + zzEndRead = end; + yybegin(initialState); + } + + /** + * Refills the input buffer. + * + * @return <code>false</code>, iff there was new input. + * + * @exception java.io.IOException if any I/O-Error occurs + */ + private boolean zzRefill() throws java.io.IOException { + return true; + } + + + /** + * Returns the current lexical state. + */ + public final int yystate() { + return zzLexicalState; + } + + + /** + * Enters a new lexical state + * + * @param newState the new lexical state + */ + public final void yybegin(int newState) { + zzLexicalState = newState; + } + + + /** + * Returns the text matched by the current regular expression. + */ + public final CharSequence yytext() { + return zzBuffer.subSequence(zzStartRead, zzMarkedPos); + } + + + /** + * Returns the character at position <tt>pos</tt> from the + * matched text. + * + * It is equivalent to yytext().charAt(pos), but faster + * + * @param pos the position of the character to fetch. + * A value from 0 to yylength()-1. + * + * @return the character at position pos + */ + public final char yycharat(int pos) { + return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos); + } + + + /** + * Returns the length of the matched text region. + */ + public final int yylength() { + return zzMarkedPos-zzStartRead; + } + + + /** + * Reports an error that occured while scanning. + * + * In a wellformed scanner (no or only correct usage of + * yypushback(int) and a match-all fallback rule) this method + * will only be called with things that "Can't Possibly Happen". + * If this method is called, something is seriously wrong + * (e.g. a JFlex bug producing a faulty scanner etc.). + * + * Usual syntax/scanner level error handling should be done + * in error fallback rules. + * + * @param errorCode the code of the errormessage to display + */ + private void zzScanError(int errorCode) { + String message; + try { + message = ZZ_ERROR_MSG[errorCode]; + } + catch (ArrayIndexOutOfBoundsException e) { + message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; + } + + throw new Error(message); + } + + + /** + * Pushes the specified amount of characters back into the input stream. + * + * They will be read again by then next call of the scanning method + * + * @param number the number of characters to be read again. + * This number must not be greater than yylength()! + */ + public void yypushback(int number) { + if ( number > yylength() ) + zzScanError(ZZ_PUSHBACK_2BIG); + + zzMarkedPos -= number; + } + + + /** + * Contains user EOF-code, which will be executed exactly once, + * when the end of file is reached + */ + private void zzDoEOF() { + if (!zzEOFDone) { + zzEOFDone = true; + + } + } + + + /** + * Resumes scanning until the next regular expression is matched, + * the end of input is encountered or an I/O-Error occurs. + * + * @return the next token + * @exception java.io.IOException if any I/O-Error occurs + */ + public IElementType advance() throws java.io.IOException { + int zzInput; + int zzAction; + + // cached fields: + int zzCurrentPosL; + int zzMarkedPosL; + int zzEndReadL = zzEndRead; + CharSequence zzBufferL = zzBuffer; + char[] zzBufferArrayL = zzBufferArray; + char [] zzCMapL = ZZ_CMAP; + + int [] zzTransL = ZZ_TRANS; + int [] zzRowMapL = ZZ_ROWMAP; + int [] zzAttrL = ZZ_ATTRIBUTE; + + while (true) { + zzMarkedPosL = zzMarkedPos; + + zzAction = -1; + + zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; + + zzState = ZZ_LEXSTATE[zzLexicalState]; + + + zzForAction: { + while (true) { + + if (zzCurrentPosL < zzEndReadL) + zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); + else if (zzAtEOF) { + zzInput = YYEOF; + break zzForAction; + } + else { + // store back cached positions + zzCurrentPos = zzCurrentPosL; + zzMarkedPos = zzMarkedPosL; + boolean eof = zzRefill(); + // get translated positions and possibly new buffer + zzCurrentPosL = zzCurrentPos; + zzMarkedPosL = zzMarkedPos; + zzBufferL = zzBuffer; + zzEndReadL = zzEndRead; + if (eof) { + zzInput = YYEOF; + break zzForAction; + } + else { + zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); + } + } + int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; + if (zzNext == -1) break zzForAction; + zzState = zzNext; + + int zzAttributes = zzAttrL[zzState]; + if ( (zzAttributes & 1) == 1 ) { + zzAction = zzState; + zzMarkedPosL = zzCurrentPosL; + if ( (zzAttributes & 8) == 8 ) break zzForAction; + } + + } + } + + // store back cached position + zzMarkedPos = zzMarkedPosL; + + switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { + case 2: + { return JavaTokenType.WHITE_SPACE; + } + case 6: break; + case 5: + { return JavaTokenType.DOT; + } + case 7: break; + case 3: + { return JavaTokenType.IDENTIFIER; + } + case 8: break; + case 4: + { return JavaTokenType.END_OF_LINE_COMMENT; + } + case 9: break; + case 1: + { return JavaTokenType.BAD_CHARACTER; + } + case 10: break; + default: + if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { + zzAtEOF = true; + zzDoEOF(); + return null; + } + else { + zzScanError(ZZ_NO_MATCH); + } + } + } + } + + +} diff --git a/java/java-impl/src/com/intellij/spi/psi/SPIFile.java b/java/java-impl/src/com/intellij/spi/psi/SPIFile.java new file mode 100644 index 000000000000..9f1e8106878a --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/psi/SPIFile.java @@ -0,0 +1,97 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi.psi; + +import com.intellij.extapi.psi.PsiFileBase; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.*; +import com.intellij.psi.util.ClassUtil; +import com.intellij.spi.SPIFileType; +import com.intellij.lang.spi.SPILanguage; +import com.intellij.util.ArrayUtil; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * User: anna + */ +public class SPIFile extends PsiFileBase { + public SPIFile(@NotNull FileViewProvider viewProvider) { + super(viewProvider, SPILanguage.INSTANCE); + } + + @Override + public PsiReference getReference() { + return new SPIFileName2ClassReference(this, ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() { + @Override + public PsiClass compute() { + return ClassUtil.findPsiClass(getManager(), getName(), null, true, getResolveScope()); + } + })); + } + + @NotNull + @Override + public FileType getFileType() { + return SPIFileType.INSTANCE; + } + + private static class SPIFileName2ClassReference extends PsiReferenceBase<PsiFile> { + private final PsiClass myClass; + + public SPIFileName2ClassReference(PsiFile file, PsiClass aClass) { + super(file, new TextRange(0, 0), false); + myClass = aClass; + } + + @Nullable + @Override + public PsiElement resolve() { + return myClass; + } + + @Override + public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { + final String className = ClassUtil.getJVMClassName(myClass); + if (className != null) { + final String newFileName = className.substring(0, className.lastIndexOf(myClass.getName())) + newElementName; + return getElement().setName(newFileName); + } + return getElement(); + } + + @Override + public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { + if (element instanceof PsiClass) { + final String className = ClassUtil.getJVMClassName((PsiClass)element); + if (className != null) { + return getElement().setName(className); + } + } + return getElement(); + } + + @NotNull + @Override + public Object[] getVariants() { + return ArrayUtil.EMPTY_OBJECT_ARRAY; + } + } +} diff --git a/java/java-impl/src/com/intellij/spi/psi/SPIProviderElement.java b/java/java-impl/src/com/intellij/spi/psi/SPIProviderElement.java new file mode 100644 index 000000000000..17c47b0ffbcc --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/psi/SPIProviderElement.java @@ -0,0 +1,127 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi.psi; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.*; +import com.intellij.psi.infos.ClassCandidateInfo; +import com.intellij.psi.scope.PsiScopeProcessor; +import com.intellij.psi.util.ClassUtil; +import com.intellij.spi.SPIFileType; +import com.intellij.util.ArrayUtil; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * User: anna + */ +public class SPIProviderElement extends ASTWrapperPsiElement implements PsiJavaReference { + public SPIProviderElement(ASTNode node) { + super(node); + } + + @Override + public void processVariants(PsiScopeProcessor processor) { + } + + @NotNull + @Override + public JavaResolveResult advancedResolve(boolean incompleteCode) { + final PsiElement resolve = resolve(); + if (resolve instanceof PsiClass) { + return new ClassCandidateInfo(resolve, PsiSubstitutor.EMPTY); + } + return JavaResolveResult.EMPTY; + } + + @NotNull + @Override + public JavaResolveResult[] multiResolve(boolean incompleteCode) { + final PsiElement resolve = resolve(); + if (resolve instanceof PsiClass) { + return new JavaResolveResult[]{new ClassCandidateInfo(resolve, PsiSubstitutor.EMPTY)}; + } + return JavaResolveResult.EMPTY_ARRAY; + } + + @Override + public PsiElement getElement() { + return this; + } + + @Override + public TextRange getRangeInElement() { + return new TextRange(0, getTextLength()); + } + + @Nullable + @Override + public PsiElement resolve() { + return ClassUtil.findPsiClass(getManager(), getText(), null, true, getResolveScope()); + } + + @NotNull + @Override + public String getCanonicalText() { + return getText(); + } + + @Override + public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { + final SPIProvidersElementList firstChild = + (SPIProvidersElementList)PsiFileFactory.getInstance(getProject()) + .createFileFromText("spi_dummy", SPIFileType.INSTANCE, newElementName).getFirstChild(); + return replace(firstChild.getElements().get(0)); + } + + @Override + public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { + if (element instanceof PsiClass) { + final String className = ClassUtil.getJVMClassName((PsiClass)element); + if (className != null) { + return handleElementRename(className); + } + } + return null; + } + + @Override + public boolean isReferenceTo(PsiElement element) { + if (element instanceof PsiClass) { + return getText().equals(ClassUtil.getJVMClassName((PsiClass)element)); + } + return false; + } + + @NotNull + @Override + public Object[] getVariants() { + return ArrayUtil.EMPTY_OBJECT_ARRAY; + } + + @Override + public PsiReference getReference() { + return this; + } + + @Override + public boolean isSoft() { + return false; + } +} diff --git a/java/java-impl/src/com/intellij/spi/psi/SPIProvidersElementList.java b/java/java-impl/src/com/intellij/spi/psi/SPIProvidersElementList.java new file mode 100644 index 000000000000..75cc44cb700f --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/psi/SPIProvidersElementList.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.spi.psi; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.spi.parsing.SPIElementType; +import com.intellij.spi.parsing.SPIElementTypes; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * User: anna + */ +public class SPIProvidersElementList extends ASTWrapperPsiElement { + public SPIProvidersElementList(@NotNull ASTNode node) { + super(node); + } + + public List<SPIProviderElement> getElements() { + return findChildrenByType(SPIElementTypes.PROVIDER); + } +} |