diff --git a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java index d6ea650d6c6b..d5fc224f7464 100644 --- a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java +++ b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java @@ -49,6 +49,8 @@ public class AsmCodeGenerator { private String myClassToBind; private byte[] myPatchedData; + private Method myGetFontMethod; + private static final Map myContainerLayoutCodeGenerators = new HashMap(); private static final Map myComponentLayoutCodeGenerators = new HashMap(); private static final Map myPropertyCodeGenerators = new LinkedHashMap(); // need LinkedHashMap for deterministic iteration @@ -228,7 +230,7 @@ public class AsmCodeGenerator { return Type.getType("L" + className.replace('.', '/') + ";"); } - class FormClassVisitor extends ClassVisitor { + class FormClassVisitor extends ClassVisitor implements GetFontMethodProvider { private String myClassName; private String mySuperName; private final Map myFieldDescMap = new HashMap(); @@ -312,6 +314,11 @@ public class AsmCodeGenerator { buildGetRootComponenMethod(); } + if (myGetFontMethod != null) { + FontPropertyCodeGenerator + .buildGetFontMethod(new GeneratorAdapter(Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC, myGetFontMethod, null, null, cv)); + } + for (Iterator iterator = myPropertyCodeGenerators.values().iterator(); iterator.hasNext();) { PropertyCodeGenerator propertyCodeGenerator = (PropertyCodeGenerator)iterator.next(); propertyCodeGenerator.generateClassEnd(this); @@ -553,7 +560,8 @@ public class AsmCodeGenerator { final PropertyCodeGenerator propGen = (PropertyCodeGenerator) myPropertyCodeGenerators.get(propertyClass); try { - if (propGen != null && propGen.generateCustomSetValue(lwComponent, componentClass, property, generator, componentLocal, myClassName)) { + if (propGen != null && + propGen.generateCustomSetValue(lwComponent, componentClass, property, generator, this, componentLocal, myClassName)) { continue; } } @@ -772,7 +780,16 @@ public class AsmCodeGenerator { } } - private Type getMainClassType() { + @Override + public Method getFontMethod() { + if (myGetFontMethod == null) { + myGetFontMethod = FontPropertyCodeGenerator.createGetFontMethod(); + } + return myGetFontMethod; + } + + @Override + public Type getMainClassType() { return Type.getType("L" + myClassName + ";"); } @@ -879,7 +896,7 @@ public class AsmCodeGenerator { generator.push((String) null); } else { - FontPropertyCodeGenerator.generatePushFont(generator, componentLocal, container, font, "getFont", null); + FontPropertyCodeGenerator.generatePushFont(generator, this, componentLocal, container, font, "getFont", null); } if (container.getBorderTitleColor() == null) { generator.push((String) null); diff --git a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/FontPropertyCodeGenerator.java b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/FontPropertyCodeGenerator.java index 100704ca9a74..909288010cca 100644 --- a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/FontPropertyCodeGenerator.java +++ b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/FontPropertyCodeGenerator.java @@ -19,8 +19,8 @@ import com.intellij.compiler.instrumentation.InstrumentationClassFinder; import com.intellij.uiDesigner.lw.FontDescriptor; import com.intellij.uiDesigner.lw.LwComponent; import com.intellij.uiDesigner.lw.LwIntrospectedProperty; -import org.jetbrains.org.objectweb.asm.*; import org.jetbrains.org.objectweb.asm.Label; +import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.org.objectweb.asm.commons.GeneratorAdapter; import org.jetbrains.org.objectweb.asm.commons.Method; @@ -37,93 +37,157 @@ public class FontPropertyCodeGenerator extends PropertyCodeGenerator { private static final Type ourStringType = Type.getType(String.class); private static final Method ourInitMethod = Method.getMethod("void (java.lang.String,int,int)"); - private static final Method ourUIManagerGetFontMethod = new Method("getFont", ourFontType, new Type[] { ourObjectType } ); - private static final Method ourGetNameMethod = new Method("getName", ourStringType, new Type[0] ); - private static final Method ourGetSizeMethod = new Method("getSize", Type.INT_TYPE, new Type[0] ); - private static final Method ourGetStyleMethod = new Method("getStyle", Type.INT_TYPE, new Type[0] ); + private static final Method ourUIManagerGetFontMethod = new Method("getFont", ourFontType, new Type[]{ourObjectType}); + private static final Method ourGetNameMethod = new Method("getName", ourStringType, new Type[0]); + private static final Method ourGetSizeMethod = new Method("getSize", Type.INT_TYPE, new Type[0]); + private static final Method ourGetStyleMethod = new Method("getStyle", Type.INT_TYPE, new Type[0]); + private static final Method ourCanDisplay = new Method("canDisplay", Type.BOOLEAN_TYPE, new Type[]{Type.CHAR_TYPE}); public boolean generateCustomSetValue(final LwComponent lwComponent, final InstrumentationClassFinder.PseudoClass componentClass, final LwIntrospectedProperty property, final GeneratorAdapter generator, + GetFontMethodProvider fontMethodProvider, final int componentLocal, final String formClassName) { - FontDescriptor descriptor = (FontDescriptor) property.getPropertyValue(lwComponent); - if (descriptor.isFixedFont() && !descriptor.isFullyDefinedFont()) { - Label fontNullLabel = generator.newLabel(); - generatePushFont(generator, componentLocal, lwComponent, descriptor, property.getReadMethodName(), fontNullLabel); + FontDescriptor descriptor = (FontDescriptor)property.getPropertyValue(lwComponent); + Label fontNullLabel = generator.newLabel(); + generatePushFont(generator, fontMethodProvider, componentLocal, lwComponent, descriptor, property.getReadMethodName(), fontNullLabel); - Method setFontMethod = new Method(property.getWriteMethodName(), Type.VOID_TYPE, new Type[] { ourFontType } ); - Type componentType = AsmCodeGenerator.typeFromClassName(lwComponent.getComponentClassName()); - generator.invokeVirtual(componentType, setFontMethod); - generator.mark(fontNullLabel); - - return true; - } - return false; - } - - public static void generatePushFont(final GeneratorAdapter generator, final int componentLocal, final LwComponent lwComponent, - final FontDescriptor descriptor, final String readMethodName, - Label fontNullLabel) { - final int fontLocal = generator.newLocal(ourFontType); - - generator.loadLocal(componentLocal); + Method setFontMethod = new Method(property.getWriteMethodName(), Type.VOID_TYPE, new Type[]{ourFontType}); Type componentType = AsmCodeGenerator.typeFromClassName(lwComponent.getComponentClassName()); - Method getFontMethod = new Method(readMethodName, ourFontType, new Type[0] ); - generator.invokeVirtual(componentType, getFontMethod); - generator.storeLocal(fontLocal); + generator.invokeVirtual(componentType, setFontMethod); + generator.mark(fontNullLabel); - if (fontNullLabel != null) { - generator.loadLocal(fontLocal); - generator.ifNull(fontNullLabel); - generator.loadLocal(componentLocal); - } - - generator.newInstance(ourFontType); - generator.dup(); - if (descriptor.getFontName() != null) { - generator.push(descriptor.getFontName()); - } - else { - generator.loadLocal(fontLocal); - generator.invokeVirtual(ourFontType, ourGetNameMethod); - } - - if (descriptor.getFontStyle() >= 0) { - generator.push(descriptor.getFontStyle()); - } - else { - generator.loadLocal(fontLocal); - generator.invokeVirtual(ourFontType, ourGetStyleMethod); - } - - if (descriptor.getFontSize() >= 0) { - generator.push(descriptor.getFontSize()); - } - else { - generator.loadLocal(fontLocal); - generator.invokeVirtual(ourFontType, ourGetSizeMethod); - } - generator.invokeConstructor(ourFontType, ourInitMethod); + return true; } - public void generatePushValue(final GeneratorAdapter generator, final Object value) { - FontDescriptor descriptor = (FontDescriptor) value; + public static void generatePushFont(GeneratorAdapter generator, + GetFontMethodProvider fontMethodProvider, + int componentLocal, + LwComponent lwComponent, + FontDescriptor descriptor, + String readMethodName, + Label fontNullLabel) { if (descriptor.isFixedFont()) { - if (!descriptor.isFullyDefinedFont()) throw new IllegalStateException("Unexpected font state"); - generator.newInstance(ourFontType); - generator.dup(); + generator.loadThis(); + generator.push(descriptor.getFontName()); generator.push(descriptor.getFontStyle()); generator.push(descriptor.getFontSize()); - generator.invokeConstructor(ourFontType, ourInitMethod); + + generator.loadLocal(componentLocal); + Type componentType = AsmCodeGenerator.typeFromClassName(lwComponent.getComponentClassName()); + Method getFontMethod = new Method(readMethodName, ourFontType, new Type[0]); + generator.invokeVirtual(componentType, getFontMethod); + + generator.invokeVirtual(fontMethodProvider.getMainClassType(), fontMethodProvider.getFontMethod()); } - else if (descriptor.getSwingFont() != null) { + else { generator.push(descriptor.getSwingFont()); generator.invokeStatic(ourUIManagerType, ourUIManagerGetFontMethod); } - else { - throw new IllegalStateException("Unknown font type"); + + if (fontNullLabel != null) { + int fontResult = generator.newLocal(ourFontType); + generator.storeLocal(fontResult); + generator.loadLocal(fontResult); + generator.ifNull(fontNullLabel); + generator.loadLocal(componentLocal); + generator.loadLocal(fontResult); } } -} + + public void generatePushValue(final GeneratorAdapter generator, final Object value) { + throw new IllegalStateException("Unknown font type"); + } + + public static Method createGetFontMethod() { + return new Method("getFont" + System.currentTimeMillis(), ourFontType, + new Type[]{ourStringType, Type.INT_TYPE, Type.INT_TYPE, ourFontType}); + } + + // Source code for this bytecode in com/intellij/uiDesigner/make/FormSourceCodeGenerator.java:299 + public static void buildGetFontMethod(GeneratorAdapter generator) { + Label fontNonNull = new Label(); + generator.loadArg(3); // font + generator.ifNonNull(fontNonNull); + generator.push((String)null); + generator.returnValue(); + + generator.mark(fontNonNull); + Label nameNonNull = new Label(); + generator.loadArg(0); // name + generator.ifNonNull(nameNonNull); + + generator.loadArg(3); // font + generator.invokeVirtual(ourFontType, ourGetNameMethod); + int nameLocal = generator.newLocal(ourStringType); + generator.storeLocal(nameLocal); + + Label createFont = new Label(); + generator.goTo(createFont); + generator.mark(nameNonNull); + + generator.newInstance(ourFontType); + generator.dup(); + generator.loadArg(0); // name + generator.push(Font.PLAIN); + generator.push(10); + generator.invokeConstructor(ourFontType, ourInitMethod); + + int testFont = generator.newLocal(ourFontType); + generator.storeLocal(testFont); + + Label fontGetNameLabel = new Label(); + generator.loadLocal(testFont); + generator.push('a'); + generator.invokeVirtual(ourFontType, ourCanDisplay); + generator.ifZCmp(GeneratorAdapter.EQ, fontGetNameLabel); + generator.loadLocal(testFont); + generator.push('1'); + generator.invokeVirtual(ourFontType, ourCanDisplay); + generator.ifZCmp(GeneratorAdapter.EQ, fontGetNameLabel); + + generator.loadArg(0); // name + generator.storeLocal(nameLocal); + generator.goTo(createFont); + generator.mark(fontGetNameLabel); + + generator.loadArg(3); // font + generator.invokeVirtual(ourFontType, ourGetNameMethod); + generator.storeLocal(nameLocal); + generator.mark(createFont); + + generator.newInstance(ourFontType); + generator.dup(); + + generator.loadLocal(nameLocal); + + Label checkStyle1 = new Label(); + Label checkStyle2 = new Label(); + generator.loadArg(1); // style + generator.ifZCmp(GeneratorAdapter.LT, checkStyle1); + generator.loadArg(1); // style + generator.goTo(checkStyle2); + generator.mark(checkStyle1); + generator.loadArg(3); // font + generator.invokeVirtual(ourFontType, ourGetStyleMethod); + generator.mark(checkStyle2); + + Label checkSize1 = new Label(); + Label checkSize2 = new Label(); + generator.loadArg(2); // size + generator.ifZCmp(GeneratorAdapter.LT, checkSize1); + generator.loadArg(2); // size + generator.goTo(checkSize2); + generator.mark(checkSize1); + generator.loadArg(3); // font + generator.invokeVirtual(ourFontType, ourGetSizeMethod); + generator.mark(checkSize2); + + generator.invokeConstructor(ourFontType, ourInitMethod); + generator.returnValue(); + + generator.endMethod(); + } +} \ No newline at end of file diff --git a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/GetFontMethodProvider.java b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/GetFontMethodProvider.java new file mode 100644 index 000000000000..470557c21149 --- /dev/null +++ b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/GetFontMethodProvider.java @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.uiDesigner.compiler; + +import org.jetbrains.org.objectweb.asm.Type; +import org.jetbrains.org.objectweb.asm.commons.Method; + +/** + * @author Alexander Lobas + */ +public interface GetFontMethodProvider { + Method getFontMethod(); + + Type getMainClassType(); +} \ No newline at end of file diff --git a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/PropertyCodeGenerator.java b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/PropertyCodeGenerator.java index 16cb0790f8f6..3af6693d1038 100644 --- a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/PropertyCodeGenerator.java +++ b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/PropertyCodeGenerator.java @@ -31,6 +31,7 @@ public abstract class PropertyCodeGenerator { public boolean generateCustomSetValue(final LwComponent lwComponent, final InstrumentationClassFinder.PseudoClass componentClass, final LwIntrospectedProperty property, final GeneratorAdapter generator, + GetFontMethodProvider fontMethodProvider, final int componentLocal, final String formClassName) throws IOException, ClassNotFoundException { return false; } diff --git a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/StringPropertyCodeGenerator.java b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/StringPropertyCodeGenerator.java index 94dffc379ed0..a1c7bef592ab 100644 --- a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/StringPropertyCodeGenerator.java +++ b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/StringPropertyCodeGenerator.java @@ -67,6 +67,7 @@ public class StringPropertyCodeGenerator extends PropertyCodeGenerator implement final InstrumentationClassFinder.PseudoClass componentClass, final LwIntrospectedProperty property, final GeneratorAdapter generator, + GetFontMethodProvider fontMethodProvider, final int componentLocal, final String formClassName) throws IOException, ClassNotFoundException { final InstrumentationClassFinder.PseudoClass abstractButtonClass = componentClass.getFinder().loadClass(AbstractButton.class.getName()); diff --git a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/lw/FontDescriptor.java b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/lw/FontDescriptor.java index 46c2cf98eb62..85b611996fe0 100644 --- a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/lw/FontDescriptor.java +++ b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/lw/FontDescriptor.java @@ -66,9 +66,23 @@ public class FontDescriptor { if (myFontName == null && defaultFont == null) { return null; } - return new Font(myFontName != null ? myFontName : defaultFont.getFontName(), - myFontStyle >= 0 ? myFontStyle : defaultFont.getStyle(), - myFontSize >= 0 ? myFontSize : defaultFont.getSize()); + String name = myFontName; + if (name == null || name.length() == 0) { + if (defaultFont == null) { + return null; + } + name = defaultFont.getName(); + } + else { + if (!isValidFontName()) { + if (defaultFont == null) { + return null; + } + name = defaultFont.getName(); + } + } + + return new Font(name, myFontStyle >= 0 ? myFontStyle : defaultFont.getStyle(), myFontSize >= 0 ? myFontSize : defaultFont.getSize()); } public String getSwingFont() { @@ -77,11 +91,24 @@ public class FontDescriptor { public Font getResolvedFont(Font defaultFont) { if (mySwingFont != null) { - return UIManager.getFont(mySwingFont); + Font result = UIManager.getFont(mySwingFont); + return result == null ? defaultFont : result; } return getFont(defaultFont); } + private boolean isValidFontName() { + Font font = new Font(myFontName, Font.PLAIN, 10); + return font.canDisplay('a') && font.canDisplay('1'); + } + + public boolean isValid() { + if (mySwingFont == null) { + return myFontName == null || isValidFontName(); + } + return UIManager.getFont(mySwingFont) != null; + } + public boolean equals(Object obj) { if (obj == null || !(obj instanceof FontDescriptor)) { return false; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java index 6db976eb4446..12caf386a120 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java @@ -179,7 +179,7 @@ public class ExceptionBreakpoint extends Breakpoint !s.isEmpty()).findFirst().ifPresent(System.out::println); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/beforeFindFirstReturn.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/beforeFindFirstReturn.java new file mode 100644 index 000000000000..e6a07635359a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamApiMigration/beforeFindFirstReturn.java @@ -0,0 +1,14 @@ +// "Replace with findFirst()" "true" + +import java.util.Arrays; + +public class TestFile { + public void test() { + for(String s : Arrays.asList("a", "b")) { + if(!s.isEmpty()) { + System.out.println(s); + return; + } + } + } +} \ No newline at end of file diff --git a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt index 1285a68b4df6..628da926130e 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt +++ b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt @@ -54,7 +54,7 @@ class UISettings : BaseState(), PersistentStateComponent { @get:Property(filter = FontFilter::class) @get:OptionTag("FONT_SIZE") - var fontSize by storedProperty(12) + var fontSize by storedProperty((UIUtil.DEF_SYSTEM_FONT_SIZE * UISettings.normalizingScale).toInt()) @get:Property(filter = FontFilter::class) @get:OptionTag("FONT_SCALE") diff --git a/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineDescriptorResolveResult.java b/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineDescriptorResolveResult.java index f4b2e430150c..4ab7779c158f 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineDescriptorResolveResult.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineDescriptorResolveResult.java @@ -31,8 +31,10 @@ import com.intellij.codeInspection.reference.RefEntity; import com.intellij.codeInspection.ui.InspectionToolPresentation; import com.intellij.lang.Language; import com.intellij.openapi.application.ReadAction; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtilCore; @@ -49,6 +51,7 @@ import java.util.Set; * @author Dmitry Batkovich */ class OfflineDescriptorResolveResult { + private static final Logger LOG = Logger.getInstance(OfflineDescriptorResolveResult.class); private RefEntity myResolvedEntity; private CommonProblemDescriptor myResolvedDescriptor; @@ -122,8 +125,15 @@ class OfflineDescriptorResolveResult { PsiFile containingFile = psiElement.getContainingFile(); final ProblemsHolder holder = new ProblemsHolder(inspectionManager, containingFile, false); final LocalInspectionTool localTool = toolWrapper.getTool(); - final int startOffset = psiElement.getTextRange().getStartOffset(); - final int endOffset = psiElement.getTextRange().getEndOffset(); + TextRange textRange = psiElement.getTextRange(); + LOG.assertTrue(textRange != null, + "text range muse be not null here; " + + "isValid = " + psiElement.isValid() + ", " + + "isPhysical = " + psiElement.isPhysical() + ", " + + "containingFile = " + containingFile.getName() + ", " + + "inspection = " + toolWrapper.getShortName()); + final int startOffset = textRange.getStartOffset(); + final int endOffset = textRange.getEndOffset(); LocalInspectionToolSession session = new LocalInspectionToolSession(containingFile, startOffset, endOffset); final PsiElementVisitor visitor = localTool.buildVisitor(holder, false, session); localTool.inspectionStarted(session, false); diff --git a/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java b/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java index e4f64cfda5d9..1844a0adea53 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java +++ b/platform/platform-api/src/com/intellij/openapi/fileEditor/OpenFileDescriptor.java @@ -168,30 +168,30 @@ public class OpenFileDescriptor implements Navigatable, Comparable { - final int offset = getOffset(); - CaretModel caretModel = e.getCaretModel(); - boolean caretMoved = false; - if (myLogicalLine >= 0) { - LogicalPosition pos = new LogicalPosition(myLogicalLine, Math.max(myLogicalColumn, 0)); - if (offset < 0 || offset == e.logicalPositionToOffset(pos)) { - caretModel.removeSecondaryCarets(); - caretModel.moveToLogicalPosition(pos); - caretMoved = true; - } - } - if (!caretMoved && offset >= 0) { + final int offset = getOffset(); + CaretModel caretModel = e.getCaretModel(); + boolean caretMoved = false; + if (myLogicalLine >= 0) { + LogicalPosition pos = new LogicalPosition(myLogicalLine, Math.max(myLogicalColumn, 0)); + if (offset < 0 || offset == e.logicalPositionToOffset(pos)) { caretModel.removeSecondaryCarets(); - caretModel.moveToOffset(Math.min(offset, e.getDocument().getTextLength())); + caretModel.moveToLogicalPosition(pos); caretMoved = true; } + } + if (!caretMoved && offset >= 0) { + caretModel.removeSecondaryCarets(); + caretModel.moveToOffset(Math.min(offset, e.getDocument().getTextLength())); + caretMoved = true; + } - if (caretMoved) { - e.getSelectionModel().removeSelection(); + if (caretMoved) { + e.getSelectionModel().removeSelection(); + FileEditorManager.getInstance(myProject).runWhenLoaded(e, () -> { scrollToCaret(e); unfoldCurrentLine(e); - } - }); + }); + } } protected static void unfoldCurrentLine(@NotNull final Editor editor) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java index 2e21fb5d52a3..7d56593ffc01 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java @@ -605,7 +605,10 @@ public class ControlFlowUtils { return EquivalenceChecker.getCanonicalPsiEquivalence() .expressionsAreEquivalent(returnValue, ((PsiReturnStatement)nextElement).getReturnValue()); } - if(nextElement == null && returnValue == null && cur.getParent() instanceof PsiMethod) { + if(returnValue == null && + cur.getParent() instanceof PsiCodeBlock && + cur.getParent().getParent() instanceof PsiMethod && + nextElement instanceof PsiJavaToken && ((PsiJavaToken)nextElement).getTokenType().equals(JavaTokenType.RBRACE)) { return true; } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/frameworkSupport/GradleGroovyFrameworkSupportProvider.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/frameworkSupport/GradleGroovyFrameworkSupportProvider.java index 64a4bce35e6c..8a1af87f5089 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/frameworkSupport/GradleGroovyFrameworkSupportProvider.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/frameworkSupport/GradleGroovyFrameworkSupportProvider.java @@ -66,6 +66,6 @@ public class GradleGroovyFrameworkSupportProvider extends GradleFrameworkSupport .addPluginDefinition("apply plugin: 'groovy'") .addRepositoriesDefinition("mavenCentral()") .addDependencyNotation("compile 'org.codehaus.groovy:groovy-all:2.3.11'") - .addDependencyNotation("testCompile group: 'junit', name: 'junit', version: '4.11'"); + .addDependencyNotation("testCompile group: 'junit', name: 'junit', version: '4.12'"); } } \ No newline at end of file diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy index 4105d822cf29..85534efefedc 100644 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy @@ -21,6 +21,7 @@ import org.gradle.api.file.FileVisitDetails import org.gradle.api.java.archives.Manifest import org.gradle.api.plugins.WarPlugin import org.gradle.api.tasks.bundling.War +import org.gradle.util.GradleVersion import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable import org.jetbrains.plugins.gradle.model.web.WebConfiguration @@ -38,6 +39,8 @@ class WarModelBuilderImpl implements ModelBuilderService { private static final String WEB_APP_DIR_PROPERTY = "webAppDir" private static final String WEB_APP_DIR_NAME_PROPERTY = "webAppDirName" + private static is4OrBetter = GradleVersion.current().baseVersion >= GradleVersion.version("4.0") + @Override boolean canBuild(String modelName) { @@ -99,9 +102,17 @@ class WarModelBuilderImpl implements ModelBuilderService { Manifest manifest = warTask.manifest if (manifest != null) { - def writer = new StringWriter() - manifest.writeTo(writer) - warModel.manifestContent = writer.toString() + if(is4OrBetter) { + if(manifest instanceof org.gradle.api.java.archives.internal.ManifestInternal) { + ByteArrayOutputStream baos = new ByteArrayOutputStream() + manifest.writeTo(baos) + warModel.manifestContent = baos.toString(manifest.contentCharset) + } + } else { + def writer = new StringWriter() + manifest.writeTo(writer) + warModel.manifestContent = writer.toString() + } } warModels.add(warModel) } diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/ResourceBundlePropertyStructureViewElement.java b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/ResourceBundlePropertyStructureViewElement.java index 0a99fa9c40d3..e1f4cc53d28b 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/ResourceBundlePropertyStructureViewElement.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/ResourceBundlePropertyStructureViewElement.java @@ -58,7 +58,7 @@ public class ResourceBundlePropertyStructureViewElement implements StructureView } public IProperty getProperty() { - return myProperty; + return myProperty.getPsiElement().isValid() ? myProperty : null; } @NotNull diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/make/FormSourceCodeGenerator.java b/plugins/ui-designer/src/com/intellij/uiDesigner/make/FormSourceCodeGenerator.java index a2aab63d8576..274c397248eb 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/make/FormSourceCodeGenerator.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/make/FormSourceCodeGenerator.java @@ -293,6 +293,25 @@ public final class FormSourceCodeGenerator { final String loadLabelTextMethodText = getLoadMethodText(AsmCodeGenerator.LOAD_LABEL_TEXT_METHOD, JLabel.class, module); generateMethodIfRequired(newClass, method, AsmCodeGenerator.LOAD_LABEL_TEXT_METHOD, loadLabelTextMethodText, myNeedLoadLabelText); + + if (myGetFontMethod != null) { + String getFontMethod = + "/** @noinspection ALL */ " + + "private java.awt.Font " + myGetFontMethod + + "(String fontName, int style, int size, java.awt.Font currentFont) {" + + "if (currentFont == null) return null;" + + "String resultName;" + + "if (fontName == null) {resultName = currentFont.getName();}" + + "else {" + + " java.awt.Font testFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 10);" + + " if (testFont.canDisplay('a') && testFont.canDisplay('1')) {resultName = fontName;}" + + " else {resultName = currentFont.getName();}" + + "}" + + "return new java.awt.Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());}"; + + generateMethodIfRequired(newClass, method, myGetFontMethod, getFontMethod, true); + } + newClass = (PsiClass) styler.shortenClassReferences(newClass); newClass = (PsiClass) formatter.reformat(newClass); @@ -617,6 +636,11 @@ public final class FormSourceCodeGenerator { if (!descriptor.isColorSet()) continue; } + if (propertyClass.equals(Font.class.getName())) { + pushFontProperty(variable, (FontDescriptor) value, property.getReadMethodName(), property.getWriteMethodName()); + continue; + } + startMethodCall(variable, property.getWriteMethodName()); if (propertyClass.equals(Dimension.class.getName())) { @@ -658,9 +682,6 @@ public final class FormSourceCodeGenerator { else if (propertyClass.equals(Color.class.getName())) { pushColor((ColorDescriptor) value); } - else if (propertyClass.equals(Font.class.getName())) { - pushFont(variable, (FontDescriptor) value, property.getReadMethodName()); - } else if (propertyClass.equals(Icon.class.getName())) { pushIcon((IconDescriptor) value); } @@ -996,6 +1017,16 @@ public final class FormSourceCodeGenerator { } } + private String myGetFontMethod; + + private void pushFontProperty(String variable, FontDescriptor fontDescriptor, String getterName, String setterName) { + myBuffer.append("java.awt.Font ").append(variable).append("Font = "); + pushFont(variable, fontDescriptor, getterName); + + myBuffer.append("if (").append(variable).append("Font != null) ").append(variable).append(".").append(setterName).append("(") + .append(variable).append("Font);\n"); + } + private void pushFont(final String variable, final FontDescriptor fontDescriptor, @NonNls final String getterName) { if (fontDescriptor.getSwingFont() != null) { startStaticMethodCall(UIManager.class, "getFont"); @@ -1003,25 +1034,15 @@ public final class FormSourceCodeGenerator { endMethod(); } else { - startConstructor(Font.class.getName()); - if (fontDescriptor.getFontName() != null) { - push(fontDescriptor.getFontName()); - } - else { - pushVar(variable + "." + getterName + "().getName()"); - } - if (fontDescriptor.getFontStyle() >= 0) { - push(fontDescriptor.getFontStyle(), ourFontStyleMap); - } - else { - pushVar(variable + "." + getterName + "().getStyle()"); - } - if (fontDescriptor.getFontSize() >= 0) { - push(fontDescriptor.getFontSize()); - } - else { - pushVar(variable + "." + getterName + "().getSize()"); + if (myGetFontMethod == null) { + myGetFontMethod = "getFont" + System.currentTimeMillis(); } + + startMethodCall("this", myGetFontMethod); + push(fontDescriptor.getFontName()); + push(fontDescriptor.getFontStyle(), ourFontStyleMap); + push(fontDescriptor.getFontSize()); + pushVar(variable + "." + getterName + "()"); endMethod(); } } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/renderers/FontRenderer.java b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/renderers/FontRenderer.java index 37a923bb3b77..d1abb0d505f6 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/renderers/FontRenderer.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/renderers/FontRenderer.java @@ -16,14 +16,17 @@ package com.intellij.uiDesigner.propertyInspector.renderers; +import com.intellij.ui.JBColor; import com.intellij.uiDesigner.lw.FontDescriptor; import com.intellij.uiDesigner.propertyInspector.properties.IntroFontProperty; +import org.jetbrains.annotations.NotNull; /** * @author yole */ public class FontRenderer extends LabelPropertyRenderer { - protected void customize(FontDescriptor value) { + protected void customize(@NotNull FontDescriptor value) { setText(IntroFontProperty.descriptorToString(value)); + setForeground(value.isValid() ? null : JBColor.red); } } diff --git a/python/educational-core/src/com/jetbrains/edu/learning/EduPluginConfigurator.java b/python/educational-core/src/com/jetbrains/edu/learning/EduPluginConfigurator.java index d29ff113de48..e614afc242a0 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/EduPluginConfigurator.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/EduPluginConfigurator.java @@ -139,7 +139,9 @@ public interface EduPluginConfigurator { return Collections.emptyList(); } - EduCourseProjectGenerator getEduCourseProjectGenerator(); + default EduCourseProjectGenerator getEduCourseProjectGenerator() { + return null; + } default ModuleType getModuleType() {return StdModuleTypes.JAVA;} } diff --git a/python/educational-core/testData/migration/adaptive45.after.xml b/python/educational-core/testData/migration/adaptive45.after.xml index cdb97a37db83..0355503300c2 100644 --- a/python/educational-core/testData/migration/adaptive45.after.xml +++ b/python/educational-core/testData/migration/adaptive45.after.xml @@ -1,7 +1,7 @@ diff --git a/python/educational-core/testData/migration/theory35To4.after.xml b/python/educational-core/testData/migration/theory35To4.after.xml index 07edf716d6b2..2ff33d1dcf62 100644 --- a/python/educational-core/testData/migration/theory35To4.after.xml +++ b/python/educational-core/testData/migration/theory35To4.after.xml @@ -30,7 +30,7 @@ diff --git a/python/educational-core/testData/migration/theory35To4.xml b/python/educational-core/testData/migration/theory35To4.xml index 408fd6301eef..08e98366e4aa 100644 --- a/python/educational-core/testData/migration/theory35To4.xml +++ b/python/educational-core/testData/migration/theory35To4.xml @@ -39,7 +39,7 @@