diff options
Diffstat (limited to 'java')
167 files changed, 4305 insertions, 1360 deletions
diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 8a1ce68f8ba8..9139b750c25b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -18,7 +18,7 @@ package com.intellij.compiler.server; import com.intellij.ProjectTopics; import com.intellij.compiler.CompilerWorkspaceConfiguration; import com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration; -import com.intellij.compiler.server.impl.CompileServerClasspathManager; +import com.intellij.compiler.server.impl.BuildProcessClasspathManager; import com.intellij.execution.ExecutionAdapter; import com.intellij.execution.ExecutionException; import com.intellij.execution.ExecutionManager; @@ -152,7 +152,7 @@ public class BuildManager implements ApplicationComponent{ private final Map<RequestFuture, Project> myAutomakeFutures = new HashMap<RequestFuture, Project>(); private final Map<String, RequestFuture> myBuildsInProgress = Collections.synchronizedMap(new HashMap<String, RequestFuture>()); - private final CompileServerClasspathManager myClasspathManager = new CompileServerClasspathManager(); + private final BuildProcessClasspathManager myClasspathManager = new BuildProcessClasspathManager(); private final Executor myPooledThreadExecutor = new PooledThreadExecutor(); private final SequentialTaskExecutor myRequestsProcessor = new SequentialTaskExecutor(myPooledThreadExecutor); private final Map<String, ProjectData> myProjectDataMap = Collections.synchronizedMap(new HashMap<String, ProjectData>()); @@ -843,9 +843,14 @@ public class BuildManager implements ApplicationComponent{ workDirectory.mkdirs(); cmdLine.addParameter("-Djava.io.tmpdir=" + FileUtil.toSystemIndependentName(workDirectory.getPath()) + "/" + TEMP_DIR_NAME); + for (BuildProcessParametersProvider provider : project.getExtensions(BuildProcessParametersProvider.EP_NAME)) { + final List<String> args = provider.getVMArguments(); + cmdLine.addParameters(args); + } + final List<String> cp = ClasspathBootstrap.getBuildProcessApplicationClasspath(); cp.add(compilerPath); - cp.addAll(myClasspathManager.getCompileServerPluginsClasspath(project)); + cp.addAll(myClasspathManager.getBuildProcessPluginsClasspath(project)); if (isProfilingMode) { cp.add(new File(workDirectory, "yjp-controller-api-redist.jar").getPath()); cmdLine.addParameter("-agentlib:yjpagent=disablej2ee,disablealloc,sessionname=ExternalBuild"); diff --git a/java/compiler/impl/src/com/intellij/compiler/server/CompileServerPathProvider.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildProcessParametersProvider.java index f4f2bb446f8e..434633f3da47 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/CompileServerPathProvider.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildProcessParametersProvider.java @@ -18,13 +18,21 @@ package com.intellij.compiler.server; import com.intellij.openapi.extensions.ExtensionPointName; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.List; /** - * Project-level extension points to dynamically vary classpath of external build process. + * Project-level extension point to dynamically vary build process parameters like classpath, bootclasspath and JVM arguments. */ -public interface CompileServerPathProvider { - ExtensionPointName<CompileServerPathProvider> EP_NAME = ExtensionPointName.create("com.intellij.compileServer.pathProvider"); +public abstract class BuildProcessParametersProvider { + public static final ExtensionPointName<BuildProcessParametersProvider> EP_NAME = ExtensionPointName.create("com.intellij.buildProcess.parametersProvider"); - @NotNull List<String> getClassPath(); + public @NotNull List<String> getClassPath() { + return Collections.emptyList(); + } + + public @NotNull List<String> getVMArguments() { + return Collections.emptyList(); + } + } diff --git a/java/compiler/impl/src/com/intellij/compiler/server/impl/CompileServerClasspathManager.java b/java/compiler/impl/src/com/intellij/compiler/server/impl/BuildProcessClasspathManager.java index 508227014753..076e7e09b8d3 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/impl/CompileServerClasspathManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/impl/BuildProcessClasspathManager.java @@ -15,7 +15,7 @@ */ package com.intellij.compiler.server.impl; -import com.intellij.compiler.server.CompileServerPathProvider; +import com.intellij.compiler.server.BuildProcessParametersProvider; import com.intellij.compiler.server.CompileServerPlugin; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; @@ -35,12 +35,12 @@ import java.util.List; /** * @author nik */ -public class CompileServerClasspathManager { - private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.server.impl.CompileServerClasspathManager"); +public class BuildProcessClasspathManager { + private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.server.impl.BuildProcessClasspathManager"); private List<String> myCompileServerPluginsClasspath; - public List<String> getCompileServerPluginsClasspath(Project project) { + public List<String> getBuildProcessPluginsClasspath(Project project) { List<String> staticClasspath = getStaticClasspath(); List<String> dynamicClasspath = getDynamicClasspath(project); @@ -131,8 +131,8 @@ public class CompileServerClasspathManager { } private static List<String> getDynamicClasspath(Project project) { - List<String> classpath = ContainerUtil.newArrayList(); - for (CompileServerPathProvider provider : project.getExtensions(CompileServerPathProvider.EP_NAME)) { + final List<String> classpath = ContainerUtil.newArrayList(); + for (BuildProcessParametersProvider provider : project.getExtensions(BuildProcessParametersProvider.EP_NAME)) { classpath.addAll(provider.getClassPath()); } return classpath; diff --git a/java/compiler/instrumentation-util/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java b/java/compiler/instrumentation-util/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java index 77bc53816847..68098f14ef79 100644 --- a/java/compiler/instrumentation-util/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java +++ b/java/compiler/instrumentation-util/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java @@ -34,6 +34,8 @@ public class NotNullVerifyingInstrumenter extends ClassVisitor implements Opcode private static final String CONSTRUCTOR_NAME = "<init>"; private static final String EXCEPTION_INIT_SIGNATURE = "(L" + STRING_CLASS_NAME + ";)V"; + private static final String ANNOTATION_DEFAULT_METHOD = "value"; + private static final String NULL_ARG_MESSAGE = "Argument %d for @NotNull parameter of %s.%s must not be null"; private static final String NULL_RESULT_MESSAGE = "@NotNull method %s.%s must not return null"; @@ -65,25 +67,51 @@ public class NotNullVerifyingInstrumenter extends ClassVisitor implements Opcode private final List<Integer> myNotNullParams = new ArrayList<Integer>(); private int mySyntheticCount = 0; private boolean myIsNotNull = false; + private String myMessage = null; private Label myStartGeneratedCodeLabel; public AnnotationVisitor visitParameterAnnotation(final int parameter, final String anno, final boolean visible) { - final AnnotationVisitor av = mv.visitParameterAnnotation(parameter, anno, visible); + AnnotationVisitor av = mv.visitParameterAnnotation(parameter, anno, visible); if (isReferenceType(args[parameter]) && anno.equals(NOT_NULL_TYPE)) { myNotNullParams.add(new Integer(parameter)); + av = new AnnotationVisitor(Opcodes.ASM4, av) { + @Override + public void visit(String methodName, Object o) { + if(ANNOTATION_DEFAULT_METHOD.equals(methodName)) { + String message = (String) o; + if(!message.isEmpty()) { + myMessage = message; + } + } + super.visit(methodName, o); + } + }; } else if (anno.equals(SYNTHETIC_TYPE)) { // see http://forge.ow2.org/tracker/?aid=307392&group_id=23&atid=100023&func=detail mySyntheticCount++; } + return av; } @Override public AnnotationVisitor visitAnnotation(String anno, boolean isRuntime) { - final AnnotationVisitor av = mv.visitAnnotation(anno, isRuntime); + AnnotationVisitor av = mv.visitAnnotation(anno, isRuntime); if (isReferenceType(returnType) && anno.equals(NOT_NULL_TYPE)) { myIsNotNull = true; + av = new AnnotationVisitor(Opcodes.ASM4, av) { + @Override + public void visit(String methodName, Object o) { + if(ANNOTATION_DEFAULT_METHOD.equals(methodName)) { + String message = (String) o; + if(!message.isEmpty()) { + myMessage = message; + } + } + super.visit(methodName, o); + } + }; } return av; @@ -105,7 +133,7 @@ public class NotNullVerifyingInstrumenter extends ClassVisitor implements Opcode Label end = new Label(); mv.visitJumpInsn(IFNONNULL, end); - generateThrow(IAE_CLASS_NAME, String.format(NULL_ARG_MESSAGE, param - mySyntheticCount, myClassName, name), end); + generateThrow(IAE_CLASS_NAME, myMessage == null ? String.format(NULL_ARG_MESSAGE, param - mySyntheticCount, myClassName, name) : myMessage, end); } } @@ -124,7 +152,7 @@ public class NotNullVerifyingInstrumenter extends ClassVisitor implements Opcode mv.visitInsn(DUP); final Label skipLabel = new Label(); mv.visitJumpInsn(IFNONNULL, skipLabel); - generateThrow(ISE_CLASS_NAME, String.format(NULL_RESULT_MESSAGE, myClassName, name), skipLabel); + generateThrow(ISE_CLASS_NAME, myMessage == null ? String.format(NULL_RESULT_MESSAGE, myClassName, name) : myMessage, skipLabel); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreeRenderer.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreeRenderer.java index e515575f727f..857443f456c9 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreeRenderer.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreeRenderer.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. @@ -21,7 +21,7 @@ import com.intellij.debugger.impl.DebuggerUtilsEx; import com.intellij.debugger.ui.impl.watch.*; import com.intellij.debugger.ui.tree.ValueDescriptor; import com.intellij.icons.AllIcons; -import com.intellij.openapi.editor.SyntaxHighlighterColors; +import com.intellij.ide.highlighter.JavaHighlightingColors; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.text.StringUtil; @@ -193,14 +193,14 @@ public class DebuggerTreeRenderer extends ColoredTreeCellRenderer { valueLabelAttribs = XDebuggerUIConstants.CHANGED_VALUE_ATTRIBUTES; } else { - TextAttributes highlightingAttribs = null; + TextAttributes attributes = null; if (valueDescriptor.isNull()){ - highlightingAttribs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(SyntaxHighlighterColors.KEYWORD); + attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(JavaHighlightingColors.KEYWORD); } else if (valueDescriptor.isString()) { - highlightingAttribs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(SyntaxHighlighterColors.STRING); + attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(JavaHighlightingColors.STRING); } - valueLabelAttribs = highlightingAttribs != null? SimpleTextAttributes.fromTextAttributes(highlightingAttribs) : DEFAULT_ATTRIBUTES; + valueLabelAttribs = attributes != null? SimpleTextAttributes.fromTextAttributes(attributes) : DEFAULT_ATTRIBUTES; } final EvaluateException exception = descriptor.getEvaluateException(); @@ -248,7 +248,7 @@ public class DebuggerTreeRenderer extends ColoredTreeCellRenderer { } if (escapeAttribs == null) { // lazy init - final TextAttributes fromHighlighter = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(SyntaxHighlighterColors.VALID_STRING_ESCAPE); + TextAttributes fromHighlighter = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(JavaHighlightingColors.VALID_STRING_ESCAPE); if (fromHighlighter != null) { escapeAttribs = SimpleTextAttributes.fromTextAttributes(fromHighlighter); } diff --git a/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java b/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java index a460c8498490..7bf07bf64518 100644 --- a/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java +++ b/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java @@ -25,6 +25,7 @@ import com.intellij.execution.testframework.JavaAwareFilter; import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComponentContainer; +import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.NotNull; public class JavaRerunFailedTestsAction extends AbstractRerunFailedTestsAction { @@ -35,8 +36,8 @@ public class JavaRerunFailedTestsAction extends AbstractRerunFailedTestsAction { @NotNull @Override - protected Filter getFilter(Project project) { - return Filter.FAILED_OR_INTERRUPTED.and(JavaAwareFilter.METHOD(project)); + protected Filter getFilter(Project project, GlobalSearchScope searchScope) { + return Filter.FAILED_OR_INTERRUPTED.and(JavaAwareFilter.METHOD(project, searchScope)); } } diff --git a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java index fb674a0dba51..a10102eabc68 100644 --- a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java +++ b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.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. @@ -157,6 +157,7 @@ public class JUnitUtil { @Nullable private static PsiClass getTestCaseClassOrNull(final Location<?> location) { final Location<PsiClass> ancestorOrSelf = location.getAncestorOrSelf(PsiClass.class); + if (ancestorOrSelf == null) return null; final PsiClass aClass = ancestorOrSelf.getPsiElement(); Module module = JavaExecutionUtil.findModule(aClass); if (module == null) return null; diff --git a/java/execution/impl/src/com/intellij/execution/testframework/JavaAwareFilter.java b/java/execution/impl/src/com/intellij/execution/testframework/JavaAwareFilter.java index a98c7bde854b..86463e06adff 100644 --- a/java/execution/impl/src/com/intellij/execution/testframework/JavaAwareFilter.java +++ b/java/execution/impl/src/com/intellij/execution/testframework/JavaAwareFilter.java @@ -25,15 +25,16 @@ import com.intellij.execution.PsiLocation; import com.intellij.execution.junit2.info.MethodLocation; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiMethod; +import com.intellij.psi.search.GlobalSearchScope; public class JavaAwareFilter { private JavaAwareFilter() { } - public static Filter METHOD(final Project project) { + public static Filter METHOD(final Project project, final GlobalSearchScope searchScope) { return new Filter() { public boolean shouldAccept(final AbstractTestProxy test) { - final Location location = test.getLocation(project); + final Location location = test.getLocation(project, searchScope); if (location instanceof MethodLocation) return true; if (location instanceof PsiLocation && location.getPsiElement() instanceof PsiMethod) return true; return false; diff --git a/java/execution/impl/src/com/intellij/execution/util/JavaParametersUtil.java b/java/execution/impl/src/com/intellij/execution/util/JavaParametersUtil.java index 22dc20750689..4433413eaf35 100644 --- a/java/execution/impl/src/com/intellij/execution/util/JavaParametersUtil.java +++ b/java/execution/impl/src/com/intellij/execution/util/JavaParametersUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -34,6 +34,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiFile; +import org.intellij.lang.annotations.MagicConstant; import java.util.List; import java.util.Map; @@ -94,7 +95,7 @@ public class JavaParametersUtil { public static void configureModule(final RunConfigurationModule runConfigurationModule, final JavaParameters parameters, - final int classPathType, + @MagicConstant(valuesFromClass = JavaParameters.class) final int classPathType, final String jreHome) throws CantRunException { Module module = runConfigurationModule.getModule(); if (module == null) { @@ -103,11 +104,11 @@ public class JavaParametersUtil { configureModule(module, parameters, classPathType, jreHome); } - public static void configureModule(Module module, JavaParameters parameters, int classPathType, String jreHome) throws CantRunException { + public static void configureModule(Module module, JavaParameters parameters, @MagicConstant(valuesFromClass = JavaParameters.class) int classPathType, String jreHome) throws CantRunException { parameters.configureByModule(module, classPathType, createModuleJdk(module, jreHome)); } - public static void configureProject(Project project, final JavaParameters parameters, final int classPathType, final String jreHome) + public static void configureProject(Project project, final JavaParameters parameters, @MagicConstant(valuesFromClass = JavaParameters.class) final int classPathType, final String jreHome) throws CantRunException { parameters.configureByProject(project, classPathType, createProjectJdk(project, jreHome)); } diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java index 08f41d249a6b..99bb06703f0a 100644 --- a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java +++ b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.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. @@ -25,6 +25,7 @@ import com.intellij.openapi.roots.*; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.encoding.EncodingProjectManager; import com.intellij.util.NotNullFunction; +import org.intellij.lang.annotations.MagicConstant; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -53,7 +54,9 @@ public class JavaParameters extends SimpleJavaParameters { public static final int JDK_AND_CLASSES_AND_TESTS = JDK_ONLY | CLASSES_ONLY | TESTS_ONLY; public static final int CLASSES_AND_TESTS = CLASSES_ONLY | TESTS_ONLY; - public void configureByModule(final Module module, final int classPathType, final Sdk jdk) throws CantRunException { + public void configureByModule(final Module module, + @MagicConstant(valuesFromClass = JavaParameters.class) final int classPathType, + final Sdk jdk) throws CantRunException { if ((classPathType & JDK_ONLY) != 0) { if (jdk == null) { throw CantRunException.noJdkConfigured(); @@ -70,7 +73,7 @@ public class JavaParameters extends SimpleJavaParameters { } @Nullable - private static NotNullFunction<OrderEntry, VirtualFile[]> computeRootProvider(int classPathType, final Sdk jdk) { + private static NotNullFunction<OrderEntry, VirtualFile[]> computeRootProvider(@MagicConstant(valuesFromClass = JavaParameters.class) int classPathType, final Sdk jdk) { return (classPathType & JDK_ONLY) == 0 ? null : new NotNullFunction<OrderEntry, VirtualFile[]>() { @NotNull @Override @@ -90,7 +93,8 @@ public class JavaParameters extends SimpleJavaParameters { } } - public void configureByModule(final Module module, final int classPathType) throws CantRunException { + public void configureByModule(final Module module, + @MagicConstant(valuesFromClass = JavaParameters.class) final int classPathType) throws CantRunException { configureByModule(module, classPathType, getModuleJdk(module)); } @@ -106,7 +110,7 @@ public class JavaParameters extends SimpleJavaParameters { return jdk; } - public void configureByProject(final Project project, final int classPathType, final Sdk jdk) throws CantRunException { + public void configureByProject(final Project project, @MagicConstant(valuesFromClass = JavaParameters.class) final int classPathType, final Sdk jdk) throws CantRunException { if ((classPathType & JDK_ONLY) != 0) { if (jdk == null) { throw CantRunException.noJdkConfigured(); @@ -121,7 +125,7 @@ public class JavaParameters extends SimpleJavaParameters { configureEnumerator(OrderEnumerator.orderEntries(project).runtimeOnly(), classPathType, jdk).collectPaths(getClassPath()); } - private static OrderRootsEnumerator configureEnumerator(OrderEnumerator enumerator, int classPathType, Sdk jdk) { + private static OrderRootsEnumerator configureEnumerator(OrderEnumerator enumerator, @MagicConstant(valuesFromClass = JavaParameters.class) int classPathType, Sdk jdk) { if ((classPathType & JDK_ONLY) == 0) { enumerator = enumerator.withoutSdk(); } diff --git a/java/idea-ui/src/com/intellij/framework/FrameworkGroupVersion.java b/java/idea-ui/src/com/intellij/framework/FrameworkGroupVersion.java deleted file mode 100644 index ea0f3102c3d2..000000000000 --- a/java/idea-ui/src/com/intellij/framework/FrameworkGroupVersion.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.intellij.framework; - -import org.jetbrains.annotations.NotNull; - -/** - * @author nik - */ -public interface FrameworkGroupVersion { - @NotNull String getId(); - @NotNull String getPresentableName(); -} diff --git a/java/idea-ui/src/com/intellij/framework/FrameworkTypeEx.java b/java/idea-ui/src/com/intellij/framework/FrameworkTypeEx.java index 02c0298a7331..b13ec41f4ba8 100644 --- a/java/idea-ui/src/com/intellij/framework/FrameworkTypeEx.java +++ b/java/idea-ui/src/com/intellij/framework/FrameworkTypeEx.java @@ -20,6 +20,9 @@ import com.intellij.openapi.extensions.ExtensionPointName; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; +import java.util.List; + /** * @author nik */ @@ -42,4 +45,8 @@ public abstract class FrameworkTypeEx extends FrameworkType { public String getUnderlyingFrameworkTypeId() { return null; } + + public <V extends FrameworkVersion> List<V> getVersions() { + return Collections.emptyList(); + } } diff --git a/java/idea-ui/src/com/intellij/framework/addSupport/FrameworkSupportInModuleProvider.java b/java/idea-ui/src/com/intellij/framework/addSupport/FrameworkSupportInModuleProvider.java index 190cee5e3394..fd043b14fc31 100644 --- a/java/idea-ui/src/com/intellij/framework/addSupport/FrameworkSupportInModuleProvider.java +++ b/java/idea-ui/src/com/intellij/framework/addSupport/FrameworkSupportInModuleProvider.java @@ -46,4 +46,8 @@ public abstract class FrameworkSupportInModuleProvider { public boolean canAddSupport(@NotNull Module module, @NotNull FacetsProvider facetsProvider) { return !isSupportAlreadyAdded(module, facetsProvider); } + + public String getPresentableName() { + return getFrameworkType().getPresentableName(); + } } diff --git a/java/idea-ui/src/com/intellij/framework/addSupport/FrameworkVersionListener.java b/java/idea-ui/src/com/intellij/framework/addSupport/FrameworkVersionListener.java new file mode 100644 index 000000000000..78aea931c511 --- /dev/null +++ b/java/idea-ui/src/com/intellij/framework/addSupport/FrameworkVersionListener.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.framework.addSupport; + +import com.intellij.framework.FrameworkVersion; +import org.jetbrains.annotations.NotNull; + +import java.util.EventListener; + +/** + * @author nik + */ +public interface FrameworkVersionListener extends EventListener { + void versionChanged(@NotNull FrameworkVersion version); +} diff --git a/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java index dbaa6d019ee8..c02599766272 100644 --- a/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java +++ b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java @@ -17,8 +17,8 @@ package com.intellij.framework.library.impl; import com.intellij.facet.frameworks.beans.Artifact; import com.intellij.facet.frameworks.beans.RequiredFrameworkVersion; -import com.intellij.framework.FrameworkGroup; -import com.intellij.framework.FrameworkGroupVersion; +import com.intellij.framework.FrameworkAvailabilityCondition; +import com.intellij.framework.FrameworkVersion; import com.intellij.framework.library.*; import com.intellij.ide.util.frameworkSupport.CustomLibraryDescriptionImpl; import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel; @@ -44,12 +44,12 @@ public class DownloadableLibraryServiceImpl extends DownloadableLibraryService { return new LibraryVersionsFetcher(groupId, localUrls) { //todo[nik] pull up this method after moving corresponding API to lang-api @NotNull - protected FrameworkAvailabilityFilter createAvailabilityFilter(Artifact version) { + protected FrameworkAvailabilityCondition createAvailabilityCondition(Artifact version) { RequiredFrameworkVersion groupVersion = version.getRequiredFrameworkVersion(); if (groupVersion != null) { - return new FrameworkLibraryAvailabilityFilter(groupVersion.myGroupId, groupVersion.myVersion); + return new FrameworkLibraryAvailabilityCondition(groupVersion.myGroupId, groupVersion.myVersion); } - return FrameworkAvailabilityFilter.ALWAYS; + return FrameworkAvailabilityCondition.ALWAYS_TRUE; } }; } @@ -70,25 +70,19 @@ public class DownloadableLibraryServiceImpl extends DownloadableLibraryService { return new DownloadableLibraryPropertiesEditor(description, editorComponent, libraryType); } - private static class FrameworkLibraryAvailabilityFilter extends FrameworkAvailabilityFilter { + private static class FrameworkLibraryAvailabilityCondition extends FrameworkAvailabilityCondition { private final String myGroupId; private final String myVersionId; - public FrameworkLibraryAvailabilityFilter(String groupId, String versionId) { + public FrameworkLibraryAvailabilityCondition(String groupId, String versionId) { myGroupId = groupId; myVersionId = versionId; } @Override - public boolean isAvailable(@NotNull FrameworkSupportModel model) { - FrameworkSupportModelBase modelBase = (FrameworkSupportModelBase)model; - for (FrameworkGroup<?> group : modelBase.getFrameworkGroups()) { - if (group.getId().equals(myGroupId)) { - FrameworkGroupVersion selectedVersion = modelBase.getSelectedVersion(group); - return selectedVersion != null && myVersionId.equals(selectedVersion.getId()); - } - } - return true; + public boolean isAvailableFor(@NotNull FrameworkSupportModel model) { + FrameworkVersion selectedVersion = ((FrameworkSupportModelBase)model).getSelectedVersion(myGroupId); + return selectedVersion != null && myVersionId.equals(selectedVersion.getId()); } } } diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java index ae8972654496..78c9c686394d 100644 --- a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/FrameworkSupportUtil.java @@ -93,7 +93,9 @@ public class FrameworkSupportUtil { @Nullable public static FrameworkSupportInModuleProvider findProvider(@NotNull String id, final List<FrameworkSupportInModuleProvider> providers) { for (FrameworkSupportInModuleProvider provider : providers) { - if (id.equals(provider.getFrameworkType().getId())) { + String frameworkId = provider.getFrameworkType().getId(); + if (id.equals(frameworkId) + || id.equals("facet:"+frameworkId)) {//we need this additional check for compatibility, e.g. id of web framework support provider was changed from 'facet:web' for 'web' return provider; } } diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java index 1adad9b94104..70a452dbb1c7 100644 --- a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java @@ -20,7 +20,7 @@ import com.intellij.facet.ui.libraries.LibraryDownloadInfo; import com.intellij.facet.ui.libraries.LibraryInfo; import com.intellij.framework.library.DownloadableLibraryDescription; import com.intellij.framework.library.DownloadableLibraryFileDescription; -import com.intellij.framework.library.FrameworkAvailabilityFilter; +import com.intellij.framework.FrameworkAvailabilityCondition; import com.intellij.framework.library.FrameworkLibraryVersion; import com.intellij.framework.library.impl.DownloadableLibraryDescriptionImpl; import com.intellij.framework.library.impl.DownloadableLibraryFileDescriptionImpl; @@ -62,7 +62,7 @@ public class OldCustomLibraryDescription extends CustomLibraryDescriptionBase { downloadingInfo.getFileNameSuffix(), null, null, false)); } } - libraryVersions.add(new FrameworkLibraryVersionImpl(version.getVersionName(), FrameworkAvailabilityFilter.ALWAYS, downloads, version.getLibraryName())); + libraryVersions.add(new FrameworkLibraryVersionImpl(version.getVersionName(), FrameworkAvailabilityCondition.ALWAYS_TRUE, downloads, version.getLibraryName())); } myDownloadableDescription = !libraryVersions.isEmpty() ? new DownloadableLibraryDescriptionImpl(libraryVersions) : null; } diff --git a/java/idea-ui/src/com/intellij/ide/util/importProject/JavaModuleInsight.java b/java/idea-ui/src/com/intellij/ide/util/importProject/JavaModuleInsight.java index b7b9f7c9d594..c59652709c46 100644 --- a/java/idea-ui/src/com/intellij/ide/util/importProject/JavaModuleInsight.java +++ b/java/idea-ui/src/com/intellij/ide/util/importProject/JavaModuleInsight.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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.ide.util.importProject; import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot; import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot; import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil; -import com.intellij.lexer.JavaLexer; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.lexer.Lexer; import com.intellij.openapi.module.StdModuleTypes; import com.intellij.openapi.progress.ProgressIndicator; @@ -38,13 +38,13 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class JavaModuleInsight extends ModuleInsight { - private final JavaLexer myLexer; + private final Lexer myLexer; public JavaModuleInsight(@Nullable final ProgressIndicator progress, Set<String> existingModuleNames, Set<String> existingProjectLibraryNames) { super(progress, existingModuleNames, existingProjectLibraryNames); - myLexer = new JavaLexer(LanguageLevel.JDK_1_5); + myLexer = JavaParserDefinition.createLexer(LanguageLevel.JDK_1_5); } @Override diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/AddSupportForFrameworksPanel.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/AddSupportForFrameworksPanel.java index 7cccf0aa1b3c..dcd8af3db567 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/AddSupportForFrameworksPanel.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/AddSupportForFrameworksPanel.java @@ -151,6 +151,7 @@ public class AddSupportForFrameworksPanel implements Disposable { FrameworkGroup<?> group = ((FrameworkGroupNode)node).getGroup(); initializeGroupPanel(group); showCard(group.getId()); + UIUtil.setEnabled(myOptionsPanel, true, true); } else { showCard(EMPTY_CARD); @@ -159,7 +160,7 @@ public class AddSupportForFrameworksPanel implements Disposable { private void initializeGroupPanel(FrameworkGroup<?> group) { if (!myInitializedGroupPanels.containsKey(group)) { - FrameworkGroupOptionsComponent component = new FrameworkGroupOptionsComponent(group, myModel); + FrameworkVersionComponent component = new FrameworkVersionComponent(myModel, group.getId(), group.getGroupVersions()); myInitializedGroupPanels.put(group, component.getMainPanel()); myOptionsPanel.add(group.getId(), component.getMainPanel()); } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkGroupNode.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkGroupNode.java index 807110f4463c..de77e6109f21 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkGroupNode.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkGroupNode.java @@ -31,4 +31,10 @@ public class FrameworkGroupNode extends FrameworkSupportNodeBase { public Icon getIcon() { return myGroup.getIcon(); } + + @NotNull + @Override + public String getId() { + return myGroup.getId(); + } } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkGroupOptionsComponent.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkGroupOptionsComponent.java deleted file mode 100644 index b83dd0c3c439..000000000000 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkGroupOptionsComponent.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.intellij.ide.util.newProjectWizard; - -import com.intellij.framework.FrameworkGroup; -import com.intellij.framework.FrameworkGroupVersion; -import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase; -import com.intellij.openapi.ui.ComboBox; -import com.intellij.openapi.ui.VerticalFlowLayout; -import com.intellij.ui.ListCellRendererWrapper; -import com.intellij.util.ui.FormBuilder; - -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.List; - -/** - * @author nik - */ -public class FrameworkGroupOptionsComponent { - private final JPanel myMainPanel; - - public FrameworkGroupOptionsComponent(final FrameworkGroup<?> group, final FrameworkSupportModelBase model) { - JPanel panel = new JPanel(new VerticalFlowLayout()); - List<? extends FrameworkGroupVersion> versions = group.getGroupVersions(); - if (!versions.isEmpty()) { - final ComboBox versionsBox = new ComboBox(); - versionsBox.setRenderer(new ListCellRendererWrapper<FrameworkGroupVersion>() { - @Override - public void customize(JList list, FrameworkGroupVersion value, int index, boolean selected, boolean hasFocus) { - setText(value != null ? value.getPresentableName() : ""); - } - }); - versionsBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - model.setSelectedVersion(group, (FrameworkGroupVersion)versionsBox.getSelectedItem()); - } - }); - for (FrameworkGroupVersion version : versions) { - versionsBox.addItem(version); - } - FrameworkGroupVersion latestVersion = versions.get(versions.size() - 1); - versionsBox.setSelectedItem(latestVersion); - model.setSelectedVersion(group, latestVersion); - panel.add(FormBuilder.createFormBuilder().addLabeledComponent("Version:", versionsBox).getPanel()); - } - myMainPanel = panel; - } - - public JPanel getMainPanel() { - return myMainPanel; - } -} diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java index 84d7280f5b5a..917462658d0b 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java @@ -56,7 +56,7 @@ public class FrameworkSupportNode extends FrameworkSupportNodeBase { @NotNull public String getTitle() { - return myProvider.getFrameworkType().getPresentableName(); + return myProvider.getPresentableName(); } @NotNull @@ -64,4 +64,10 @@ public class FrameworkSupportNode extends FrameworkSupportNodeBase { public Icon getIcon() { return myProvider.getFrameworkType().getIcon(); } + + @NotNull + @Override + public String getId() { + return myProvider.getFrameworkType().getId(); + } } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNodeBase.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNodeBase.java index c4632c0bf93f..6097897d74ce 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNodeBase.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNodeBase.java @@ -48,6 +48,9 @@ public abstract class FrameworkSupportNodeBase extends CheckedTreeNode { public abstract Icon getIcon(); @NotNull + public abstract String getId(); + + @NotNull public List<FrameworkSupportNodeBase> getChildren() { return children != null ? children : Collections.<FrameworkSupportNodeBase>emptyList(); } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java index 0f84009320e7..d83950152b5f 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java @@ -17,6 +17,7 @@ package com.intellij.ide.util.newProjectWizard; import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings; import com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel; +import com.intellij.framework.FrameworkVersion; import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable; import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider; import com.intellij.framework.library.FrameworkLibraryVersion; @@ -37,6 +38,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.List; /** * @author nik @@ -44,6 +46,7 @@ import java.awt.*; public class FrameworkSupportOptionsComponent { private final JPanel myMainPanel; private final FrameworkSupportModelBase myModel; + private FrameworkVersionComponent myFrameworkVersionComponent; private LibraryCompositionSettings myLibraryCompositionSettings; private LibraryOptionsPanel myLibraryOptionsPanel; private final FrameworkSupportInModuleConfigurable myConfigurable; @@ -60,13 +63,18 @@ public class FrameworkSupportOptionsComponent { layout.setVerticalFill(true); myMainPanel = new JPanel(layout); myModel.registerOptionsComponent(provider, this); + List<FrameworkVersion> versions = provider.getFrameworkType().getVersions(); + if (!versions.isEmpty()) { + myFrameworkVersionComponent = new FrameworkVersionComponent(model, provider.getFrameworkType().getId(), versions); + myMainPanel.add(myFrameworkVersionComponent.getMainPanel()); + } final JComponent component = myConfigurable.createComponent(); if (component != null) { myMainPanel.add(component); } - final boolean addSeparator = component != null; + final boolean addSeparator = component != null || myFrameworkVersionComponent != null; myLibraryOptionsPanelWrapper = new JPanel(new BorderLayout()); myMainPanel.add(myLibraryOptionsPanelWrapper); if (myConfigurable instanceof OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) { @@ -107,16 +115,23 @@ public class FrameworkSupportOptionsComponent { } } + public void updateVersionsComponent() { + if (myFrameworkVersionComponent != null) { + myFrameworkVersionComponent.updateVersionsList(); + } + } + + private FrameworkLibraryVersionFilter createLibraryVersionFilter() { return new FrameworkLibraryVersionFilter() { @Override public boolean isAccepted(@NotNull FrameworkLibraryVersion version) { - return myConfigurable.getLibraryVersionFilter().isAccepted(version) && ((FrameworkLibraryVersionImpl)version).getAvailabilityFilter().isAvailable(myModel); + return myConfigurable.getLibraryVersionFilter().isAccepted(version) && ((FrameworkLibraryVersionImpl)version).getAvailabilityCondition().isAvailableFor( + myModel); } }; } - public JPanel getMainPanel() { return myMainPanel; } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkVersionComponent.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkVersionComponent.java new file mode 100644 index 000000000000..e424caffe699 --- /dev/null +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkVersionComponent.java @@ -0,0 +1,87 @@ +package com.intellij.ide.util.newProjectWizard; + +import com.intellij.framework.FrameworkVersion; +import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase; +import com.intellij.openapi.ui.ComboBox; +import com.intellij.openapi.ui.VerticalFlowLayout; +import com.intellij.ui.ListCellRendererWrapper; +import com.intellij.util.ui.FormBuilder; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + +/** + * @author nik + */ +public class FrameworkVersionComponent { + private final JPanel myMainPanel; + private final FrameworkSupportModelBase myModel; + private final List<? extends FrameworkVersion> myAllVersions; + private final JPanel myVersionsPanel; + private final ComboBox myVersionsBox; + private final String myFrameworkOrGroupId; + + public FrameworkVersionComponent(final FrameworkSupportModelBase model, final String frameworkOrGroupId, + final List<? extends FrameworkVersion> versions_) { + myModel = model; + myAllVersions = versions_; + myMainPanel = new JPanel(new VerticalFlowLayout()); + myFrameworkOrGroupId = frameworkOrGroupId; + myVersionsBox = new ComboBox(); + myVersionsBox.setRenderer(new ListCellRendererWrapper<FrameworkVersion>() { + @Override + public void customize(JList list, FrameworkVersion value, int index, boolean selected, boolean hasFocus) { + setText(value != null ? value.getPresentableName() : ""); + } + }); + myVersionsBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + FrameworkVersion selectedVersion = getSelectedVersion(); + if (selectedVersion != null) { + model.setSelectedVersion(frameworkOrGroupId, selectedVersion); + } + } + }); + + myVersionsPanel = FormBuilder.createFormBuilder().addLabeledComponent("Version:", myVersionsBox).getPanel(); + myMainPanel.add(myVersionsPanel); + updateVersionsList(); + } + + private FrameworkVersion getSelectedVersion() { + return (FrameworkVersion)myVersionsBox.getSelectedItem(); + } + + public JPanel getMainPanel() { + return myMainPanel; + } + + public void updateVersionsList() { + FrameworkVersion oldSelection = getSelectedVersion(); + List<? extends FrameworkVersion> versions = computeAvailableVersions(); + myVersionsBox.removeAllItems(); + for (FrameworkVersion version : versions) { + myVersionsBox.addItem(version); + } + myVersionsPanel.setVisible(!versions.isEmpty()); + if (!versions.isEmpty()) { + FrameworkVersion toSelect = oldSelection != null && versions.contains(oldSelection) ? oldSelection : versions.get(versions.size() - 1); + myVersionsBox.setSelectedItem(toSelect); + myModel.setSelectedVersion(myFrameworkOrGroupId, toSelect); + } + } + + private List<FrameworkVersion> computeAvailableVersions() { + List<FrameworkVersion> versions = new ArrayList<FrameworkVersion>(); + for (FrameworkVersion version : myAllVersions) { + if (version.getAvailabilityCondition().isAvailableFor(myModel)) { + versions.add(version); + } + } + return versions; + } +} diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/impl/FrameworkSupportModelBase.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/impl/FrameworkSupportModelBase.java index acfa5e8ffdfc..48a9d9297d79 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/impl/FrameworkSupportModelBase.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/impl/FrameworkSupportModelBase.java @@ -17,7 +17,9 @@ package com.intellij.ide.util.newProjectWizard.impl; import com.intellij.framework.FrameworkGroup; import com.intellij.framework.FrameworkGroupVersion; +import com.intellij.framework.FrameworkVersion; import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider; +import com.intellij.framework.addSupport.FrameworkVersionListener; import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable; import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel; import com.intellij.ide.util.frameworkSupport.FrameworkSupportModelListener; @@ -34,7 +36,6 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -46,9 +47,10 @@ public abstract class FrameworkSupportModelBase extends UserDataHolderBase imple private final ModuleBuilder myModuleBuilder; private final LibrariesContainer myLibrariesContainer; private final EventDispatcher<FrameworkSupportModelListener> myDispatcher = EventDispatcher.create(FrameworkSupportModelListener.class); + private final EventDispatcher<FrameworkVersionListener> myVersionEventDispatcher = EventDispatcher.create(FrameworkVersionListener.class); private final Map<String, FrameworkSupportNode> mySettingsMap = new HashMap<String, FrameworkSupportNode>(); private final Map<String, FrameworkSupportOptionsComponent> myOptionsComponentsMap = new HashMap<String, FrameworkSupportOptionsComponent>(); - private final Map<FrameworkGroup<?>, FrameworkGroupVersion> mySelectedVersions = new HashMap<FrameworkGroup<?>, FrameworkGroupVersion>(); + private final Map<String, FrameworkVersion> mySelectedVersions = new HashMap<String, FrameworkVersion>(); public FrameworkSupportModelBase(final @Nullable Project project, @Nullable ModuleBuilder builder, @NotNull LibrariesContainer librariesContainer) { myProject = project; @@ -89,6 +91,10 @@ public abstract class FrameworkSupportModelBase extends UserDataHolderBase imple myDispatcher.addListener(listener, parentDisposable); } + public void addFrameworkVersionListener(@NotNull FrameworkVersionListener listener, @NotNull Disposable parentDisposable) { + myVersionEventDispatcher.addListener(listener, parentDisposable); + } + public void removeFrameworkListener(@NotNull final FrameworkSupportModelListener listener) { myDispatcher.removeListener(listener); } @@ -126,34 +132,41 @@ public abstract class FrameworkSupportModelBase extends UserDataHolderBase imple return ((OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper)node.getConfigurable()).getConfigurable(); } - public void setSelectedVersion(@NotNull FrameworkGroup<?> group, @Nullable FrameworkGroupVersion version) { - FrameworkGroupVersion oldVersion = mySelectedVersions.put(group, version); + public void setSelectedVersion(@NotNull String frameworkOrGroupId, @NotNull FrameworkVersion version) { + FrameworkVersion oldVersion = mySelectedVersions.put(frameworkOrGroupId, version); if (!Comparing.equal(oldVersion, version)) { for (Map.Entry<String, FrameworkSupportNode> entry : mySettingsMap.entrySet()) { - FrameworkGroup<?> parentGroup = getParentGroup(entry.getValue()); - if (group.equals(parentGroup)) { + if (hasParentWithId(entry.getValue(), frameworkOrGroupId)) { + if (!entry.getValue().getId().equals(frameworkOrGroupId)) { + FrameworkSupportOptionsComponent component = myOptionsComponentsMap.get(entry.getKey()); + if (component != null) { + component.updateVersionsComponent(); + } + } updateFrameworkLibraryComponent(entry.getKey()); } } } + myVersionEventDispatcher.getMulticaster().versionChanged(version); } - @Nullable - private static FrameworkGroup<?> getParentGroup(final FrameworkSupportNode node) { + private static boolean hasParentWithId(final FrameworkSupportNode node, @NotNull String frameworkOrGroupId) { FrameworkSupportNodeBase current = node; - while (current instanceof FrameworkSupportNode) { + while (current != null) { + if (current.getId().equals(frameworkOrGroupId)) return true; current = current.getParentNode(); } - return current instanceof FrameworkGroupNode ? ((FrameworkGroupNode)current).getGroup() : null; + return false; } - public Collection<FrameworkGroup<?>> getFrameworkGroups() { - return mySelectedVersions.keySet(); + @Nullable + public <V extends FrameworkVersion> V getSelectedVersion(@NotNull String frameworkOrGroupId) { + return (V)mySelectedVersions.get(frameworkOrGroupId); } @Nullable public <V extends FrameworkGroupVersion> V getSelectedVersion(@NotNull FrameworkGroup<V> group) { - return (V)mySelectedVersions.get(group); + return (V)mySelectedVersions.get(group.getId()); } public void onFrameworkSelectionChanged(FrameworkSupportNode node) { diff --git a/java/idea-ui/src/com/intellij/ide/util/projectWizard/importSources/JavaSourceRootDetectionUtil.java b/java/idea-ui/src/com/intellij/ide/util/projectWizard/importSources/JavaSourceRootDetectionUtil.java index bbffb7efa215..f83a8abb1619 100644 --- a/java/idea-ui/src/com/intellij/ide/util/projectWizard/importSources/JavaSourceRootDetectionUtil.java +++ b/java/idea-ui/src/com/intellij/ide/util/projectWizard/importSources/JavaSourceRootDetectionUtil.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. @@ -16,32 +16,25 @@ package com.intellij.ide.util.projectWizard.importSources; import com.intellij.ide.util.importProject.RootDetectionProcessor; -import com.intellij.lexer.JavaLexer; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.lexer.Lexer; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.JavaTokenType; import com.intellij.psi.impl.source.tree.ElementType; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; -import com.intellij.util.NullableFunction; import com.intellij.util.StringBuilderSpinAllocator; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.text.CharArrayCharSequence; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; -import java.io.IOException; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; - public class JavaSourceRootDetectionUtil { private static final TokenSet JAVA_FILE_FIRST_TOKEN_SET = TokenSet.orSet( ElementType.MODIFIER_BIT_SET, @@ -76,10 +69,9 @@ public class JavaSourceRootDetectionUtil { return result.values(); } - @Nullable public static String getPackageName(CharSequence text) { - Lexer lexer = new JavaLexer(LanguageLevel.JDK_1_3); + Lexer lexer = JavaParserDefinition.createLexer(LanguageLevel.JDK_1_3); lexer.start(text); skipWhiteSpaceAndComments(lexer); final IElementType firstToken = lexer.getTokenType(); diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/java15api/Java15APIUsageInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/java15api/Java15APIUsageInspection.java index f63b2d802840..90935d236c25 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/java15api/Java15APIUsageInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/java15api/Java15APIUsageInspection.java @@ -33,9 +33,11 @@ import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.javadoc.PsiDocComment; +import com.intellij.psi.util.InheritanceUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.reference.SoftReference; +import com.intellij.util.containers.hash.HashSet; import com.intellij.util.ui.UIUtil; import gnu.trove.THashSet; import org.jdom.Element; @@ -75,6 +77,12 @@ public class Java15APIUsageInspection extends BaseJavaBatchLocalInspectionTool { loadForbiddenApi("ignore16List.txt", ourIgnored16ClassesAPI); } + private static Set<String> ourGenerifiedClasses = new HashSet<String>(); + static { + ourGenerifiedClasses.add("javax.swing.JComboBox"); + ourGenerifiedClasses.add("javax.swing.ListModel"); + } + @Nullable private static Set<String> getForbiddenApi(@NotNull LanguageLevel languageLevel) { if (!ourPresentableShortMessage.containsKey(languageLevel)) return null; @@ -282,6 +290,17 @@ public class Java15APIUsageInspection extends BaseJavaBatchLocalInspectionTool { } } registerError(reference, languageLevel); + } else if (resolved instanceof PsiClass && isInProject(reference)&& !languageLevel.isAtLeast(LanguageLevel.JDK_1_7)) { + final PsiReferenceParameterList parameterList = reference.getParameterList(); + if (parameterList != null && parameterList.getTypeParameterElements().length > 0) { + for (String generifiedClass : ourGenerifiedClasses) { + if (InheritanceUtil.isInheritor((PsiClass)resolved, generifiedClass)) { + myHolder.registerProblem(reference, InspectionsBundle.message("inspection.1.7.problem.descriptor", + getJdkName(languageLevel))); + break; + } + } + } } } } @@ -330,6 +349,11 @@ public class Java15APIUsageInspection extends BaseJavaBatchLocalInspectionTool { } } + private static String getJdkName(LanguageLevel languageLevel) { + final String presentableText = languageLevel.getPresentableText(); + return presentableText.substring(0, presentableText.indexOf(" ")); + } + public static boolean isForbiddenApiUsage(@NotNull PsiMember member, @NotNull LanguageLevel languageLevel) { // Annotations caught by special inspection if necessary if (member instanceof PsiClass && ((PsiClass)member).isAnnotationType()) return false; 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); + } +} diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/ConstructorReferencesSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/ConstructorReferencesSearcher.java index 5bc07cb4e4bd..80459c1b20f8 100644 --- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/ConstructorReferencesSearcher.java +++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/ConstructorReferencesSearcher.java @@ -28,7 +28,7 @@ public class ConstructorReferencesSearcher extends QueryExecutorBase<PsiReferenc return aClass; } }); - if (aClass == null) { + if (manager[0] == null) { return; } new ConstructorReferencesSearchHelper(manager[0]) diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/SPIReferencesSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/SPIReferencesSearcher.java new file mode 100644 index 000000000000..6ffe6247d4e7 --- /dev/null +++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/SPIReferencesSearcher.java @@ -0,0 +1,66 @@ +/* + * 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.psi.impl.search; + +import com.intellij.lang.spi.SPILanguage; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.QueryExecutorBase; +import com.intellij.openapi.util.Computable; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiReference; +import com.intellij.psi.search.FilenameIndex; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.SearchScope; +import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.util.ClassUtil; +import com.intellij.util.Processor; +import org.jetbrains.annotations.NotNull; + +public class SPIReferencesSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> { + @Override + public void processQuery(@NotNull ReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) { + final PsiElement element = p.getElementToSearch(); + if (!(element instanceof PsiClass)) { + return; + } + final SearchScope scope = p.getEffectiveSearchScope(); + if (!(scope instanceof GlobalSearchScope)) return; + final PsiClass aClass = (PsiClass)element; + final String jvmClassName = ApplicationManager.getApplication().runReadAction(new Computable<String>() { + @Override + public String compute() { + return ClassUtil.getJVMClassName(aClass); + } + }); + if (jvmClassName == null) return; + final PsiFile[] files = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile[]>() { + @Override + public PsiFile[] compute() { + return FilenameIndex.getFilesByName(aClass.getProject(), jvmClassName, (GlobalSearchScope)scope); + } + }); + for (PsiFile file : files) { + if (file.getLanguage() == SPILanguage.INSTANCE) { + final PsiReference reference = file.getReference(); + if (reference != null) { + consumer.process(reference); + } + } + } + } +} diff --git a/java/java-psi-api/src/com/intellij/lang/spi/SPILanguage.java b/java/java-psi-api/src/com/intellij/lang/spi/SPILanguage.java new file mode 100644 index 000000000000..84bfec8f9564 --- /dev/null +++ b/java/java-psi-api/src/com/intellij/lang/spi/SPILanguage.java @@ -0,0 +1,31 @@ +/* + * 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.lang.spi; + +import com.intellij.lang.Language; + +/** + * User: anna + */ +public class SPILanguage extends Language { + public static final SPILanguage INSTANCE = new SPILanguage(); + + protected SPILanguage() { + super("SPI"); + } + + +} diff --git a/java/java-psi-api/src/com/intellij/lexer/JavaDocLexer.java b/java/java-psi-api/src/com/intellij/lexer/JavaDocLexer.java index 6efb4ab16cce..72176faecc60 100644 --- a/java/java-psi-api/src/com/intellij/lexer/JavaDocLexer.java +++ b/java/java-psi-api/src/com/intellij/lexer/JavaDocLexer.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,9 +15,8 @@ */ package com.intellij.lexer; -/** - * @author yole - */ +/** @deprecated use com.intellij.lang.java.JavaDocLexer (to remove in IDEA 14) */ +@SuppressWarnings("UnusedDeclaration") public class JavaDocLexer extends DocCommentLexer { public JavaDocLexer(final boolean isJdk15Enabled) { super(JavaDocTokenTypes.INSTANCE, isJdk15Enabled); diff --git a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java index ab97463cab91..7202ecd99d3e 100644 --- a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java @@ -151,7 +151,7 @@ public class LambdaUtil { } return false; } - final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(leftType); + final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(GenericsUtil.eliminateWildcards(leftType)); final PsiClass psiClass = resolveResult.getElement(); if (psiClass instanceof PsiAnonymousClass) { return isAcceptable(lambdaExpression, ((PsiAnonymousClass)psiClass).getBaseClassType(), checkReturnType); diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java b/java/java-psi-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java index 1045dcd3f7cd..269114bb512f 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java @@ -18,13 +18,9 @@ package com.intellij.codeInsight; import com.intellij.lang.PsiBuilder; import com.intellij.lang.java.parser.JavaParser; import com.intellij.lang.java.parser.JavaParserUtil; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -38,14 +34,18 @@ import com.intellij.util.IncorrectOperationException; import com.intellij.util.SmartList; import com.intellij.util.containers.*; import gnu.trove.THashSet; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; - +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import java.io.IOException; -import java.io.StringWriter; +import java.io.StringReader; import java.util.*; import java.util.concurrent.ConcurrentMap; @@ -193,113 +193,25 @@ public abstract class BaseExternalAnnotationsManager extends ExternalAnnotations if (cached != null && cached.getSecond() == fileModificationStamp) { return cached.getFirst(); } - MostlySingularMultiMap<String, AnnotationData> data = new MostlySingularMultiMap<String, AnnotationData>(); + DataParsingSaxHandler handler = new DataParsingSaxHandler(file); try { - Document document = JDOMUtil.loadDocument(escapeAttributes(file.getText())); - Element rootElement = document.getRootElement(); - //noinspection unchecked - List<Element> itemElements = rootElement == null ? Collections.<Element>emptyList() : (List<Element>)rootElement.getChildren("item"); - boolean sorted = true; - boolean modified = false; - String prevItemName = null; - for (Element element : itemElements) { - String externalName = element.getAttributeValue("name"); - if (externalName == null) { - element.detach(); - modified = true; - continue; - } - if (prevItemName != null && prevItemName.compareTo(externalName) > 0) { - sorted = false; - } - prevItemName = externalName; - - //noinspection unchecked - for (Element annotationElement : (List<Element>) element.getChildren("annotation")) { - String annotationFQN = annotationElement.getAttributeValue("name"); - if (StringUtil.isEmpty(annotationFQN)) continue; - annotationFQN = intern(annotationFQN); - //noinspection unchecked - List<Element> children = (List<Element>)annotationElement.getChildren(); - StringBuilder buf = new StringBuilder(children.size() * "name=value,".length()); // just guess - for (Element annotationParameter : children) { - if (buf.length() != 0) { - buf.append(","); - } - String nameValue = annotationParameter.getAttributeValue("name"); - if (nameValue != null) { - buf.append(nameValue); - buf.append("="); - } - buf.append(annotationParameter.getAttributeValue("val")); - } - String annotationParameters = buf.length() == 0 ? "" : intern(buf.toString()); - for (AnnotationData existingData : data.get(externalName)) { - if (existingData.annotationClassFqName.equals(annotationFQN)) { - duplicateError(file, externalName, "Duplicate annotation '" + annotationFQN + "' "); - } - } - AnnotationData annData = internAnnotationData(new AnnotationData(annotationFQN, annotationParameters, file.getVirtualFile())); - - data.add(externalName, annData); - } - } - if (!sorted) { - modified = true; - List<Element> items = new ArrayList<Element>(rootElement.getChildren("item")); - rootElement.removeChildren("item"); - Collections.sort(items, new Comparator<Element>() { - @Override - public int compare(Element item1, Element item2) { - String externalName1 = item1.getAttributeValue("name"); - String externalName2 = item2.getAttributeValue("name"); - return externalName1.compareTo(externalName2); - } - }); - for (Element item : items) { - rootElement.addContent(item); - } - } - final VirtualFile virtualFile = file.getVirtualFile(); - if (modified && virtualFile.isInLocalFileSystem() && virtualFile.isWritable()) { - final Project project = file.getProject(); - final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); - final StringWriter string = new StringWriter(file.getTextLength()); - JDOMUtil.writeDocument(document, string, "\n"); - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - if (file.getModificationStamp() == fileModificationStamp && !fileDocumentManager.isFileModified(virtualFile)) { - // modify .xml in write action to avoid conflicts and torn reads - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - com.intellij.openapi.editor.Document editorDoc = PsiDocumentManager.getInstance(project).getDocument(file); - if (editorDoc != null) { - editorDoc.setText(string.toString()); - fileDocumentManager.saveDocument(editorDoc); - } - } - }); - } - } - }, project.getDisposed()); - } + SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); + saxParser.parse(new InputSource(new StringReader(escapeAttributes(file.getText()))), handler); } catch (IOException e) { LOG.error(e); } - catch (JDOMException e) { + catch (ParserConfigurationException e) { LOG.error(e); } - if (data.isEmpty()) { - data = MostlySingularMultiMap.emptyMap(); + catch (SAXException e) { + LOG.error(e); } - data.compact(); - Pair<MostlySingularMultiMap<String, AnnotationData>, Long> pair = Pair.create(data, file.getModificationStamp()); + + Pair<MostlySingularMultiMap<String, AnnotationData>, Long> pair = Pair.create(handler.getResult(), file.getModificationStamp()); annotationFileToDataAndModStamp.put(file, pair); - return data; + return pair.first; } protected void duplicateError(@NotNull PsiFile file, @NotNull String externalName, @NotNull String text) { @@ -547,4 +459,66 @@ public abstract class BaseExternalAnnotationsManager extends ExternalAnnotations JavaParser.INSTANCE.getDeclarationParser().parseAnnotation(builder); } }; + + private class DataParsingSaxHandler extends DefaultHandler { + private final MostlySingularMultiMap<String, AnnotationData> data = new MostlySingularMultiMap<String, AnnotationData>(); + + private final PsiFile file; + + private String externalName = null; + private String annotationFQN = null; + private StringBuilder arguments = null; + + private DataParsingSaxHandler(PsiFile file) { + this.file = file; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if ("item".equals(qName)) { + externalName = attributes.getValue("name"); + } else if ("annotation".equals(qName)) { + annotationFQN = attributes.getValue("name"); + arguments = new StringBuilder(); + } else if ("val".equals(qName)) { + if (arguments.length() != 0) { + arguments.append(","); + } + String name = attributes.getValue("name"); + if (name != null) { + arguments.append(name); + arguments.append("="); + } + arguments.append(attributes.getValue("val")); + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if ("item".equals(qName)) { + externalName = null; + } else if ("annotation".equals(qName)) { + if (externalName != null && annotationFQN != null) { + String argumentsString = arguments.length() == 0 ? "" : intern(arguments.toString()); + for (AnnotationData existingData : data.get(externalName)) { + if (existingData.annotationClassFqName.equals(annotationFQN)) { + duplicateError(file, externalName, "Duplicate annotation '" + annotationFQN + "' "); + } + } + AnnotationData annData = internAnnotationData(new AnnotationData(annotationFQN, argumentsString, file.getVirtualFile())); + data.add(externalName, annData); + annotationFQN = null; + arguments = null; + } + } + } + + public MostlySingularMultiMap<String, AnnotationData> getResult() { + if (data.isEmpty()) { + return MostlySingularMultiMap.emptyMap(); + } + data.compact(); + return data; + } + } } diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java index c61659752eec..ae6a063b3873 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.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. @@ -416,7 +416,7 @@ public class JavaDocInfoGenerator { final PsiModifierList modifierList = docOwner.getModifierList(); if (modifierList != null) { final PsiElement parent = modifierList.getParent(); - if (parent instanceof PsiDocCommentOwner) { + if (parent instanceof PsiDocCommentOwner && parent.getNavigationElement() instanceof PsiDocCommentOwner) { return ((PsiDocCommentOwner)parent.getNavigationElement()).getDocComment(); } } diff --git a/java/java-psi-impl/src/com/intellij/lang/java/JavaParserDefinition.java b/java/java-psi-impl/src/com/intellij/lang/java/JavaParserDefinition.java index fa2957692e26..f891c053690e 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/JavaParserDefinition.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/JavaParserDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -19,7 +19,8 @@ import com.intellij.lang.ASTNode; import com.intellij.lang.LanguageUtil; import com.intellij.lang.ParserDefinition; import com.intellij.lang.PsiParser; -import com.intellij.lexer.JavaLexer; +import com.intellij.lang.java.lexer.JavaDocLexer; +import com.intellij.lang.java.lexer.JavaLexer; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.LanguageLevelProjectExtension; @@ -34,6 +35,7 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IFileElementType; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author max @@ -41,14 +43,19 @@ import org.jetbrains.annotations.NotNull; public class JavaParserDefinition implements ParserDefinition { @Override @NotNull - public Lexer createLexer(final Project project) { - final LanguageLevel languageLevel = LanguageLevelProjectExtension.getInstance(project).getLanguageLevel(); - return createLexer(languageLevel); + public Lexer createLexer(@Nullable Project project) { + LanguageLevel level = project != null ? LanguageLevelProjectExtension.getInstance(project).getLanguageLevel() : LanguageLevel.HIGHEST; + return createLexer(level); } @NotNull - public static Lexer createLexer(final LanguageLevel languageLevel) { - return new JavaLexer(languageLevel); + public static Lexer createLexer(@NotNull LanguageLevel level) { + return new JavaLexer(level); + } + + @NotNull + public static Lexer createDocLexer(@NotNull LanguageLevel level) { + return new JavaDocLexer(level); } @Override @@ -98,24 +105,27 @@ public class JavaParserDefinition implements ParserDefinition { @Override public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) { - final PsiFile containingFile = left.getTreeParent().getPsi().getContainingFile(); - final Lexer lexer; - if(containingFile instanceof PsiJavaFile) - lexer = new JavaLexer(((PsiJavaFile)containingFile).getLanguageLevel()); - else lexer = new JavaLexer(LanguageLevel.HIGHEST); - if(right.getElementType() == JavaDocTokenType.DOC_TAG_VALUE_SHARP_TOKEN) return SpaceRequirements.MUST_NOT; - if(left.getElementType() == JavaDocTokenType.DOC_TAG_VALUE_SHARP_TOKEN) return SpaceRequirements.MUST_NOT; - final SpaceRequirements spaceRequirements = LanguageUtil.canStickTokensTogetherByLexer(left, right, lexer); - if(left.getElementType() == JavaTokenType.END_OF_LINE_COMMENT) return SpaceRequirements.MUST_LINE_BREAK; - - if(left.getElementType() == JavaDocTokenType.DOC_COMMENT_DATA) { + if (right.getElementType() == JavaDocTokenType.DOC_TAG_VALUE_SHARP_TOKEN || + left.getElementType() == JavaDocTokenType.DOC_TAG_VALUE_SHARP_TOKEN) { + return SpaceRequirements.MUST_NOT; + } + + PsiFile containingFile = left.getTreeParent().getPsi().getContainingFile(); + LanguageLevel level = containingFile instanceof PsiJavaFile? ((PsiJavaFile)containingFile).getLanguageLevel() : LanguageLevel.HIGHEST; + Lexer lexer = createLexer(level); + SpaceRequirements spaceRequirements = LanguageUtil.canStickTokensTogetherByLexer(left, right, lexer); + if (left.getElementType() == JavaTokenType.END_OF_LINE_COMMENT) { + return SpaceRequirements.MUST_LINE_BREAK; + } + + if (left.getElementType() == JavaDocTokenType.DOC_COMMENT_DATA) { String text = left.getText(); if (text.length() > 0 && Character.isWhitespace(text.charAt(text.length() - 1))) { return SpaceRequirements.MAY; } } - if(right.getElementType() == JavaDocTokenType.DOC_COMMENT_DATA) { + if (right.getElementType() == JavaDocTokenType.DOC_COMMENT_DATA) { String text = right.getText(); if (text.length() > 0 && Character.isWhitespace(text.charAt(0))) { return SpaceRequirements.MAY; diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaDocLexer.java b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaDocLexer.java new file mode 100644 index 000000000000..de1e03f30d6d --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaDocLexer.java @@ -0,0 +1,179 @@ +/* + * 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.lang.java.lexer; + +import com.intellij.lexer.DocCommentTokenTypes; +import com.intellij.lexer.JavaDocTokenTypes; +import com.intellij.lexer.LexerBase; +import com.intellij.lexer.MergingLexerAdapter; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.tree.IElementType; +import com.intellij.util.text.CharArrayUtil; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; + +public class JavaDocLexer extends MergingLexerAdapter { + public JavaDocLexer(@NotNull LanguageLevel level) { + this(JavaDocTokenTypes.INSTANCE, level.isAtLeast(LanguageLevel.JDK_1_5)); + } + + private JavaDocLexer(DocCommentTokenTypes tokenTypes, boolean isJdk15Enabled) { + super(new AsteriskStripperLexer(new _JavaDocLexer(isJdk15Enabled, tokenTypes), tokenTypes), + tokenTypes.spaceCommentsTokenSet()); + } + + private static class AsteriskStripperLexer extends LexerBase { + private final _JavaDocLexer myFlex; + private final DocCommentTokenTypes myTokenTypes; + private CharSequence myBuffer; + private int myBufferIndex; + private int myBufferEndOffset; + private int myTokenEndOffset; + private int myState; + private IElementType myTokenType; + private boolean myAfterLineBreak; + private boolean myInLeadingSpace; + + public AsteriskStripperLexer(final _JavaDocLexer flex, final DocCommentTokenTypes tokenTypes) { + myFlex = flex; + myTokenTypes = tokenTypes; + } + + @Override + public final void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + myBuffer = buffer; + myBufferIndex = startOffset; + myBufferEndOffset = endOffset; + myTokenType = null; + myTokenEndOffset = startOffset; + myFlex.reset(myBuffer, startOffset, endOffset, initialState); + } + + @Override + public int getState() { + return myState; + } + + @Override + public CharSequence getBufferSequence() { + return myBuffer; + } + + @Override + public int getBufferEnd() { + return myBufferEndOffset; + } + + @Override + public final IElementType getTokenType() { + locateToken(); + return myTokenType; + } + + @Override + public final int getTokenStart() { + locateToken(); + return myBufferIndex; + } + + @Override + public final int getTokenEnd() { + locateToken(); + return myTokenEndOffset; + } + + + @Override + public final void advance() { + locateToken(); + myTokenType = null; + } + + protected final void locateToken() { + if (myTokenType != null) return; + _locateToken(); + + if (myTokenType == myTokenTypes.space()) { + myAfterLineBreak = CharArrayUtil.containLineBreaks(myBuffer, getTokenStart(), getTokenEnd()); + } + } + + private void _locateToken() { + if (myTokenEndOffset == myBufferEndOffset) { + myTokenType = null; + myBufferIndex = myBufferEndOffset; + return; + } + + myBufferIndex = myTokenEndOffset; + + if (myAfterLineBreak) { + myAfterLineBreak = false; + while (myTokenEndOffset < myBufferEndOffset && myBuffer.charAt(myTokenEndOffset) == '*' && + (myTokenEndOffset + 1 >= myBufferEndOffset || myBuffer.charAt(myTokenEndOffset + 1) != '/')) { + myTokenEndOffset++; + } + + myInLeadingSpace = true; + if (myBufferIndex < myTokenEndOffset) { + myTokenType = myTokenTypes.commentLeadingAsterisks(); + return; + } + } + + if (myInLeadingSpace) { + myInLeadingSpace = false; + boolean lf = false; + while (myTokenEndOffset < myBufferEndOffset && Character.isWhitespace(myBuffer.charAt(myTokenEndOffset))) { + if (myBuffer.charAt(myTokenEndOffset) == '\n') lf = true; + myTokenEndOffset++; + } + + final int state = myFlex.yystate(); + if (state == _JavaDocLexer.COMMENT_DATA || + myTokenEndOffset < myBufferEndOffset && (myBuffer.charAt(myTokenEndOffset) == '@' || + myBuffer.charAt(myTokenEndOffset) == '{' || + myBuffer.charAt(myTokenEndOffset) == '\"' || + myBuffer.charAt(myTokenEndOffset) == '<')) { + myFlex.yybegin(_JavaDocLexer.COMMENT_DATA_START); + } + + if (myBufferIndex < myTokenEndOffset) { + myTokenType = lf || state == _JavaDocLexer.PARAM_TAG_SPACE || state == _JavaDocLexer.TAG_DOC_SPACE || state == _JavaDocLexer.INLINE_TAG_NAME || state == _JavaDocLexer.DOC_TAG_VALUE_IN_PAREN + ? myTokenTypes.space() + : myTokenTypes.commentData(); + + return; + } + } + + flexLocateToken(); + } + + private void flexLocateToken() { + try { + myState = myFlex.yystate(); + myFlex.goTo(myBufferIndex); + myTokenType = myFlex.advance(); + myTokenEndOffset = myFlex.getTokenEnd(); + } + catch (IOException e) { + // Can't be + } + } + } +} diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java new file mode 100644 index 000000000000..db6e5e21aa25 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java @@ -0,0 +1,429 @@ +/* + * 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.lang.java.lexer; + +import com.intellij.lexer.LexerBase; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.JavaTokenType; +import com.intellij.psi.TokenType; +import com.intellij.psi.impl.source.tree.JavaDocElementType; +import com.intellij.psi.tree.IElementType; +import com.intellij.util.text.CharArrayUtil; +import gnu.trove.THashSet; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.util.Set; + +public class JavaLexer extends LexerBase { + private static final HashTable[] TABLES = new HashTable[]{ + new HashTable(LanguageLevel.JDK_1_5), + new HashTable(LanguageLevel.JDK_1_4), + new HashTable(LanguageLevel.JDK_1_3) + }; + + private static HashTable getTable(final LanguageLevel level) { + for (HashTable table : TABLES) { + if (level.isAtLeast(table.myLevel)) { + return table; + } + } + throw new IllegalArgumentException("Unsupported level: " + level); + } + + public static boolean isKeyword(String id, LanguageLevel level) { + return getTable(level).contains(id); + } + + private final _JavaLexer myFlexLexer; + private final HashTable myTable; + private CharSequence myBuffer; + private char[] myBufferArray; + private int myBufferIndex; + private int myBufferEndOffset; + private int myTokenEndOffset; // positioned after the last symbol of the current token + private IElementType myTokenType; + + public JavaLexer(@NotNull final LanguageLevel level) { + myFlexLexer = new _JavaLexer(level); + myTable = getTable(level); + } + + private static final class HashTable { + private static final int NUM_ENTRIES = 999; + private static final Logger LOG = Logger.getInstance("com.intellij.Lexer.JavaLexer"); + + private final LanguageLevel myLevel; + private final char[][] myTable = new char[NUM_ENTRIES][]; + private final IElementType[] myKeywords = new IElementType[NUM_ENTRIES]; + private final Set<String> myKeywordsInSet = new THashSet<String>(); + + private void add(String s, IElementType tokenType) { + char[] chars = s.toCharArray(); + int hashCode = chars[0] * 2; + for (int j = 1; j < chars.length; j++) { + hashCode += chars[j]; + } + int modHashCode = hashCode % NUM_ENTRIES; + LOG.assertTrue(myTable[modHashCode] == null); + + myTable[modHashCode] = chars; + myKeywords[modHashCode] = tokenType; + myKeywordsInSet.add(s); + } + + public boolean contains(String s) { + return myKeywordsInSet.contains(s); + } + + private boolean contains(int hashCode, final char[] bufferArray, final CharSequence buffer, int offset) { + int modHashCode = hashCode % NUM_ENTRIES; + final char[] kwd = myTable[modHashCode]; + if (kwd == null) return false; + + if (bufferArray != null) { + for (int j = 0; j < kwd.length; j++) { + if (bufferArray[j + offset] != kwd[j]) return false; + } + } else { + for (int j = 0; j < kwd.length; j++) { + if (buffer.charAt(j + offset) != kwd[j]) return false; + } + } + return true; + } + + private IElementType getTokenType(int hashCode) { + return myKeywords[hashCode % NUM_ENTRIES]; + } + + @SuppressWarnings({"HardCodedStringLiteral"}) + private HashTable(final LanguageLevel level) { + myLevel = level; + if (level.isAtLeast(LanguageLevel.JDK_1_4)) { + add("assert", JavaTokenType.ASSERT_KEYWORD); + if (level.isAtLeast(LanguageLevel.JDK_1_5)) { + add("enum", JavaTokenType.ENUM_KEYWORD); + } + } + add("abstract", JavaTokenType.ABSTRACT_KEYWORD); + add("default", JavaTokenType.DEFAULT_KEYWORD); + add("if", JavaTokenType.IF_KEYWORD); + add("private", JavaTokenType.PRIVATE_KEYWORD); + add("this", JavaTokenType.THIS_KEYWORD); + add("boolean", JavaTokenType.BOOLEAN_KEYWORD); + add("do", JavaTokenType.DO_KEYWORD); + add("implements", JavaTokenType.IMPLEMENTS_KEYWORD); + add("protected", JavaTokenType.PROTECTED_KEYWORD); + add("throw", JavaTokenType.THROW_KEYWORD); + add("break", JavaTokenType.BREAK_KEYWORD); + add("double", JavaTokenType.DOUBLE_KEYWORD); + add("import", JavaTokenType.IMPORT_KEYWORD); + add("public", JavaTokenType.PUBLIC_KEYWORD); + add("throws", JavaTokenType.THROWS_KEYWORD); + add("byte", JavaTokenType.BYTE_KEYWORD); + add("else", JavaTokenType.ELSE_KEYWORD); + add("instanceof", JavaTokenType.INSTANCEOF_KEYWORD); + add("return", JavaTokenType.RETURN_KEYWORD); + add("transient", JavaTokenType.TRANSIENT_KEYWORD); + add("case", JavaTokenType.CASE_KEYWORD); + add("extends", JavaTokenType.EXTENDS_KEYWORD); + add("int", JavaTokenType.INT_KEYWORD); + add("short", JavaTokenType.SHORT_KEYWORD); + add("try", JavaTokenType.TRY_KEYWORD); + add("catch", JavaTokenType.CATCH_KEYWORD); + add("final", JavaTokenType.FINAL_KEYWORD); + add("interface", JavaTokenType.INTERFACE_KEYWORD); + add("static", JavaTokenType.STATIC_KEYWORD); + add("void", JavaTokenType.VOID_KEYWORD); + add("char", JavaTokenType.CHAR_KEYWORD); + add("finally", JavaTokenType.FINALLY_KEYWORD); + add("long", JavaTokenType.LONG_KEYWORD); + add("strictfp", JavaTokenType.STRICTFP_KEYWORD); + add("volatile", JavaTokenType.VOLATILE_KEYWORD); + add("class", JavaTokenType.CLASS_KEYWORD); + add("float", JavaTokenType.FLOAT_KEYWORD); + add("native", JavaTokenType.NATIVE_KEYWORD); + add("super", JavaTokenType.SUPER_KEYWORD); + add("while", JavaTokenType.WHILE_KEYWORD); + add("const", JavaTokenType.CONST_KEYWORD); + add("for", JavaTokenType.FOR_KEYWORD); + add("new", JavaTokenType.NEW_KEYWORD); + add("switch", JavaTokenType.SWITCH_KEYWORD); + add("continue", JavaTokenType.CONTINUE_KEYWORD); + add("goto", JavaTokenType.GOTO_KEYWORD); + add("package", JavaTokenType.PACKAGE_KEYWORD); + add("synchronized", JavaTokenType.SYNCHRONIZED_KEYWORD); + add("true", JavaTokenType.TRUE_KEYWORD); + add("false", JavaTokenType.FALSE_KEYWORD); + add("null", JavaTokenType.NULL_KEYWORD); + } + } + + @Override + public final void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + myBuffer = buffer; + myBufferArray = CharArrayUtil.fromSequenceWithoutCopying(buffer); + myBufferIndex = startOffset; + myBufferEndOffset = endOffset; + myTokenType = null; + myTokenEndOffset = startOffset; + myFlexLexer.reset(myBuffer, startOffset, endOffset, 0); + } + + @Override + public int getState() { + return 0; + } + + @Override + public final IElementType getTokenType() { + if (myTokenType == null) _locateToken(); + + return myTokenType; + } + + @Override + public final int getTokenStart() { + return myBufferIndex; + } + + @Override + public final int getTokenEnd() { + if (myTokenType == null) _locateToken(); + return myTokenEndOffset; + } + + + @Override + public final void advance() { + if (myTokenType == null) _locateToken(); + myTokenType = null; + } + + private void _locateToken() { + if (myTokenEndOffset == myBufferEndOffset) { + myTokenType = null; + myBufferIndex = myBufferEndOffset; + return; + } + + myBufferIndex = myTokenEndOffset; + + final char c = myBufferArray != null ? myBufferArray[myBufferIndex]:myBuffer.charAt(myBufferIndex); + switch (c) { + default: + flexLocateToken(); + break; + + case ' ': + case '\t': + case '\n': + case '\r': + case '\f': + myTokenType = TokenType.WHITE_SPACE; + myTokenEndOffset = getWhitespaces(myBufferIndex + 1); + break; + + case '/': + if (myBufferIndex + 1 >= myBufferEndOffset) { + myTokenType = JavaTokenType.DIV; + myTokenEndOffset = myBufferEndOffset; + } + else { + final char nextChar = myBufferArray != null ? myBufferArray[myBufferIndex + 1]:myBuffer.charAt(myBufferIndex + 1); + + if (nextChar == '/') { + myTokenType = JavaTokenType.END_OF_LINE_COMMENT; + myTokenEndOffset = getLineTerminator(myBufferIndex + 2); + } + else if (nextChar == '*') { + if (myBufferIndex + 2 >= myBufferEndOffset || + (myBufferArray != null ? myBufferArray[myBufferIndex + 2]:myBuffer.charAt(myBufferIndex + 2)) != '*' || + (myBufferIndex + 3 < myBufferEndOffset && + (myBufferArray != null ? myBufferArray[myBufferIndex + 3]:myBuffer.charAt(myBufferIndex + 3)) == '/')) { + myTokenType = JavaTokenType.C_STYLE_COMMENT; + myTokenEndOffset = getClosingComment(myBufferIndex + 2); + } + else { + myTokenType = JavaDocElementType.DOC_COMMENT; + myTokenEndOffset = getClosingComment(myBufferIndex + 3); + } + } + else if (c > 127 && Character.isJavaIdentifierStart(c)) { + myTokenEndOffset = getIdentifier(myBufferIndex + 1); + } + else { + flexLocateToken(); + } + } + break; + + case '"': + case '\'': + myTokenType = c == '"' ? JavaTokenType.STRING_LITERAL : JavaTokenType.CHARACTER_LITERAL; + myTokenEndOffset = getClosingParenthesis(myBufferIndex + 1, c); + } + + if (myTokenEndOffset > myBufferEndOffset) { + myTokenEndOffset = myBufferEndOffset; + } + } + + private int getWhitespaces(int pos) { + if (pos >= myBufferEndOffset) return myBufferEndOffset; + final CharSequence lBuffer = myBuffer; + final char[] lBufferArray = myBufferArray; + + char c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + + while (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f') { + pos++; + if (pos == myBufferEndOffset) return pos; + c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + } + + return pos; + } + + private void flexLocateToken() { + try { + myFlexLexer.goTo(myBufferIndex); + myTokenType = myFlexLexer.advance(); + myTokenEndOffset = myFlexLexer.getTokenEnd(); + } + catch (IOException e) { + // Can't be + } + } + + private int getClosingParenthesis(int offset, char c) { + int pos = offset; + final int lBufferEnd = myBufferEndOffset; + if (pos >= lBufferEnd) return lBufferEnd; + + final CharSequence lBuffer = myBuffer; + final char[] lBufferArray = myBufferArray; + char cur = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + + while (true) { + while (cur != c && cur != '\n' && cur != '\r' && cur != '\\') { + pos++; + if (pos >= lBufferEnd) return lBufferEnd; + cur = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + } + + if (cur == '\\') { + pos++; + if (pos >= lBufferEnd) return lBufferEnd; + cur = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + if (cur == '\n' || cur == '\r') continue; + pos++; + if (pos >= lBufferEnd) return lBufferEnd; + cur = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + } + else if (cur == c) { + break; + } + else { + pos--; + break; + } + } + + return pos + 1; + } + + private int getClosingComment(int offset) { + int pos = offset; + + final int lBufferEnd = myBufferEndOffset; + final CharSequence lBuffer = myBuffer; + final char[] lBufferArray = myBufferArray; + + while (pos < lBufferEnd - 1) { + final char c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + + if (c == '*' && (lBufferArray != null ? lBufferArray[pos + 1]:lBuffer.charAt(pos + 1)) == '/') { + break; + } + pos++; + } + + return pos + 2; + } + + private int getLineTerminator(int offset) { + int pos = offset; + final int lBufferEnd = myBufferEndOffset; + final CharSequence lBuffer = myBuffer; + final char[] lBufferArray = myBufferArray; + + while (pos < lBufferEnd) { + final char c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + if (c == '\r' || c == '\n') break; + pos++; + } + + return pos; + } + + private int getIdentifier(int offset) { + final CharSequence lBuffer = myBuffer; + final char[] lBufferArray = myBufferArray; + + int hashCode = (lBufferArray != null ? lBufferArray[offset - 1]:lBuffer.charAt(offset - 1)) * 2; + final int lBufferEnd = myBufferEndOffset; + + int pos = offset; + if (pos < lBufferEnd) { + char c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + + while (c >= 'a' && c <= 'z' || + c >= 'A' && c <= 'Z' || + c >= '0' && c <= '9' || + c == '_' || + c == '$' || + c > 127 && Character.isJavaIdentifierPart(c)) { + pos++; + hashCode += c; + + if (pos == lBufferEnd) break; + c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); + } + } + + if (myTable.contains(hashCode, lBufferArray, lBuffer, offset - 1)) { + myTokenType = myTable.getTokenType(hashCode); + } + else { + myTokenType = JavaTokenType.IDENTIFIER; + } + + return pos; + } + + @Override + public CharSequence getBufferSequence() { + return myBuffer; + } + + @Override + public final int getBufferEnd() { + return myBufferEndOffset; + } +} diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.flex b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.flex new file mode 100644 index 000000000000..460d1d78e8d4 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.flex @@ -0,0 +1,111 @@ +/* It's an automatically generated code. Do not modify it. */ +package com.intellij.lang.java.lexer; + +import com.intellij.lexer.DocCommentTokenTypes; +import com.intellij.lexer.FlexLexer; +import com.intellij.psi.tree.IElementType; + +@SuppressWarnings("ALL") +%% + +%{ + private boolean myJdk15Enabled; + private DocCommentTokenTypes myTokenTypes; + + public _JavaDocLexer(boolean isJdk15Enabled, DocCommentTokenTypes tokenTypes) { + this((java.io.Reader)null); + myJdk15Enabled = isJdk15Enabled; + myTokenTypes = tokenTypes; + } + + public boolean checkAhead(char c) { + if (zzMarkedPos >= zzBuffer.length()) return false; + return zzBuffer.charAt(zzMarkedPos) == c; + } + + public void goTo(int offset) { + zzCurrentPos = zzMarkedPos = zzStartRead = offset; + zzPushbackPos = 0; + zzAtEOF = offset < zzEndRead; + } +%} + +%class _JavaDocLexer +%implements FlexLexer +%unicode +%function advance +%type IElementType +%eof{ return; +%eof} + +%state COMMENT_DATA_START +%state COMMENT_DATA +%state TAG_DOC_SPACE +%state PARAM_TAG_SPACE +%state DOC_TAG_VALUE +%state DOC_TAG_VALUE_IN_PAREN +%state DOC_TAG_VALUE_IN_LTGT +%state INLINE_TAG_NAME + +WHITE_DOC_SPACE_CHAR=[\ \t\f\n\r] +WHITE_DOC_SPACE_NO_LR=[\ \t\f] +DIGIT=[0-9] +ALPHA=[:jletter:] +IDENTIFIER={ALPHA}({ALPHA}|{DIGIT}|[":.-"])* + +%% + +<YYINITIAL> "/**" { yybegin(COMMENT_DATA_START); return myTokenTypes.commentStart(); } +<COMMENT_DATA_START> {WHITE_DOC_SPACE_CHAR}+ { return myTokenTypes.space(); } +<COMMENT_DATA> {WHITE_DOC_SPACE_NO_LR}+ { return myTokenTypes.commentData(); } +<COMMENT_DATA> [\n\r]+{WHITE_DOC_SPACE_CHAR}* { return myTokenTypes.space(); } + +<DOC_TAG_VALUE> {WHITE_DOC_SPACE_CHAR}+ { yybegin(COMMENT_DATA); return myTokenTypes.space(); } +<DOC_TAG_VALUE, DOC_TAG_VALUE_IN_PAREN> ({ALPHA}|[_0-9\."$"\[\]])+ { return myTokenTypes.tagValueToken(); } +<DOC_TAG_VALUE> [\(] { yybegin(DOC_TAG_VALUE_IN_PAREN); return myTokenTypes.tagValueLParen(); } +<DOC_TAG_VALUE_IN_PAREN> [\)] { yybegin(DOC_TAG_VALUE); return myTokenTypes.tagValueRParen(); } +<DOC_TAG_VALUE> [#] { return myTokenTypes.tagValueSharp(); } +<DOC_TAG_VALUE, DOC_TAG_VALUE_IN_PAREN> [,] { return myTokenTypes.tagValueComma(); } +<DOC_TAG_VALUE_IN_PAREN> {WHITE_DOC_SPACE_CHAR}+ { return myTokenTypes.space(); } + +<INLINE_TAG_NAME, COMMENT_DATA_START> "@param" { yybegin(PARAM_TAG_SPACE); return myTokenTypes.tagName(); } +<PARAM_TAG_SPACE> {WHITE_DOC_SPACE_CHAR}+ {yybegin(DOC_TAG_VALUE); return myTokenTypes.space();} +<DOC_TAG_VALUE> [\<] { + if (myJdk15Enabled) { + yybegin(DOC_TAG_VALUE_IN_LTGT); + return myTokenTypes.tagValueLT(); + } + else { + yybegin(COMMENT_DATA); + return myTokenTypes.commentData(); + } +} +<DOC_TAG_VALUE_IN_LTGT> {IDENTIFIER} { return myTokenTypes.tagValueToken(); } +<DOC_TAG_VALUE_IN_LTGT> {IDENTIFIER} { return myTokenTypes.tagValueToken(); } +<DOC_TAG_VALUE_IN_LTGT> [\>] { yybegin(COMMENT_DATA); return myTokenTypes.tagValueGT(); } + +<COMMENT_DATA_START, COMMENT_DATA> "{" { + if (checkAhead('@')) { + yybegin(INLINE_TAG_NAME); + return myTokenTypes.inlineTagStart(); + } + else{ + yybegin(COMMENT_DATA); + return myTokenTypes.inlineTagStart(); + } +} +<INLINE_TAG_NAME> "@"{IDENTIFIER} { yybegin(TAG_DOC_SPACE); return myTokenTypes.tagName(); } +<COMMENT_DATA_START, COMMENT_DATA, TAG_DOC_SPACE, DOC_TAG_VALUE> "}" { yybegin(COMMENT_DATA); return myTokenTypes.inlineTagEnd(); } + +<COMMENT_DATA_START, COMMENT_DATA, DOC_TAG_VALUE> . { yybegin(COMMENT_DATA); return myTokenTypes.commentData(); } +<COMMENT_DATA_START> "@"{IDENTIFIER} { yybegin(TAG_DOC_SPACE); return myTokenTypes.tagName(); } + +<TAG_DOC_SPACE> {WHITE_DOC_SPACE_CHAR}+ { + if (checkAhead('<') || checkAhead('\"')) yybegin(COMMENT_DATA); + else if (checkAhead('\u007b') ) yybegin(COMMENT_DATA); // lbrace - there's a error in JLex when typing lbrace directly + else yybegin(DOC_TAG_VALUE); + return myTokenTypes.space(); +} + +"*"+"/" { return myTokenTypes.commentEnd(); } +[^] { return myTokenTypes.badCharacter(); } diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.java b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.java new file mode 100644 index 000000000000..1780cbeb9721 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.java @@ -0,0 +1,721 @@ +/* + * 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. + */ + +/* The following code was generated by JFlex 1.4.3 on 05.06.13 19:07 */ + +/* It's an automatically generated code. Do not modify it. */ +package com.intellij.lang.java.lexer; + +import com.intellij.lexer.DocCommentTokenTypes; +import com.intellij.lexer.FlexLexer; +import com.intellij.psi.tree.IElementType; + +@SuppressWarnings("ALL") + +/** + * This class is a scanner generated by + * <a href="http://www.jflex.de/">JFlex</a> 1.4.3 + * on 05.06.13 19:07 from the specification file + * <tt>C:/Users/roman.shevchenko/Projects/IDEA/tools/lexer/../../community/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.flex</tt> + */ +class _JavaDocLexer implements FlexLexer { + /** initial size of the lookahead buffer */ + private static final int ZZ_BUFFERSIZE = 16384; + + /** lexical states */ + public static final int INLINE_TAG_NAME = 16; + public static final int PARAM_TAG_SPACE = 8; + public static final int COMMENT_DATA = 4; + public static final int DOC_TAG_VALUE = 10; + public static final int COMMENT_DATA_START = 2; + public static final int TAG_DOC_SPACE = 6; + public static final int YYINITIAL = 0; + public static final int DOC_TAG_VALUE_IN_PAREN = 12; + public static final int DOC_TAG_VALUE_IN_LTGT = 14; + + /** + * 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, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, + 8, 8 + }; + + /** + * Translates characters to character classes + */ + private static final String ZZ_CMAP_PACKED = + "\11\0\1\2\1\1\1\0\1\2\1\1\22\0\1\2\2\0\1\13"+ + "\1\4\3\0\1\11\1\12\1\7\1\0\1\14\1\5\1\3\1\6"+ + "\12\3\1\5\1\0\1\22\1\0\1\23\1\0\1\15\32\4\1\10"+ + "\1\0\1\10\1\0\1\4\1\0\1\17\13\4\1\21\2\4\1\16"+ + "\1\4\1\20\10\4\1\24\1\0\1\25\44\0\4\4\4\0\1\4"+ + "\12\0\1\4\4\0\1\4\5\0\27\4\1\0\37\4\1\0\u01ca\4"+ + "\4\0\14\4\16\0\5\4\7\0\1\4\1\0\1\4\201\0\5\4"+ + "\1\0\2\4\2\0\4\4\10\0\1\4\1\0\3\4\1\0\1\4"+ + "\1\0\24\4\1\0\123\4\1\0\213\4\10\0\236\4\11\0\46\4"+ + "\2\0\1\4\7\0\47\4\110\0\33\4\5\0\3\4\30\0\1\4"+ + "\24\0\53\4\43\0\2\4\1\0\143\4\1\0\1\4\17\0\2\4"+ + "\7\0\2\4\12\0\3\4\2\0\1\4\20\0\1\4\1\0\36\4"+ + "\35\0\131\4\13\0\1\4\30\0\41\4\11\0\2\4\4\0\1\4"+ + "\5\0\26\4\4\0\1\4\11\0\1\4\3\0\1\4\27\0\31\4"+ + "\253\0\66\4\3\0\1\4\22\0\1\4\7\0\12\4\17\0\7\4"+ + "\1\0\7\4\5\0\10\4\2\0\2\4\2\0\26\4\1\0\7\4"+ + "\1\0\1\4\3\0\4\4\3\0\1\4\20\0\1\4\15\0\2\4"+ + "\1\0\3\4\16\0\4\4\7\0\1\4\11\0\6\4\4\0\2\4"+ + "\2\0\26\4\1\0\7\4\1\0\2\4\1\0\2\4\1\0\2\4"+ + "\37\0\4\4\1\0\1\4\23\0\3\4\20\0\11\4\1\0\3\4"+ + "\1\0\26\4\1\0\7\4\1\0\2\4\1\0\5\4\3\0\1\4"+ + "\22\0\1\4\17\0\2\4\17\0\1\4\23\0\10\4\2\0\2\4"+ + "\2\0\26\4\1\0\7\4\1\0\2\4\1\0\5\4\3\0\1\4"+ + "\36\0\2\4\1\0\3\4\17\0\1\4\21\0\1\4\1\0\6\4"+ + "\3\0\3\4\1\0\4\4\3\0\2\4\1\0\1\4\1\0\2\4"+ + "\3\0\2\4\3\0\3\4\3\0\14\4\26\0\1\4\50\0\1\4"+ + "\13\0\10\4\1\0\3\4\1\0\27\4\1\0\12\4\1\0\5\4"+ + "\3\0\1\4\32\0\2\4\6\0\2\4\43\0\10\4\1\0\3\4"+ + "\1\0\27\4\1\0\12\4\1\0\5\4\3\0\1\4\40\0\1\4"+ + "\1\0\2\4\17\0\2\4\22\0\10\4\1\0\3\4\1\0\51\4"+ + "\2\0\1\4\20\0\1\4\21\0\2\4\30\0\6\4\5\0\22\4"+ + "\3\0\30\4\1\0\11\4\1\0\1\4\2\0\7\4\72\0\60\4"+ + "\1\0\2\4\13\0\10\4\72\0\2\4\1\0\1\4\2\0\2\4"+ + "\1\0\1\4\2\0\1\4\6\0\4\4\1\0\7\4\1\0\3\4"+ + "\1\0\1\4\1\0\1\4\2\0\2\4\1\0\4\4\1\0\2\4"+ + "\11\0\1\4\2\0\5\4\1\0\1\4\25\0\2\4\42\0\1\4"+ + "\77\0\10\4\1\0\44\4\33\0\5\4\163\0\53\4\24\0\1\4"+ + "\20\0\6\4\4\0\4\4\3\0\1\4\3\0\2\4\7\0\3\4"+ + "\4\0\15\4\14\0\1\4\21\0\46\4\12\0\53\4\1\0\1\4"+ + "\3\0\u0149\4\1\0\4\4\2\0\7\4\1\0\1\4\1\0\4\4"+ + "\2\0\51\4\1\0\4\4\2\0\41\4\1\0\4\4\2\0\7\4"+ + "\1\0\1\4\1\0\4\4\2\0\17\4\1\0\71\4\1\0\4\4"+ + "\2\0\103\4\45\0\20\4\20\0\125\4\14\0\u026c\4\2\0\21\4"+ + "\1\0\32\4\5\0\113\4\3\0\3\4\17\0\15\4\1\0\4\4"+ + "\16\0\22\4\16\0\22\4\16\0\15\4\1\0\3\4\17\0\64\4"+ + "\43\0\1\4\3\0\2\4\103\0\130\4\10\0\51\4\1\0\1\4"+ + "\5\0\106\4\12\0\35\4\63\0\36\4\2\0\5\4\13\0\54\4"+ + "\25\0\7\4\70\0\27\4\11\0\65\4\122\0\1\4\135\0\57\4"+ + "\21\0\7\4\67\0\36\4\15\0\2\4\20\0\46\4\32\0\44\4"+ + "\51\0\3\4\12\0\44\4\153\0\4\4\1\0\4\4\16\0\300\4"+ + "\100\0\u0116\4\2\0\6\4\2\0\46\4\2\0\6\4\2\0\10\4"+ + "\1\0\1\4\1\0\1\4\1\0\1\4\1\0\37\4\2\0\65\4"+ + "\1\0\7\4\1\0\1\4\3\0\3\4\1\0\7\4\3\0\4\4"+ + "\2\0\6\4\4\0\15\4\5\0\3\4\1\0\7\4\102\0\2\4"+ + "\23\0\1\4\34\0\1\4\15\0\1\4\20\0\15\4\3\0\32\4"+ + "\110\0\1\4\4\0\1\4\2\0\12\4\1\0\1\4\3\0\5\4"+ + "\6\0\1\4\1\0\1\4\1\0\1\4\1\0\4\4\1\0\13\4"+ + "\2\0\4\4\5\0\5\4\4\0\1\4\21\0\51\4\u0a77\0\57\4"+ + "\1\0\57\4\1\0\205\4\6\0\4\4\21\0\46\4\12\0\66\4"+ + "\11\0\1\4\20\0\27\4\11\0\7\4\1\0\7\4\1\0\7\4"+ + "\1\0\7\4\1\0\7\4\1\0\7\4\1\0\7\4\1\0\7\4"+ + "\120\0\1\4\u01d5\0\3\4\31\0\11\4\7\0\5\4\2\0\5\4"+ + "\4\0\126\4\6\0\3\4\1\0\132\4\1\0\4\4\5\0\51\4"+ + "\3\0\136\4\21\0\33\4\65\0\20\4\u0200\0\u19b6\4\112\0\u51cc\4"+ + "\64\0\u048d\4\103\0\56\4\2\0\u010d\4\3\0\20\4\12\0\2\4"+ + "\24\0\57\4\20\0\31\4\10\0\120\4\47\0\11\4\2\0\147\4"+ + "\2\0\4\4\1\0\2\4\16\0\12\4\120\0\10\4\1\0\3\4"+ + "\1\0\4\4\1\0\27\4\25\0\1\4\7\0\64\4\16\0\62\4"+ + "\76\0\6\4\3\0\1\4\16\0\34\4\12\0\27\4\31\0\35\4"+ + "\7\0\57\4\34\0\1\4\60\0\51\4\27\0\3\4\1\0\10\4"+ + "\24\0\27\4\3\0\1\4\5\0\60\4\1\0\1\4\3\0\2\4"+ + "\2\0\5\4\2\0\1\4\1\0\1\4\30\0\3\4\43\0\6\4"+ + "\2\0\6\4\2\0\6\4\11\0\7\4\1\0\7\4\221\0\43\4"+ + "\35\0\u2ba4\4\14\0\27\4\4\0\61\4\u2104\0\u012e\4\2\0\76\4"+ + "\2\0\152\4\46\0\7\4\14\0\5\4\5\0\1\4\1\0\12\4"+ + "\1\0\15\4\1\0\5\4\1\0\1\4\1\0\2\4\1\0\2\4"+ + "\1\0\154\4\41\0\u016b\4\22\0\100\4\2\0\66\4\50\0\15\4"+ + "\66\0\2\4\30\0\3\4\31\0\1\4\6\0\5\4\1\0\207\4"+ + "\7\0\1\4\34\0\32\4\4\0\1\4\1\0\32\4\13\0\131\4"+ + "\3\0\6\4\2\0\6\4\2\0\6\4\2\0\3\4\3\0\2\4"+ + "\3\0\2\4\31\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 = + "\11\0\3\1\1\2\1\3\2\2\1\4\1\5\1\6"+ + "\1\7\1\10\1\11\1\12\1\13\1\14\1\15\1\16"+ + "\1\17\1\12\1\20\1\1\1\0\1\21\1\0\2\22"+ + "\1\23\3\22\1\24"; + + private static int [] zzUnpackAction() { + int [] result = new int[41]; + 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\26\0\54\0\102\0\130\0\156\0\204\0\232"+ + "\0\260\0\306\0\334\0\362\0\306\0\u0108\0\362\0\u011e"+ + "\0\306\0\306\0\u0134\0\u014a\0\u0160\0\u0176\0\u018c\0\306"+ + "\0\306\0\306\0\306\0\306\0\u01a2\0\306\0\u011e\0\u01b8"+ + "\0\306\0\362\0\u01ce\0\u01e4\0\306\0\u01fa\0\u0210\0\u0226"+ + "\0\u01ce"; + + private static int [] zzUnpackRowMap() { + int [] result = new int[41]; + 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 = + "\6\12\1\13\1\14\16\12\1\15\2\16\4\15\1\17"+ + "\5\15\1\20\6\15\1\21\1\22\1\15\1\16\1\23"+ + "\4\15\1\17\14\15\1\21\1\22\1\12\2\24\4\12"+ + "\1\14\15\12\1\22\1\12\2\25\4\12\1\14\16\12"+ + "\1\15\2\26\2\27\2\15\1\17\1\27\1\30\1\15"+ + "\1\31\1\32\1\15\4\27\1\33\2\15\1\22\1\12"+ + "\2\16\2\27\2\12\1\14\1\27\1\12\1\34\1\12"+ + "\1\32\1\12\4\27\10\12\1\35\2\12\1\14\6\12"+ + "\4\35\1\12\1\36\11\12\1\14\5\12\1\37\10\12"+ + "\35\0\1\40\24\0\1\41\1\42\17\0\2\16\27\0"+ + "\1\43\11\0\1\44\3\43\6\0\1\23\24\0\2\24"+ + "\24\0\2\25\24\0\2\26\26\0\2\27\3\0\1\27"+ + "\5\0\4\27\7\0\3\35\10\0\4\35\13\0\1\45"+ + "\21\0\3\43\10\0\4\43\7\0\3\43\10\0\1\43"+ + "\1\46\2\43\7\0\3\43\10\0\2\43\1\47\1\43"+ + "\7\0\3\43\10\0\1\43\1\50\2\43\7\0\3\43"+ + "\10\0\3\43\1\51\4\0"; + + private static int [] zzUnpackTrans() { + int [] result = new int[572]; + 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 = + "\11\0\1\11\2\1\1\11\3\1\2\11\5\1\5\11"+ + "\1\1\1\11\1\1\1\0\1\11\1\0\2\1\1\11"+ + "\4\1"; + + private static int [] zzUnpackAttribute() { + int [] result = new int[41]; + 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: */ + private boolean myJdk15Enabled; + private DocCommentTokenTypes myTokenTypes; + + public _JavaDocLexer(boolean isJdk15Enabled, DocCommentTokenTypes tokenTypes) { + this((java.io.Reader)null); + myJdk15Enabled = isJdk15Enabled; + myTokenTypes = tokenTypes; + } + + public boolean checkAhead(char c) { + if (zzMarkedPos >= zzBuffer.length()) return false; + return zzBuffer.charAt(zzMarkedPos) == c; + } + + public void goTo(int offset) { + zzCurrentPos = zzMarkedPos = zzStartRead = offset; + zzPushbackPos = 0; + zzAtEOF = offset < zzEndRead; + } + + + _JavaDocLexer(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. + */ + _JavaDocLexer(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 < 1606) { + 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 12: + { return myTokenTypes.tagValueSharp(); + } + case 21: break; + case 16: + { yybegin(COMMENT_DATA); return myTokenTypes.tagValueGT(); + } + case 22: break; + case 3: + { return myTokenTypes.space(); + } + case 23: break; + case 6: + { return myTokenTypes.commentData(); + } + case 24: break; + case 5: + { yybegin(COMMENT_DATA); return myTokenTypes.inlineTagEnd(); + } + case 25: break; + case 19: + { yybegin(COMMENT_DATA_START); return myTokenTypes.commentStart(); + } + case 26: break; + case 7: + { if (checkAhead('<') || checkAhead('\"')) yybegin(COMMENT_DATA); + else if (checkAhead('\u007b') ) yybegin(COMMENT_DATA); // lbrace - there's a error in JLex when typing lbrace directly + else yybegin(DOC_TAG_VALUE); + return myTokenTypes.space(); + } + case 27: break; + case 8: + { yybegin(DOC_TAG_VALUE); return myTokenTypes.space(); + } + case 28: break; + case 10: + { return myTokenTypes.tagValueToken(); + } + case 29: break; + case 18: + { yybegin(TAG_DOC_SPACE); return myTokenTypes.tagName(); + } + case 30: break; + case 9: + { yybegin(COMMENT_DATA); return myTokenTypes.space(); + } + case 31: break; + case 20: + { yybegin(PARAM_TAG_SPACE); return myTokenTypes.tagName(); + } + case 32: break; + case 1: + { return myTokenTypes.badCharacter(); + } + case 33: break; + case 15: + { yybegin(DOC_TAG_VALUE); return myTokenTypes.tagValueRParen(); + } + case 34: break; + case 11: + { yybegin(DOC_TAG_VALUE_IN_PAREN); return myTokenTypes.tagValueLParen(); + } + case 35: break; + case 13: + { return myTokenTypes.tagValueComma(); + } + case 36: break; + case 14: + { if (myJdk15Enabled) { + yybegin(DOC_TAG_VALUE_IN_LTGT); + return myTokenTypes.tagValueLT(); + } + else { + yybegin(COMMENT_DATA); + return myTokenTypes.commentData(); + } + } + case 37: break; + case 4: + { if (checkAhead('@')) { + yybegin(INLINE_TAG_NAME); + return myTokenTypes.inlineTagStart(); + } + else{ + yybegin(COMMENT_DATA); + return myTokenTypes.inlineTagStart(); + } + } + case 38: break; + case 2: + { yybegin(COMMENT_DATA); return myTokenTypes.commentData(); + } + case 39: break; + case 17: + { return myTokenTypes.commentEnd(); + } + case 40: break; + default: + if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { + zzAtEOF = true; + zzDoEOF(); + return null; + } + else { + zzScanError(ZZ_NO_MATCH); + } + } + } + } + + +} diff --git a/java/java-psi-impl/src/com/intellij/lexer/_JavaLexer.flex b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.flex index 30413b509690..4d3de09b8d34 100644 --- a/java/java-psi-impl/src/com/intellij/lexer/_JavaLexer.flex +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.flex @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.lexer; +package com.intellij.lang.java.lexer; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.JavaTokenType; diff --git a/java/java-psi-impl/src/com/intellij/lexer/_JavaLexer.java b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.java index 1c5711cc4c25..517108e8bcf2 100644 --- a/java/java-psi-impl/src/com/intellij/lexer/_JavaLexer.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.java @@ -14,9 +14,10 @@ * limitations under the License. */ -/* The following code was generated by JFlex 1.4.3 on 1/17/13 8:47 PM */ -package com.intellij.lexer; +/* The following code was generated by JFlex 1.4.3 on 05.06.13 17:47 */ +package com.intellij.lang.java.lexer; +import com.intellij.lexer.FlexLexer; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.JavaTokenType; import com.intellij.psi.impl.source.tree.JavaDocElementType; @@ -27,8 +28,8 @@ import com.intellij.psi.tree.IElementType; /** * This class is a scanner generated by * <a href="http://www.jflex.de/">JFlex</a> 1.4.3 - * on 1/17/13 8:47 PM from the specification file - * <tt>/home/sher/Projects/IDEA/tools/lexer/../../community/java/java-psi-impl/src/com/intellij/lexer/_JavaLexer.flex</tt> + * on 05.06.13 17:47 from the specification file + * <tt>C:/Users/roman.shevchenko/Projects/IDEA/tools/lexer/../../community/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.flex</tt> */ class _JavaLexer implements FlexLexer { /** initial size of the lookahead buffer */ @@ -60,87 +61,109 @@ class _JavaLexer implements FlexLexer { "\1\46\1\2\1\43\1\35\1\50\1\37\1\42\1\53\1\2\1\30"+ "\1\36\1\27\1\31\1\54\1\55\1\51\1\44\1\56\1\72\1\61"+ "\1\73\1\100\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\2\4\0\1\2\5\0\27\2\1\0\37\2\1\0\u01ca\2\4\0"+ + "\14\2\16\0\5\2\7\0\1\2\1\0\1\2\21\0\160\3\5\2"+ + "\1\0\2\2\2\0\4\2\10\0\1\2\1\0\3\2\1\0\1\2"+ + "\1\0\24\2\1\0\123\2\1\0\213\2\1\0\5\3\2\0\236\2"+ + "\11\0\46\2\2\0\1\2\7\0\47\2\11\0\55\3\1\0\1\3"+ + "\1\0\2\3\1\0\2\3\1\0\1\3\10\0\33\2\5\0\3\2"+ + "\15\0\4\3\7\0\1\2\4\0\13\3\5\0\53\2\37\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\131\2\13\3\1\2\16\0\12\3\41\2"+ + "\11\3\2\2\4\0\1\2\5\0\26\2\4\3\1\2\11\3\1\2"+ + "\3\3\1\2\5\3\22\0\31\2\3\3\244\0\4\3\66\2\3\3"+ + "\1\2\22\3\1\2\7\3\12\2\2\3\2\0\12\3\1\0\7\2"+ + "\1\0\7\2\1\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\1\2\10\0\1\3\4\0\2\2\1\0"+ + "\3\2\2\3\2\0\12\3\4\2\7\0\1\2\5\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\3\0\1\3\7\0\4\2\1\0\1\2\7\0\14\3\3\2"+ + "\1\3\13\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\7\3"+ + "\2\0\2\3\2\0\3\3\10\0\2\3\4\0\2\2\1\0\3\2"+ + "\2\3\2\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\14\2\4\0\5\3\3\0\3\3"+ + "\1\0\4\3\2\0\1\2\6\0\1\3\16\0\12\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\3\0\1\2\7\3\1\0\3\3\1\0\4\3\7\0"+ + "\2\3\1\0\2\2\6\0\2\2\2\3\2\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"+ - "\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"; + "\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\2\3\2\0\12\3\1\0\2\2\17\0"+ + "\2\3\1\0\10\2\1\0\3\2\1\0\51\2\2\0\1\2\7\3"+ + "\1\0\3\3\1\0\4\3\1\2\10\0\1\3\10\0\2\2\2\3"+ + "\2\0\12\3\12\0\6\2\2\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\44\2\4\0\24\3\1\0\2\3\5\2\13\3\1\0"+ + "\44\3\11\0\1\3\71\0\53\2\24\3\1\2\12\3\6\0\6\2"+ + "\4\3\4\2\3\3\1\2\3\3\2\2\7\3\3\2\4\3\15\2"+ + "\14\3\1\2\17\3\2\0\46\2\12\0\53\2\1\0\1\2\3\0"+ + "\u0149\2\1\0\4\2\2\0\7\2\1\0\1\2\1\0\4\2\2\0"+ + "\51\2\1\0\4\2\2\0\41\2\1\0\4\2\2\0\7\2\1\0"+ + "\1\2\1\0\4\2\2\0\17\2\1\0\71\2\1\0\4\2\2\0"+ + "\103\2\2\0\3\3\40\0\20\2\20\0\125\2\14\0\u026c\2\2\0"+ + "\21\2\1\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\1\2\5\0\106\2\12\0\35\2\3\0\14\3"+ + "\4\0\14\3\12\0\12\3\36\2\2\0\5\2\13\0\54\2\4\0"+ + "\21\3\7\2\2\3\6\0\12\3\46\0\27\2\5\3\4\0\65\2"+ + "\12\3\1\0\35\3\2\0\13\3\6\0\12\3\15\0\1\2\130\0"+ + "\5\3\57\2\21\3\7\2\4\0\12\3\21\0\11\3\14\0\3\3"+ + "\36\2\12\3\3\0\2\2\12\3\6\0\46\2\16\3\14\0\44\2"+ + "\24\3\10\0\12\3\3\0\3\2\12\3\44\2\122\0\3\3\1\0"+ + "\25\3\4\2\1\3\4\2\1\3\15\0\300\2\47\3\25\0\4\3"+ + "\u0116\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\16\0\5\3\32\0"+ + "\5\3\20\0\2\2\23\0\1\2\13\0\5\3\5\0\6\3\1\0"+ + "\1\2\15\0\1\2\20\0\15\2\3\0\32\2\26\0\15\3\4\0"+ + "\1\3\3\0\14\3\21\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\13\2\2\0\4\2\5\0\5\2\4\0\1\2\21\0"+ + "\51\2\u0a77\0\57\2\1\0\57\2\1\0\205\2\6\0\4\2\3\3"+ + "\16\0\46\2\12\0\66\2\11\0\1\2\17\0\1\3\27\2\11\0"+ + "\7\2\1\0\7\2\1\0\7\2\1\0\7\2\1\0\7\2\1\0"+ + "\7\2\1\0\7\2\1\0\7\2\1\0\40\3\57\0\1\2\u01d5\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\132\2\1\0\4\2\5\0\51\2"+ + "\3\0\136\2\21\0\33\2\65\0\20\2\u0200\0\u19b6\2\112\0\u51cc\2"+ + "\64\0\u048d\2\103\0\56\2\2\0\u010d\2\3\0\20\2\12\3\2\2"+ + "\24\0\57\2\1\3\14\0\2\3\1\0\31\2\10\0\120\2\2\3"+ + "\45\0\11\2\2\0\147\2\2\0\4\2\1\0\2\2\16\0\12\2"+ + "\120\0\10\2\1\3\3\2\1\3\4\2\1\3\27\2\5\3\20\0"+ + "\1\2\7\0\64\2\14\0\2\3\62\2\21\3\13\0\12\3\6\0"+ + "\22\3\6\2\3\0\1\2\4\0\12\3\34\2\10\3\2\0\27\2"+ + "\15\3\14\0\35\2\3\0\4\3\57\2\16\3\16\0\1\2\12\3"+ + "\46\0\51\2\16\3\11\0\3\2\1\3\10\2\2\3\2\0\12\3"+ + "\6\0\27\2\3\0\1\2\1\3\4\0\60\2\1\3\1\2\3\3"+ + "\2\2\2\3\5\2\2\3\1\2\1\3\1\2\30\0\3\2\43\0"+ + "\6\2\2\0\6\2\2\0\6\2\11\0\7\2\1\0\7\2\221\0"+ + "\43\2\10\3\1\0\2\3\2\0\12\3\6\0\u2ba4\2\14\0\27\2"+ + "\4\0\61\2\u2104\0\u012e\2\2\0\76\2\2\0\152\2\46\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\7\3"+ + "\14\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\13\0\131\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 @@ -749,7 +772,7 @@ class _JavaLexer implements FlexLexer { char [] map = new char[0x10000]; int i = 0; /* index in packed string */ int j = 0; /* index in unpacked array */ - while (i < 1784) { + while (i < 2238) { int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java index b55d028d78e9..2b436e78d926 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/JavaParserUtil.java @@ -20,7 +20,6 @@ import com.intellij.lang.*; import com.intellij.lang.impl.PsiBuilderAdapter; import com.intellij.lang.java.JavaLanguage; import com.intellij.lang.java.JavaParserDefinition; -import com.intellij.lexer.JavaDocLexer; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; @@ -202,8 +201,7 @@ public class JavaParserUtil { final PsiBuilderFactory factory = PsiBuilderFactory.getInstance(); final Lexer lexer = chameleon.getElementType() == JavaDocElementType.DOC_COMMENT - ? new JavaDocLexer(level.isAtLeast(LanguageLevel.JDK_1_5)) - : JavaParserDefinition.createLexer(level); + ? JavaParserDefinition.createDocLexer(level) : JavaParserDefinition.createLexer(level); final PsiBuilder builder = factory.createBuilder(project, chameleon, lexer, chameleon.getElementType().getLanguage(), chameleon.getChars()); setLanguageLevel(builder, level); diff --git a/java/java-psi-impl/src/com/intellij/lexer/JavaLexer.java b/java/java-psi-impl/src/com/intellij/lexer/JavaLexer.java index 13dd70775356..e6e5c4191893 100644 --- a/java/java-psi-impl/src/com/intellij/lexer/JavaLexer.java +++ b/java/java-psi-impl/src/com/intellij/lexer/JavaLexer.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,473 +15,13 @@ */ package com.intellij.lexer; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.JavaTokenType; -import com.intellij.psi.TokenType; -import com.intellij.psi.impl.source.tree.JavaDocElementType; -import com.intellij.psi.tree.IElementType; -import com.intellij.util.text.CharArrayUtil; -import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; -import java.io.IOException; -import java.util.Set; - -public class JavaLexer extends LexerBase { - private static final HashTable[] TABLES = new HashTable[]{ - new HashTable(LanguageLevel.JDK_1_5), - new HashTable(LanguageLevel.JDK_1_4), - new HashTable(LanguageLevel.JDK_1_3) - }; - - private static HashTable getTable(final LanguageLevel level) { - for (HashTable table : TABLES) { - if (level.isAtLeast(table.myLevel)) { - return table; - } - } - throw new IllegalArgumentException("Unsupported level: " + level); - } - - public static boolean isKeyword(String id, LanguageLevel level) { - return getTable(level).contains(id); - } - - private final _JavaLexer myFlexLexer; - private final HashTable myTable; - private CharSequence myBuffer; - private char[] myBufferArray; - private int myBufferIndex; - private int myBufferEndOffset; - private int myTokenEndOffset; // positioned after the last symbol of the current token - private IElementType myTokenType; - - public JavaLexer(@NotNull final LanguageLevel level) { - myFlexLexer = new _JavaLexer(level); - myTable = getTable(level); - } - - private static final class HashTable { - private static final int NUM_ENTRIES = 999; - private static final Logger LOG = Logger.getInstance("com.intellij.Lexer.JavaLexer"); - - private final LanguageLevel myLevel; - private final char[][] myTable = new char[NUM_ENTRIES][]; - private final IElementType[] myKeywords = new IElementType[NUM_ENTRIES]; - private final Set<String> myKeywordsInSet = new THashSet<String>(); - - private void add(String s, IElementType tokenType) { - char[] chars = s.toCharArray(); - int hashCode = chars[0] * 2; - for (int j = 1; j < chars.length; j++) { - hashCode += chars[j]; - } - int modHashCode = hashCode % NUM_ENTRIES; - LOG.assertTrue(myTable[modHashCode] == null); - - myTable[modHashCode] = chars; - myKeywords[modHashCode] = tokenType; - myKeywordsInSet.add(s); - } - - public boolean contains(String s) { - return myKeywordsInSet.contains(s); - } - - private boolean contains(int hashCode, final char[] bufferArray, final CharSequence buffer, int offset) { - int modHashCode = hashCode % NUM_ENTRIES; - final char[] kwd = myTable[modHashCode]; - if (kwd == null) return false; - - if (bufferArray != null) { - for (int j = 0; j < kwd.length; j++) { - if (bufferArray[j + offset] != kwd[j]) return false; - } - } else { - for (int j = 0; j < kwd.length; j++) { - if (buffer.charAt(j + offset) != kwd[j]) return false; - } - } - return true; - } - - private IElementType getTokenType(int hashCode) { - return myKeywords[hashCode % NUM_ENTRIES]; - } - - @SuppressWarnings({"HardCodedStringLiteral"}) - private HashTable(final LanguageLevel level) { - myLevel = level; - if (level.isAtLeast(LanguageLevel.JDK_1_4)) { - add("assert", JavaTokenType.ASSERT_KEYWORD); - if (level.isAtLeast(LanguageLevel.JDK_1_5)) { - add("enum", JavaTokenType.ENUM_KEYWORD); - } - } - add("abstract", JavaTokenType.ABSTRACT_KEYWORD); - add("default", JavaTokenType.DEFAULT_KEYWORD); - add("if", JavaTokenType.IF_KEYWORD); - add("private", JavaTokenType.PRIVATE_KEYWORD); - add("this", JavaTokenType.THIS_KEYWORD); - add("boolean", JavaTokenType.BOOLEAN_KEYWORD); - add("do", JavaTokenType.DO_KEYWORD); - add("implements", JavaTokenType.IMPLEMENTS_KEYWORD); - add("protected", JavaTokenType.PROTECTED_KEYWORD); - add("throw", JavaTokenType.THROW_KEYWORD); - add("break", JavaTokenType.BREAK_KEYWORD); - add("double", JavaTokenType.DOUBLE_KEYWORD); - add("import", JavaTokenType.IMPORT_KEYWORD); - add("public", JavaTokenType.PUBLIC_KEYWORD); - add("throws", JavaTokenType.THROWS_KEYWORD); - add("byte", JavaTokenType.BYTE_KEYWORD); - add("else", JavaTokenType.ELSE_KEYWORD); - add("instanceof", JavaTokenType.INSTANCEOF_KEYWORD); - add("return", JavaTokenType.RETURN_KEYWORD); - add("transient", JavaTokenType.TRANSIENT_KEYWORD); - add("case", JavaTokenType.CASE_KEYWORD); - add("extends", JavaTokenType.EXTENDS_KEYWORD); - add("int", JavaTokenType.INT_KEYWORD); - add("short", JavaTokenType.SHORT_KEYWORD); - add("try", JavaTokenType.TRY_KEYWORD); - add("catch", JavaTokenType.CATCH_KEYWORD); - add("final", JavaTokenType.FINAL_KEYWORD); - add("interface", JavaTokenType.INTERFACE_KEYWORD); - add("static", JavaTokenType.STATIC_KEYWORD); - add("void", JavaTokenType.VOID_KEYWORD); - add("char", JavaTokenType.CHAR_KEYWORD); - add("finally", JavaTokenType.FINALLY_KEYWORD); - add("long", JavaTokenType.LONG_KEYWORD); - add("strictfp", JavaTokenType.STRICTFP_KEYWORD); - add("volatile", JavaTokenType.VOLATILE_KEYWORD); - add("class", JavaTokenType.CLASS_KEYWORD); - add("float", JavaTokenType.FLOAT_KEYWORD); - add("native", JavaTokenType.NATIVE_KEYWORD); - add("super", JavaTokenType.SUPER_KEYWORD); - add("while", JavaTokenType.WHILE_KEYWORD); - add("const", JavaTokenType.CONST_KEYWORD); - add("for", JavaTokenType.FOR_KEYWORD); - add("new", JavaTokenType.NEW_KEYWORD); - add("switch", JavaTokenType.SWITCH_KEYWORD); - add("continue", JavaTokenType.CONTINUE_KEYWORD); - add("goto", JavaTokenType.GOTO_KEYWORD); - add("package", JavaTokenType.PACKAGE_KEYWORD); - add("synchronized", JavaTokenType.SYNCHRONIZED_KEYWORD); - add("true", JavaTokenType.TRUE_KEYWORD); - add("false", JavaTokenType.FALSE_KEYWORD); - add("null", JavaTokenType.NULL_KEYWORD); - } - } - - @Override - public final void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { - myBuffer = buffer; - myBufferArray = CharArrayUtil.fromSequenceWithoutCopying(buffer); - myBufferIndex = startOffset; - myBufferEndOffset = endOffset; - myTokenType = null; - myTokenEndOffset = startOffset; - myFlexLexer.reset(myBuffer, startOffset, endOffset, 0); - } - - @Override - public int getState() { - return 0; - } - - @Override - public final IElementType getTokenType() { - if (myTokenType == null) _locateToken(); - - return myTokenType; - } - - @Override - public final int getTokenStart() { - return myBufferIndex; - } - - @Override - public final int getTokenEnd() { - if (myTokenType == null) _locateToken(); - return myTokenEndOffset; - } - - - @Override - public final void advance() { - if (myTokenType == null) _locateToken(); - myTokenType = null; - } - - private void _locateToken() { - if (myTokenEndOffset == myBufferEndOffset) { - myTokenType = null; - myBufferIndex = myBufferEndOffset; - return; - } - - myBufferIndex = myTokenEndOffset; - - final char c = myBufferArray != null ? myBufferArray[myBufferIndex]:myBuffer.charAt(myBufferIndex); - switch (c) { - default: - flexLocateToken(); - break; - - case ' ': - case '\t': - case '\n': - case '\r': - case '\f': - myTokenType = TokenType.WHITE_SPACE; - myTokenEndOffset = getWhitespaces(myBufferIndex + 1); - break; - - case '/': - if (myBufferIndex + 1 >= myBufferEndOffset) { - myTokenType = JavaTokenType.DIV; - myTokenEndOffset = myBufferEndOffset; - } - else { - final char nextChar = myBufferArray != null ? myBufferArray[myBufferIndex + 1]:myBuffer.charAt(myBufferIndex + 1); - - if (nextChar == '/') { - myTokenType = JavaTokenType.END_OF_LINE_COMMENT; - myTokenEndOffset = getLineTerminator(myBufferIndex + 2); - } - else if (nextChar == '*') { - if (myBufferIndex + 2 >= myBufferEndOffset || - (myBufferArray != null ? myBufferArray[myBufferIndex + 2]:myBuffer.charAt(myBufferIndex + 2)) != '*' || - (myBufferIndex + 3 < myBufferEndOffset && - (myBufferArray != null ? myBufferArray[myBufferIndex + 3]:myBuffer.charAt(myBufferIndex + 3)) == '/')) { - myTokenType = JavaTokenType.C_STYLE_COMMENT; - myTokenEndOffset = getClosingComment(myBufferIndex + 2); - } - else { - myTokenType = JavaDocElementType.DOC_COMMENT; - myTokenEndOffset = getClosingComment(myBufferIndex + 3); - } - } - else if (c > 127 && Character.isJavaIdentifierStart(c)) { - myTokenEndOffset = getIdentifier(myBufferIndex + 1); - } - else { - flexLocateToken(); - } - } - break; - - case '"': - case '\'': - myTokenType = c == '"' ? JavaTokenType.STRING_LITERAL : JavaTokenType.CHARACTER_LITERAL; - myTokenEndOffset = getClosingParenthesis(myBufferIndex + 1, c); - } - - if (myTokenEndOffset > myBufferEndOffset) { - myTokenEndOffset = myBufferEndOffset; - } - } - - private int getWhitespaces(int pos) { - if (pos >= myBufferEndOffset) return myBufferEndOffset; - final CharSequence lBuffer = myBuffer; - final char[] lBufferArray = myBufferArray; - - char c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - - while (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f') { - pos++; - if (pos == myBufferEndOffset) return pos; - c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - } - - return pos; - } - - private void flexLocateToken() { - try { - myFlexLexer.goTo(myBufferIndex); - myTokenType = myFlexLexer.advance(); - myTokenEndOffset = myFlexLexer.getTokenEnd(); - } - catch (IOException e) { - // Can't be - } - } - - private int getClosingParenthesis(int offset, char c) { - int pos = offset; - final int lBufferEnd = myBufferEndOffset; - if (pos >= lBufferEnd) return lBufferEnd; - - final CharSequence lBuffer = myBuffer; - final char[] lBufferArray = myBufferArray; - char cur = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - - while (true) { - while (cur != c && cur != '\n' && cur != '\r' && cur != '\\') { - pos++; - if (pos >= lBufferEnd) return lBufferEnd; - cur = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - } - - if (cur == '\\') { - pos++; - if (pos >= lBufferEnd) return lBufferEnd; - cur = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - if (cur == '\n' || cur == '\r') continue; - pos++; - if (pos >= lBufferEnd) return lBufferEnd; - cur = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - } - else if (cur == c) { - break; - } - else { - pos--; - break; - } - } - - return pos + 1; - } - - private int getClosingComment(int offset) { - int pos = offset; - - final int lBufferEnd = myBufferEndOffset; - final CharSequence lBuffer = myBuffer; - final char[] lBufferArray = myBufferArray; - - while (pos < lBufferEnd - 1) { - final char c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - - if (c == '*' && (lBufferArray != null ? lBufferArray[pos + 1]:lBuffer.charAt(pos + 1)) == '/') { - break; - } - pos++; - } - - return pos + 2; - } - - private int getLineTerminator(int offset) { - int pos = offset; - final int lBufferEnd = myBufferEndOffset; - final CharSequence lBuffer = myBuffer; - final char[] lBufferArray = myBufferArray; - - while (pos < lBufferEnd) { - final char c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - if (c == '\r' || c == '\n') break; - pos++; - } - - return pos; - } - - private int getIdentifier(int offset) { - final CharSequence lBuffer = myBuffer; - final char[] lBufferArray = myBufferArray; - - int hashCode = (lBufferArray != null ? lBufferArray[offset - 1]:lBuffer.charAt(offset - 1)) * 2; - final int lBufferEnd = myBufferEndOffset; - - int pos = offset; - if (pos < lBufferEnd) { - char c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - - while (c >= 'a' && c <= 'z' || - c >= 'A' && c <= 'Z' || - c >= '0' && c <= '9' || - c == '_' || - c == '$' || - c > 127 && Character.isJavaIdentifierPart(c)) { - pos++; - hashCode += c; - - if (pos == lBufferEnd) break; - c = lBufferArray != null ? lBufferArray[pos]:lBuffer.charAt(pos); - } - } - - if (myTable.contains(hashCode, lBufferArray, lBuffer, offset - 1)) { - myTokenType = myTable.getTokenType(hashCode); - } - else { - myTokenType = JavaTokenType.IDENTIFIER; - } - - return pos; - } - - @Override - public CharSequence getBufferSequence() { - return myBuffer; - } - - @Override - public final int getBufferEnd() { - return myBufferEndOffset; - } - - /* - public static void main(String[] args) throws IOException { - File root = new File(args[0]); - - Stats stats = new Stats(); - walk(root, stats); - - System.out.println("Scanned " + stats.files + " files, total of " + stats.lines + " lines in " + (stats.time / 1000000) + " ms."); - System.out.println("Size:" + stats.bytes); - - } - - private static void lex(File root, Stats stats) throws IOException { - stats.files++; - BufferedReader reader = new BufferedReader(new FileReader(root)); - String s; - StringBuilder buf = new StringBuilder(); - while ((s = reader.readLine()) != null) { - stats.lines++; - buf.append(s).append("\n"); - } - - stats.bytes += buf.length(); - - long start = System.nanoTime(); - lexText(buf); - stats.time += System.nanoTime() - start; - } - - private static void lexText(StringBuilder buf) { - JavaLexer lexer = new JavaLexer(LanguageLevel.JDK_1_5); - lexer.start(buf); - while (lexer.getTokenType() != null) { - lexer.advance(); - } - } - - private static class Stats { - public int files; - public int lines; - public long time; - public long bytes; - } - - private static void walk(File root, Stats stats) throws IOException { - if (root.isDirectory()) { - System.out.println("Lexing in " + root.getPath()); - for (File file : root.listFiles()) { - walk(file, stats); - } - } - else { - if (root.getName().endsWith(".java")) { - lex(root, stats); - } - } +/** @deprecated use com.intellij.lang.java.JavaLexer (to remove in IDEA 14) */ +@SuppressWarnings({"ClassNameSameAsAncestorName", "UnusedDeclaration"}) +public class JavaLexer extends com.intellij.lang.java.lexer.JavaLexer { + public JavaLexer(@NotNull LanguageLevel level) { + super(level); } - */ } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java index d0f86c7f8faa..120b7251f507 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java @@ -16,9 +16,9 @@ package com.intellij.psi.impl; import com.intellij.lang.*; +import com.intellij.lang.java.lexer.JavaLexer; import com.intellij.lang.java.parser.JavaParser; import com.intellij.lang.java.parser.JavaParserUtil; -import com.intellij.lexer.JavaLexer; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.pom.java.LanguageLevel; @@ -157,7 +157,7 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps final PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics(); final PsiClass refClass = resolveResult.getElement(); assert refClass != null : type; - return new LightClassReference(myManager, type.getPresentableText(), refClass, resolveResult.getSubstitutor()); + return new LightClassReference(myManager, type.getInternalCanonicalText(), refClass, resolveResult.getSubstitutor()); } @NotNull diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiNameHelperImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiNameHelperImpl.java index c08d2dafec3d..5d931e6b6d17 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiNameHelperImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiNameHelperImpl.java @@ -1,21 +1,21 @@ /* -* 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. -*/ + * 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.psi.impl; -import com.intellij.lexer.JavaLexer; +import com.intellij.lang.java.lexer.JavaLexer; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParsingUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParsingUtil.java index 39c1829d21a3..5113ed4d1fff 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParsingUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParsingUtil.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. @@ -16,9 +16,9 @@ package com.intellij.psi.impl.compiled; import com.intellij.lang.PsiBuilder; +import com.intellij.lang.java.lexer.JavaLexer; import com.intellij.lang.java.parser.JavaParser; import com.intellij.lang.java.parser.JavaParserUtil; -import com.intellij.lexer.JavaLexer; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightKeyword.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightKeyword.java index 306d2ac549f8..82b0d7178e66 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightKeyword.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightKeyword.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -16,7 +16,7 @@ package com.intellij.psi.impl.light; 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.pom.java.LanguageLevel; import com.intellij.psi.*; @@ -38,7 +38,7 @@ public class LightKeyword extends LightElement implements PsiKeyword, PsiJavaTok @Override public IElementType getTokenType(){ - Lexer lexer = new JavaLexer(LanguageLevel.HIGHEST); + Lexer lexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST); lexer.start(myText); return lexer.getTokenType(); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImportStatementBaseImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImportStatementBaseImpl.java index 254d8b39f27a..b252f1f5d6a2 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImportStatementBaseImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImportStatementBaseImpl.java @@ -22,6 +22,7 @@ import com.intellij.psi.PsiJavaCodeReferenceElement; import com.intellij.psi.impl.java.stubs.PsiImportStatementStub; import com.intellij.psi.impl.source.tree.ChildRole; import com.intellij.psi.stubs.IStubElementType; +import com.intellij.psi.util.PsiUtilCore; /** * @author dsl @@ -49,7 +50,7 @@ public abstract class PsiImportStatementBaseImpl extends JavaStubPsiElement<PsiI @Override public PsiJavaCodeReferenceElement getImportReference() { - assert isValid(); + PsiUtilCore.ensureValid(this); final PsiImportStatementStub stub = getStub(); if (stub != null) { return stub.getReference(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaFileImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaFileImpl.java index dda81bca4f16..e56f53cbfbdf 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaFileImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaFileImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -16,8 +16,6 @@ package com.intellij.psi.impl.source; import com.intellij.ide.highlighter.JavaFileType; -import com.intellij.lexer.JavaLexer; -import com.intellij.lexer.Lexer; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.roots.FileIndexFacade; @@ -33,14 +31,6 @@ public class PsiJavaFileImpl extends PsiJavaFileBaseImpl { super(JavaStubElementTypes.JAVA_FILE, JavaStubElementTypes.JAVA_FILE, file); } - public String toString(){ - return "PsiJavaFile:" + getName(); - } - - public Lexer createLexer() { - return new JavaLexer(getLanguageLevel()); - } - @NotNull @Override public GlobalSearchScope getResolveScope() { @@ -59,4 +49,9 @@ public class PsiJavaFileImpl extends PsiJavaFileBaseImpl { public FileType getFileType() { return JavaFileType.INSTANCE; } + + @Override + public String toString() { + return "PsiJavaFile:" + getName(); + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java index 71df6027483e..847d7f313141 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.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. @@ -19,17 +19,14 @@ import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.lang.PsiBuilder; import com.intellij.lang.java.JavaLanguage; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.lang.java.parser.JavaParserUtil; import com.intellij.lang.java.parser.JavadocParser; -import com.intellij.lexer.JavaLexer; +import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.impl.source.javadoc.PsiDocCommentImpl; -import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef; -import com.intellij.psi.impl.source.javadoc.PsiDocParamRef; -import com.intellij.psi.impl.source.javadoc.PsiDocTagImpl; -import com.intellij.psi.impl.source.javadoc.PsiInlineDocTagImpl; +import com.intellij.psi.impl.source.javadoc.*; import com.intellij.psi.tree.*; import com.intellij.psi.tree.java.IJavaDocElementType; import com.intellij.util.ReflectionUtil; @@ -123,7 +120,7 @@ public interface JavaDocElementType { @Override public boolean isParsable(final CharSequence buffer, Language fileLanguage, final Project project) { - final JavaLexer lexer = new JavaLexer(LanguageLevelProjectExtension.getInstance(project).getLanguageLevel()); + Lexer lexer = JavaParserDefinition.createLexer(LanguageLevelProjectExtension.getInstance(project).getLanguageLevel()); lexer.start(buffer); if (lexer.getTokenType() == DOC_COMMENT) { lexer.advance(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java index 3ffd29fc03bc..14bc9b457614 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java @@ -17,8 +17,10 @@ package com.intellij.psi.impl.source.tree; import com.intellij.lang.*; import com.intellij.lang.java.JavaLanguage; -import com.intellij.lang.java.parser.*; -import com.intellij.lexer.JavaLexer; +import com.intellij.lang.java.JavaParserDefinition; +import com.intellij.lang.java.parser.JavaParser; +import com.intellij.lang.java.parser.JavaParserUtil; +import com.intellij.lang.java.parser.ReferenceParser; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.pom.java.LanguageLevel; @@ -167,7 +169,7 @@ public interface JavaElementType { @Override public int getErrorsCount(final CharSequence seq, Language fileLanguage, final Project project) { - final Lexer lexer = new JavaLexer(LanguageLevel.HIGHEST); + Lexer lexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST); lexer.start(seq); if (lexer.getTokenType() != JavaTokenType.LBRACE) return IErrorCounterReparseableElementType.FATAL_ERROR; diff --git a/java/java-tests/testData/codeInsight/completion/keywords/instanceofAfterStatementStart.java b/java/java-tests/testData/codeInsight/completion/keywords/instanceofAfterStatementStart.java new file mode 100644 index 000000000000..b5ab87da8f4a --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/keywords/instanceofAfterStatementStart.java @@ -0,0 +1,5 @@ +class Foo { + void test(Object o) { + o <caret> + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisInInterface.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisInInterface.java index 4f1b9b37218e..ed86aac1e7af 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisInInterface.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisInInterface.java @@ -3,12 +3,12 @@ class C implements A { } interface A { - A a = new C(<error descr="Cannot find symbol variable this">this</error>); + A a = new C(<error descr="'A.this' cannot be referenced from a static context">this</error>); A a1 = new C(<error descr="Cannot find symbol variable this">this</error>){}; class B { A foo() { - return <error descr="Cannot find symbol variable this">A.this</error>; + return <error descr="'A.this' cannot be referenced from a static context">A.this</error>; } B foo1() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/IDEA108285.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/IDEA108285.java new file mode 100644 index 000000000000..fedc7cd78fea --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/IDEA108285.java @@ -0,0 +1,5 @@ +class Test<T> { + interface NestedInterface<U extends <error descr="'Test.this' cannot be referenced from a static context">T</error>> { + <V extends <error descr="'Test.this' cannot be referenced from a static context">T</error>> void foo(); + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA107654.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA107654.java new file mode 100644 index 000000000000..7af6110553db --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA107654.java @@ -0,0 +1,3 @@ +class X<A extends X<A>> { + static class Y<B extends Y> extends X<<error descr="Type parameter 'B' is not within its bound; should extend 'X<B>'">B</error>> {} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA108287.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA108287.java new file mode 100644 index 000000000000..e717d2d2d558 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA108287.java @@ -0,0 +1,9 @@ +class Foo<T> { + static class Nested {}; +} +class Bar extends Foo<<error descr="Nested is not accessible in current context">Bar.Nested</error>> {} + +interface FooI<T> { + interface Nested {}; +} +interface BarI extends FooI<<error descr="Nested is not accessible in current context">BarI.Nested</error>> {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA55510.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA55510.java new file mode 100644 index 000000000000..ee56cb21ca1a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA55510.java @@ -0,0 +1,14 @@ +abstract class IdeaBugTest<M extends IdeaBugTest.Mapping> +{ + static class Mapping {} +} + +class BugTestSub extends IdeaBugTest<<error descr="SubMapping is not accessible in current context">BugTestSub.SubMapping</error>> +{ + public abstract static class SubMapping extends Mapping {} +} + +class BugTestSub1 extends IdeaBugTest<BugTestSub1.SubMapping> +{ + public abstract static class SubMapping extends IdeaBugTest.Mapping {} //fqn here +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA77128.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA77128.java new file mode 100644 index 000000000000..cc889ab5df03 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA77128.java @@ -0,0 +1,11 @@ +import java.util.*; +class A { + public static void main(String[] args) { + List<String> strings = new ArrayList<>(); + + List<? super Integer> list = new ArrayList<>(); + list.addAll<error descr="'addAll(java.util.Collection<? extends capture<? super java.lang.Integer>>)' in 'java.util.List' cannot be applied to '(java.util.List<java.lang.String>)'">(strings)</error>; + + System.out.println(list.toString()); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/IDEA108195.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/IDEA108195.java new file mode 100644 index 000000000000..a88675fedd31 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/IDEA108195.java @@ -0,0 +1,12 @@ +class Demo { + + Function<Supplier<Double>, ? extends Supplier<Double>> mapper2 = (sa) -> () -> sa.get() + 1.0; + + interface Supplier<T> { + public T get(); + } + + interface Function<T, R> { + public R apply(T t); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ThisAccessibility.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ThisAccessibility.java index c43ef5200b04..a87cbccdbe2d 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ThisAccessibility.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ThisAccessibility.java @@ -1,5 +1,5 @@ interface Bazz { - Bazz foo = <error descr="Cannot find symbol variable this">Bazz.this</error>; + Bazz foo = <error descr="'Bazz.this' cannot be referenced from a static context">Bazz.this</error>; static void foo1() { Bazz foo = <error descr="'Bazz.this' cannot be referenced from a static context">Bazz.this</error>; } @@ -7,7 +7,7 @@ interface Bazz { Runnable bar = new Runnable() { @Override public void run() { - Bazz f = <error descr="Cannot find symbol variable this">Bazz.this</error>; + Bazz f = <error descr="'Bazz.this' cannot be referenced from a static context">Bazz.this</error>; } }; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeParameterClass/afterWildcard.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeParameterClass/afterWildcard.java new file mode 100644 index 000000000000..d81cc1623753 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeParameterClass/afterWildcard.java @@ -0,0 +1,20 @@ +// "Make 'a' implement 'b'" "true" +interface b<T> { + void f(T t); +} + +class a implements b<Integer> { + public void f(Integer integer) { + + } +} + +class X { + void h(b<? super Integer> i) { + + } + + void g() { + h(new a()); + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeParameterClass/beforeWildcard.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeParameterClass/beforeWildcard.java new file mode 100644 index 000000000000..0a95dba3731a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeParameterClass/beforeWildcard.java @@ -0,0 +1,16 @@ +// "Make 'a' implement 'b'" "true" +interface b<T> { + void f(T t); +} + +class a {} + +class X { + void h(b<? super Integer> i) { + + } + + void g() { + h(new a<caret>()); + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsAnnotateLibrary_after.xml b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsAnnotateLibrary_after.xml index 97d0dd5efeba..8b6ad7dfa54f 100644 --- a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsAnnotateLibrary_after.xml +++ b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsAnnotateLibrary_after.xml @@ -1,11 +1,11 @@ <root> - <item name='p.TestDeannotation java.lang.String get()'> - <annotation name='org.jetbrains.annotations.NotNull'/> - </item> - <item name='p.TestDeannotation1 java.lang.String get(java.lang.String) 0'> - <annotation name='org.jetbrains.annotations.NotNull'/> - </item> <item name='p.Test java.lang.String get()'> <annotation name='org.jetbrains.annotations.NotNull'/> </item> + <item name='p.TestDeannotation java.lang.String get()'> + <annotation name='org.jetbrains.annotations.NotNull'/> + </item> + <item name='p.TestDeannotation1 java.lang.String get(java.lang.String) 0'> + <annotation name='org.jetbrains.annotations.NotNull'/> + </item> </root>
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsDeannotation1_after.xml b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsDeannotation1_after.xml index 62fa98b42b99..ae478685803c 100644 --- a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsDeannotation1_after.xml +++ b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsDeannotation1_after.xml @@ -1,5 +1,5 @@ <root> - <item name='p.TestDeannotation java.lang.String get()'> - <annotation name='org.jetbrains.annotations.NotNull'/> - </item> + <item name='p.TestDeannotation java.lang.String get()'> + <annotation name='org.jetbrains.annotations.NotNull'/> + </item> </root>
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsDeannotation_after.xml b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsDeannotation_after.xml index 7b5c7f721a8c..5ef438488a57 100644 --- a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsDeannotation_after.xml +++ b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/p/annotationsDeannotation_after.xml @@ -1,5 +1,5 @@ <root> <item name='p.TestDeannotation1 java.lang.String get(java.lang.String) 0'> - <annotation name='org.jetbrains.annotations.NotNull'/> - </item> + <annotation name='org.jetbrains.annotations.NotNull'/> + </item> </root>
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsExistingExternalName_after.xml b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsExistingExternalName_after.xml index 3ea793646df7..1e77ab91421d 100644 --- a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsExistingExternalName_after.xml +++ b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsExistingExternalName_after.xml @@ -1,13 +1,13 @@ <root> - <item name='suppressed.ExistingExternalName java.lang.String foo()'> - <annotation name='org.jetbrains.annotations.NotNull'/> + <item name='suppressed.ExistingExternalName java.lang.String foo()'> + <annotation name='org.jetbrains.annotations.NotNull'/> + <annotation name='java.lang.SuppressWarnings'> + <val val=""SillyAssignment""/> + </annotation> + </item> + <item name='suppressed.SecondSuppression void second()'> <annotation name='java.lang.SuppressWarnings'> - <val val=""SillyAssignment""/> + <val val="{DoesntMatterWhat}"/> </annotation> - </item> - <item name='suppressed.SecondSuppression void second()'> - <annotation name='java.lang.SuppressWarnings'> - <val val="{DoesntMatterWhat}"/> - </annotation> - </item> + </item> </root>
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsNewSuppress_after.xml b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsNewSuppress_after.xml index 03f8c40dc079..cc3e7078cc0e 100644 --- a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsNewSuppress_after.xml +++ b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsNewSuppress_after.xml @@ -1,15 +1,15 @@ <root> - <item name='suppressed.ExistingExternalName java.lang.String foo()'> - <annotation name='org.jetbrains.annotations.NotNull'/> - </item> - <item name='suppressed.SecondSuppression void second()'> - <annotation name='java.lang.SuppressWarnings'> - <val val="{DoesntMatterWhat}"/> - </annotation> - </item> + <item name='suppressed.ExistingExternalName java.lang.String foo()'> + <annotation name='org.jetbrains.annotations.NotNull'/> + </item> <item name='suppressed.NewSuppress void barr()'> <annotation name='java.lang.SuppressWarnings'> <val val=""SillyAssignment""/> </annotation> </item> + <item name='suppressed.SecondSuppression void second()'> + <annotation name='java.lang.SuppressWarnings'> + <val val="{DoesntMatterWhat}"/> + </annotation> + </item> </root>
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsSecondSuppression_after.xml b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsSecondSuppression_after.xml index afdf1536b9d0..70cbe4ca03c2 100644 --- a/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsSecondSuppression_after.xml +++ b/java/java-tests/testData/codeInsight/externalAnnotations/content/anno/suppressed/annotationsSecondSuppression_after.xml @@ -1,10 +1,10 @@ <root> - <item name='suppressed.ExistingExternalName java.lang.String foo()'> - <annotation name='org.jetbrains.annotations.NotNull'/> - </item> - <item name='suppressed.SecondSuppression void second()'> - <annotation name='java.lang.SuppressWarnings'> - <val val="{DoesntMatterWhat, "SillyAssignment"}"/> - </annotation> - </item> + <item name='suppressed.ExistingExternalName java.lang.String foo()'> + <annotation name='org.jetbrains.annotations.NotNull'/> + </item> + <item name='suppressed.SecondSuppression void second()'> + <annotation name='java.lang.SuppressWarnings'> + <val val="{DoesntMatterWhat, "SillyAssignment"}"/> + </annotation> + </item> </root>
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/externalAnnotations/content/annoMultiRoot/root1/multiRoot/annotations_after.xml b/java/java-tests/testData/codeInsight/externalAnnotations/content/annoMultiRoot/root1/multiRoot/annotations_after.xml index f635a33b9c73..51d624c76d31 100644 --- a/java/java-tests/testData/codeInsight/externalAnnotations/content/annoMultiRoot/root1/multiRoot/annotations_after.xml +++ b/java/java-tests/testData/codeInsight/externalAnnotations/content/annoMultiRoot/root1/multiRoot/annotations_after.xml @@ -1,7 +1,7 @@ <root> - <item name='multiRoot.Test java.lang.String get(java.lang.String) 0'> - <annotation name='org.jetbrains.annotations.NotNull'> - <val name="value" val=""bar""/> - </annotation> - </item> + <item name='multiRoot.Test java.lang.String get(java.lang.String) 0'> + <annotation name='org.jetbrains.annotations.NotNull'> + <val name="value" val=""bar""/> + </annotation> + </item> </root>
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/externalAnnotations/content/annoMultiRoot/root2/multiRoot/annotations_after.xml b/java/java-tests/testData/codeInsight/externalAnnotations/content/annoMultiRoot/root2/multiRoot/annotations_after.xml index 60e041c8bd99..2cc3ed107ab5 100644 --- a/java/java-tests/testData/codeInsight/externalAnnotations/content/annoMultiRoot/root2/multiRoot/annotations_after.xml +++ b/java/java-tests/testData/codeInsight/externalAnnotations/content/annoMultiRoot/root2/multiRoot/annotations_after.xml @@ -1,7 +1,7 @@ <root> - <item name='multiRoot.Test java.lang.String get(java.lang.String)'> - <annotation name='org.jetbrains.annotations.Nullable'> - <val name="value" val=""bar""/> - </annotation> - </item> + <item name='multiRoot.Test java.lang.String get(java.lang.String)'> + <annotation name='org.jetbrains.annotations.Nullable'> + <val name="value" val=""bar""/> + </annotation> + </item> </root>
\ No newline at end of file diff --git a/java/java-tests/testData/compiler/notNullVerification/ConstructorParamWithMessage.java b/java/java-tests/testData/compiler/notNullVerification/ConstructorParamWithMessage.java new file mode 100644 index 000000000000..3da49f30b8da --- /dev/null +++ b/java/java-tests/testData/compiler/notNullVerification/ConstructorParamWithMessage.java @@ -0,0 +1,6 @@ +import org.jetbrains.annotations.NotNull; + +public class ConstructorParamWithMessage { + public ConstructorParamWithMessage(@NotNull("ConstructorParam.ConstructorParam.o cant be null") Object o) { + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/compiler/notNullVerification/SimpleParamWithMessage.java b/java/java-tests/testData/compiler/notNullVerification/SimpleParamWithMessage.java new file mode 100644 index 000000000000..cdd8f75ab9b6 --- /dev/null +++ b/java/java-tests/testData/compiler/notNullVerification/SimpleParamWithMessage.java @@ -0,0 +1,6 @@ +import org.jetbrains.annotations.NotNull; + +public class SimpleParamWithMessage { + public void test(@NotNull("SimpleParamWithMessage.test(o) cant be null") Object o) { + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/compiler/notNullVerification/SimpleReturnWithMessage.java b/java/java-tests/testData/compiler/notNullVerification/SimpleReturnWithMessage.java new file mode 100644 index 000000000000..8d52dc853e97 --- /dev/null +++ b/java/java-tests/testData/compiler/notNullVerification/SimpleReturnWithMessage.java @@ -0,0 +1,8 @@ +import org.jetbrains.annotations.NotNull; + +public class SimpleReturnWithMessage { + @NotNull("This method cannot return null") + public Object test() { + return null; + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/after/A.java b/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/after/A.java new file mode 100644 index 000000000000..a5d52700d3e9 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/after/A.java @@ -0,0 +1,4 @@ +public class A { + + public static final String ONE; +}
\ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/after/B.java b/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/after/B.java new file mode 100644 index 000000000000..add876cb4ee2 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/after/B.java @@ -0,0 +1,6 @@ +public class B { + + static { + A.ONE = "foo"; + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/before/A.java b/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/before/A.java new file mode 100644 index 000000000000..96a276f862e9 --- /dev/null +++ b/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/before/A.java @@ -0,0 +1,3 @@ +public class A { + +}
\ No newline at end of file diff --git a/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/before/B.java b/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/before/B.java new file mode 100644 index 000000000000..a1009adeeb4d --- /dev/null +++ b/java/java-tests/testData/refactoring/moveMembers/finalFieldWithInitializer/before/B.java @@ -0,0 +1,7 @@ +public class B { + public static final String ONE; + + static { + ONE = "foo"; + } +}
\ No newline at end of file diff --git a/java/java-tests/testData/refactoring/pullUp/reuseSuperMethod/after/b/B.java b/java/java-tests/testData/refactoring/pullUp/reuseSuperMethod/after/b/B.java index de579f8aac76..d56b3b4fbcc9 100644 --- a/java/java-tests/testData/refactoring/pullUp/reuseSuperMethod/after/b/B.java +++ b/java/java-tests/testData/refactoring/pullUp/reuseSuperMethod/after/b/B.java @@ -1,8 +1,8 @@ package b; public class B { - protected void foo(){} - void method2Move() { foo(); } + + protected void foo(){} }
\ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 226dbfbbc55f..a55697a9d0b9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -958,6 +958,7 @@ class Foo { edt { myFixture.completeBasic() } + assert !lookup : myFixture.lookupElementStrings myFixture.checkResult 'class Foo extends <caret>' } @@ -1355,23 +1356,6 @@ class FooBar { assert !myFixture.editor.document.text.contains('fooBar') } - public void "test choose variable name by enter when selection by chars is disabled"() { - CodeInsightSettings.instance.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = false - myFixture.configureByText 'a.java', ''' -class FooBar { - void foo() { - FooBar <caret> - } -} -''' - type 'f' - assert lookup - assert !lookup.focused - assert myFixture.lookupElementStrings == ['fooBar'] - type '\n' - assert myFixture.editor.document.text.contains('fooBar') - } - public void "test middle matching and overwrite"() { myFixture.configureByText 'a.java', ''' class ListConfigKey { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java index bd406117d582..31fc1df91e02 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java @@ -98,6 +98,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase { public void testNewInMethodRefs() throws Exception { doTest(1, "new"); } public void testSpaceAfterInstanceof() throws Exception { doTest(false); } public void testInstanceofAfterUnresolved() throws Exception { doTest(1, "instanceof"); } + public void testInstanceofAfterStatementStart() throws Exception { doTest(1, "instanceof"); } public void testAbstractInInterface() throws Exception { doTest(1, "abstract"); } public void testCharInAnnotatedParameter() throws Exception { doTest(1, "char"); } public void testReturnInTernary() throws Exception { doTest(1, "return"); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index 4882f8b33cb2..223da60d4c9e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -20,6 +20,7 @@ import com.intellij.codeInsight.lookup.Lookup import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementPresentation import com.intellij.codeInsight.lookup.LookupManager +import com.intellij.codeInsight.lookup.impl.LookupImpl import com.intellij.lang.java.JavaLanguage import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.editor.LogicalPosition @@ -1395,4 +1396,14 @@ class Bar { assert !('Inner' in myFixture.lookupElementStrings) } + public void "test show static member after instance qualifier when nothing matches"() { + myFixture.configureByText "a.java", "class Foo{{ \"\".<caret> }}" + myFixture.completeBasic() + assert !('valueOf' in myFixture.lookupElementStrings) + ((LookupImpl)myFixture.lookup).hide() + myFixture.type 'val' + myFixture.completeBasic() + assert ('valueOf' in myFixture.lookupElementStrings) + } + } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index dd144e5d5f2e..fca092470feb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -247,6 +247,14 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testCaptureTopLevelWildcardsForConditionalExpression() throws Exception { doTest5(false);} public void testGenericsOverrideMethodInRawInheritor() throws Exception { doTest5(false);} + public void testIDEA107654() throws Exception { + doTest5(false); + } + + public void testIDEA55510() throws Exception { + doTest5(false); + } + public void testIDEA27185(){ doTest(LanguageLevel.JDK_1_6, JavaSdkVersion.JDK_1_6, false); } public void testIDEA67571(){ doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); } public void testTypeArgumentsOnRawType(){ doTest(LanguageLevel.JDK_1_6, JavaSdkVersion.JDK_1_6, false); } @@ -257,6 +265,14 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); } + public void testIDEA108287() throws Exception { + doTest5(false); + } + + public void testIDEA77128() throws Exception { + doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); + } + public void testDisableCastingToNestedWildcards() throws Exception { doTest5(false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java index 9761eb47729d..221bff09ccd2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java @@ -473,4 +473,14 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase { } } + public void testAutoImportIgnoresUnresolvedImportReferences() throws Throwable { + @NonNls String text = "package x; import xxx.yyy.ArrayList; class S {{ ArrayList<caret> r; }}"; + configureByText(StdFileTypes.JAVA, text); + + PsiJavaFile javaFile = (PsiJavaFile)getFile(); + PsiReference ref = javaFile.findReferenceAt(getEditor().getCaretModel().getOffset()-1); + ImportClassFix fix = new ImportClassFix((PsiJavaCodeReferenceElement)ref); + assertFalse(fix.isAvailable(getProject(), getEditor(), getFile())); + } + } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java index 2f49d7385b8c..7e68365f8b89 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java @@ -55,4 +55,5 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase { public void testJavacQuirks() { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(true, false); } public void testMethodReturnTypeSubstitutability() { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(true, false); } public void testIDEADEV11877() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(false, false); } + public void testIDEA108285() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(false, false); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java index 4b203962db58..c472501f45e5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java @@ -87,6 +87,7 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase { public void testConditionalInferenceFromOppositePart() { doTest(); } public void testDeclaredTypeParameterBoundsAndUnboundedWildcard() { doTest(); } public void testConflictResolution() throws Exception {doTest();} + public void testIDEA108195() throws Exception {doTest();} private void doTest() { doTest(false); diff --git a/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java b/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java index 4ba78cfd9b5b..b1b6a941f861 100644 --- a/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java +++ b/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java @@ -70,6 +70,13 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase { verifyCallThrowsException("@NotNull method SimpleReturn.test must not return null", instance, method); } + public void testSimpleReturnWithMessage() throws Exception { + Class testClass = prepareTest(); + Object instance = testClass.newInstance(); + Method method = testClass.getMethod("test"); + verifyCallThrowsException("This method cannot return null", instance, method); + } + public void testMultipleReturns() throws Exception { Class testClass = prepareTest(); Object instance = testClass.newInstance(); @@ -84,12 +91,25 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase { verifyCallThrowsException("Argument 0 for @NotNull parameter of SimpleParam.test must not be null", instance, method, (Object)null); } + public void testSimpleParamWithMessage() throws Exception { + Class testClass = prepareTest(); + Object instance = testClass.newInstance(); + Method method = testClass.getMethod("test", Object.class); + verifyCallThrowsException("SimpleParamWithMessage.test(o) cant be null", instance, method, (Object)null); + } + public void testConstructorParam() throws Exception { Class testClass = prepareTest(); Constructor method = testClass.getConstructor(Object.class); verifyCallThrowsException("Argument 0 for @NotNull parameter of ConstructorParam.<init> must not be null", null, method, (Object)null); } + public void testConstructorParamWithMessage() throws Exception { + Class testClass = prepareTest(); + Constructor method = testClass.getConstructor(Object.class); + verifyCallThrowsException("ConstructorParam.ConstructorParam.o cant be null", null, method, (Object)null); + } + public void testEnumConstructor() throws Exception { Class testClass = prepareTest(); Object field = testClass.getField("Value"); diff --git a/java/java-tests/testSrc/com/intellij/ide/util/frameworkSupport/FrameworkSupportProviderTestCase.java b/java/java-tests/testSrc/com/intellij/ide/util/frameworkSupport/FrameworkSupportProviderTestCase.java index 9a14e602a230..344935daf386 100644 --- a/java/java-tests/testSrc/com/intellij/ide/util/frameworkSupport/FrameworkSupportProviderTestCase.java +++ b/java/java-tests/testSrc/com/intellij/ide/util/frameworkSupport/FrameworkSupportProviderTestCase.java @@ -4,7 +4,7 @@ import com.intellij.facet.Facet; import com.intellij.facet.FacetManager; import com.intellij.facet.FacetTypeId; import com.intellij.facet.ui.FacetBasedFrameworkSupportProvider; -import com.intellij.framework.FrameworkType; +import com.intellij.framework.*; import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable; import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider; import com.intellij.ide.util.newProjectWizard.FrameworkSupportNode; @@ -112,6 +112,11 @@ public abstract class FrameworkSupportProviderTestCase extends IdeaTestCase { return configurable; } + protected void selectVersion(FrameworkType frameworkType, com.intellij.framework.FrameworkVersion version) { + myFrameworkSupportModel.setSelectedVersion(frameworkType.getId(), version); + } + + @NotNull protected <F extends Facet> F getFacet(FacetTypeId<F> id) { final F facet = FacetManager.getInstance(myModule).getFacetByType(id); assertNotNull(id + " facet not found", facet); diff --git a/java/java-tests/testSrc/com/intellij/lang/java/lexer/JavaLexerTest.java b/java/java-tests/testSrc/com/intellij/lang/java/lexer/JavaLexerTest.java index 113211720e39..d4e0d325a334 100644 --- a/java/java-tests/testSrc/com/intellij/lang/java/lexer/JavaLexerTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/java/lexer/JavaLexerTest.java @@ -15,7 +15,7 @@ */ package com.intellij.lang.java.lexer; -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.testFramework.LexerTestCase; @@ -158,7 +158,7 @@ public class JavaLexerTest extends LexerTestCase { @Override protected Lexer createLexer() { - return new JavaLexer(LanguageLevel.HIGHEST); + return JavaParserDefinition.createLexer(LanguageLevel.HIGHEST); } @Override diff --git a/java/java-tests/testSrc/com/intellij/lang/java/parser/JavadocParsingTest.java b/java/java-tests/testSrc/com/intellij/lang/java/parser/JavadocParsingTest.java index 2d0432b198f9..95cdc1586ba5 100644 --- a/java/java-tests/testSrc/com/intellij/lang/java/parser/JavadocParsingTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/java/parser/JavadocParsingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -81,5 +81,5 @@ public class JavadocParsingTest extends JavaParsingTestCase { public void testTypeParam() { doTest(true); } public void testParameterlessTag() { doTest(true); } - public void testIDEADEV_41403() {doTest(true);} + public void testIDEADEV_41403() { doTest(true); } } diff --git a/java/java-tests/testSrc/com/intellij/lang/psi/PsiBuilderTest.java b/java/java-tests/testSrc/com/intellij/lang/psi/PsiBuilderTest.java index 5dc954bf59ee..a0823caaec34 100644 --- a/java/java-tests/testSrc/com/intellij/lang/psi/PsiBuilderTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/psi/PsiBuilderTest.java @@ -1,8 +1,23 @@ +/* + * 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.lang.psi; import com.intellij.lang.*; import com.intellij.lang.impl.PsiBuilderImpl; -import com.intellij.lexer.JavaLexer; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.JavaTokenType; @@ -17,7 +32,7 @@ import com.intellij.testFramework.LightIdeaTestCase; import junit.framework.AssertionFailedError; /** - * Date: Jan 21, 2005 + * @since Jan 21, 2005 * @author max */ public class PsiBuilderTest extends LightIdeaTestCase { @@ -66,7 +81,7 @@ public class PsiBuilderTest extends LightIdeaTestCase { final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang); assertNotNull(parserDefinition); PsiFile psiFile = createFile("x.java", text); - return new PsiBuilderImpl(getProject(), psiFile, parserDefinition, new JavaLexer(LanguageLevel.JDK_1_5), + return new PsiBuilderImpl(getProject(), psiFile, parserDefinition, JavaParserDefinition.createLexer(LanguageLevel.JDK_1_5), SharedImplUtil.findCharTableByTree(psiFile.getNode()), text, originalTree, null); } @@ -152,8 +167,8 @@ public class PsiBuilderTest extends LightIdeaTestCase { public void testAssertionFailureOnUnbalancedMarkers() { myBuilder = createBuilder("foo"); myBuilder.setDebugMode(true); - final PsiBuilder.Marker m = myBuilder.mark(); - final PsiBuilder.Marker m1 = myBuilder.mark(); + PsiBuilder.Marker m = myBuilder.mark(); + @SuppressWarnings("UnusedDeclaration") PsiBuilder.Marker m1 = myBuilder.mark(); myBuilder.getTokenType(); myBuilder.advanceLexer(); try { @@ -227,6 +242,4 @@ public class PsiBuilderTest extends LightIdeaTestCase { myBuilder.advanceLexer(); root.done(JavaStubElementTypes.ENUM_CONSTANT_INITIALIZER); } - - } diff --git a/java/java-tests/testSrc/com/intellij/lexer/LayeredLexerTest.java b/java/java-tests/testSrc/com/intellij/lexer/LayeredLexerTest.java index 21bc0650d6e0..b1026fdc7ca8 100644 --- a/java/java-tests/testSrc/com/intellij/lexer/LayeredLexerTest.java +++ b/java/java-tests/testSrc/com/intellij/lexer/LayeredLexerTest.java @@ -1,5 +1,21 @@ +/* + * 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.lexer; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.JavaTokenType; import com.intellij.psi.tree.IElementType; @@ -91,17 +107,16 @@ public class LayeredLexerTest extends TestCase { assertEquals(null, lexer.getTokenType()); } - private Lexer setupLexer(String text) { - LayeredLexer lexer = new LayeredLexer(new JavaLexer(LanguageLevel.JDK_1_3)); + private static Lexer setupLexer(String text) { + LayeredLexer lexer = new LayeredLexer(JavaParserDefinition.createLexer(LanguageLevel.JDK_1_3)); lexer.registerSelfStoppingLayer(new StringLiteralLexer('\"', JavaTokenType.STRING_LITERAL), new IElementType[]{JavaTokenType.STRING_LITERAL}, IElementType.EMPTY_ARRAY); - lexer.start(text); return lexer; } - private String nextToken(Lexer lexer) { + private static String nextToken(Lexer lexer) { assertTrue(lexer.getTokenType() != null); final String s = lexer.getBufferSequence().subSequence(lexer.getTokenStart(), lexer.getTokenEnd()).toString(); lexer.advance(); diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/InnerClassesScannerTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/InnerClassesScannerTest.java index 5b7295dfa14d..159d7c7bc9a7 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/InnerClassesScannerTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/cache/impl/InnerClassesScannerTest.java @@ -1,5 +1,21 @@ +/* + * 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.psi.impl.cache.impl; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.TextRange; @@ -56,8 +72,7 @@ public class InnerClassesScannerTest extends PsiTestCase { boolean mayHaveClassesInside = false; if (psiFile instanceof PsiJavaFileImpl) { - PsiJavaFileImpl impl = (PsiJavaFileImpl)psiFile; - Lexer originalLexer = impl.createLexer(); + Lexer originalLexer = JavaParserDefinition.createLexer(((PsiJavaFileImpl)psiFile).getLanguageLevel()); FilterLexer lexer = new FilterLexer(originalLexer, new FilterLexer.SetFilter(StdTokenSets.WHITE_SPACE_OR_COMMENT_BIT_SET)); final TextRange range = psiElement.getTextRange(); lexer.start(fileBuffer, range.getStartOffset(), range.getEndOffset()); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MoveMembersTest.java b/java/java-tests/testSrc/com/intellij/refactoring/MoveMembersTest.java index 2ceceea6c264..596944b839d3 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MoveMembersTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MoveMembersTest.java @@ -124,6 +124,16 @@ public class MoveMembersTest extends MultiFileTestCase { assertEquals("Field <b><code>B.ONE</code></b> has write access but is moved to an interface", e.getMessage()); } } + + public void testFinalFieldWithInitializer() throws Exception { + try { + doTest("B", "A", 0); + fail("conflict expected"); + } + catch (BaseRefactoringProcessor.ConflictsInTestsException e) { + assertEquals("final variable initializer won't be available after move.", e.getMessage()); + } + } public void testInnerToInterface() throws Exception { doTest("A", "B", 0); diff --git a/java/jsp-base-openapi/src/com/intellij/openapi/editor/JspHighlighterColors.java b/java/jsp-base-openapi/src/com/intellij/openapi/editor/JspHighlighterColors.java index b5116f45dbea..cde841abe11d 100644 --- a/java/jsp-base-openapi/src/com/intellij/openapi/editor/JspHighlighterColors.java +++ b/java/jsp-base-openapi/src/com/intellij/openapi/editor/JspHighlighterColors.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. @@ -21,13 +21,19 @@ import com.intellij.openapi.editor.colors.TextAttributesKey; * @author yole */ public class JspHighlighterColors { - private JspHighlighterColors() { - } + private JspHighlighterColors() { } - public static final TextAttributesKey JSP_SCRIPTING_BACKGROUND = TextAttributesKey.createTextAttributesKey("JSP_SCRIPTING_BACKGROUND", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR); - public static final TextAttributesKey JSP_ACTION_AND_DIRECTIVE_BACKGROUND = TextAttributesKey.createTextAttributesKey("JSP_DIRECTIVE_BACKGROUND", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR); - public static final TextAttributesKey JSP_ACTION_AND_DIRECTIVE_NAME = TextAttributesKey.createTextAttributesKey("JSP_DIRECTIVE_NAME", DefaultLanguageHighlighterColors.KEYWORD); - public static final TextAttributesKey JSP_ATTRIBUTE_NAME = TextAttributesKey.createTextAttributesKey("JSP_ATTRIBUTE_NAME", DefaultLanguageHighlighterColors.MARKUP_ATTRIBUTE); - public static final TextAttributesKey JSP_ATTRIBUTE_VALUE = TextAttributesKey.createTextAttributesKey("JSP_ATTRIBUTE_VALUE", DefaultLanguageHighlighterColors.STRING); - public static final TextAttributesKey JSP_COMMENT = TextAttributesKey.createTextAttributesKey("JSP_COMMENT", DefaultLanguageHighlighterColors.BLOCK_COMMENT); + public static final TextAttributesKey JSP_SCRIPTING_BACKGROUND = + TextAttributesKey.createTextAttributesKey("JSP_SCRIPTING_BACKGROUND", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR); + public static final TextAttributesKey JSP_ACTION_AND_DIRECTIVE_BACKGROUND = + TextAttributesKey.createTextAttributesKey("JSP_DIRECTIVE_BACKGROUND", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR); + public static final TextAttributesKey JSP_ACTION_AND_DIRECTIVE_NAME = + TextAttributesKey.createTextAttributesKey("JSP_DIRECTIVE_NAME", DefaultLanguageHighlighterColors.KEYWORD); + public static final TextAttributesKey JSP_ATTRIBUTE_NAME = + TextAttributesKey.createTextAttributesKey("JSP_ATTRIBUTE_NAME", DefaultLanguageHighlighterColors.MARKUP_ATTRIBUTE); + public static final TextAttributesKey JSP_ATTRIBUTE_VALUE = + TextAttributesKey.createTextAttributesKey("JSP_ATTRIBUTE_VALUE", DefaultLanguageHighlighterColors.STRING); + public static final TextAttributesKey JSP_COMMENT = + TextAttributesKey.createTextAttributesKey("JSP_COMMENT", DefaultLanguageHighlighterColors.BLOCK_COMMENT); + public static final TextAttributesKey JSP_DIRECTIVE_STAT_END_MARKER = DefaultLanguageHighlighterColors.KEYWORD; } diff --git a/java/openapi/src/com/intellij/codeInspection/GlobalJavaInspectionTool.java b/java/openapi/src/com/intellij/codeInspection/GlobalJavaInspectionTool.java index cb19ce9d9b2b..c01422b59d0e 100644 --- a/java/openapi/src/com/intellij/codeInspection/GlobalJavaInspectionTool.java +++ b/java/openapi/src/com/intellij/codeInspection/GlobalJavaInspectionTool.java @@ -28,13 +28,13 @@ import org.jetbrains.annotations.Nullable; public abstract class GlobalJavaInspectionTool extends GlobalInspectionTool implements CustomSuppressableInspectionTool { @Override - public boolean queryExternalUsagesRequests(final InspectionManager manager, - final GlobalInspectionContext globalContext, - final ProblemDescriptionsProcessor problemDescriptionsProcessor) { + public boolean queryExternalUsagesRequests(@NotNull final InspectionManager manager, + @NotNull final GlobalInspectionContext globalContext, + @NotNull final ProblemDescriptionsProcessor problemDescriptionsProcessor) { return queryExternalUsagesRequests(globalContext.getRefManager(), globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT), problemDescriptionsProcessor); } - protected boolean queryExternalUsagesRequests(RefManager manager, GlobalJavaInspectionContext globalContext, ProblemDescriptionsProcessor processor) { + protected boolean queryExternalUsagesRequests(@NotNull RefManager manager, @NotNull GlobalJavaInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor processor) { return false; } diff --git a/java/openapi/src/com/intellij/codeInspection/reference/RefJavaManager.java b/java/openapi/src/com/intellij/codeInspection/reference/RefJavaManager.java index b217cef43f7f..edd0ab945e98 100644 --- a/java/openapi/src/com/intellij/codeInspection/reference/RefJavaManager.java +++ b/java/openapi/src/com/intellij/codeInspection/reference/RefJavaManager.java @@ -29,6 +29,7 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiParameter; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; public abstract class RefJavaManager implements RefManagerExtension<RefJavaManager> { @NonNls public static final String CLASS = "class"; @@ -70,11 +71,13 @@ public abstract class RefJavaManager implements RefManagerExtension<RefJavaManag public abstract EntryPointsManager getEntryPointsManager(); + @NotNull @Override public Language getLanguage() { return StdLanguages.JAVA; } + @NotNull @Override public Key<RefJavaManager> getID() { return MANAGER; diff --git a/java/openapi/src/com/intellij/codeInspection/reference/RefPackage.java b/java/openapi/src/com/intellij/codeInspection/reference/RefPackage.java index 699e57ce61be..3aee63a4421d 100644 --- a/java/openapi/src/com/intellij/codeInspection/reference/RefPackage.java +++ b/java/openapi/src/com/intellij/codeInspection/reference/RefPackage.java @@ -15,6 +15,8 @@ */ package com.intellij.codeInspection.reference; +import org.jetbrains.annotations.NotNull; + /** * A node in the reference graph corresponding to a Java package. * @@ -28,6 +30,7 @@ public interface RefPackage extends RefEntity { * * @return the full-qualified name for the package. */ + @NotNull @Override String getQualifiedName(); } |