Skip to content

Commit

Permalink
LSP: Various stability issues with more complex project fixed. (#2824)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbalek authored Mar 24, 2021
1 parent d0a9324 commit c084119
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

# yes/no/ask
ASK_OnReload=yes
15 changes: 15 additions & 0 deletions java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBAttr.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.netbeans.lib.nbjavac.services;

import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.comp.Attr;
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Env;
Expand Down Expand Up @@ -104,6 +105,20 @@ protected void breakTreeFound(Env<AttrContext> env) {
}
}

protected void breakTreeFound(Env<AttrContext> env, Type result) {
if (fullyAttribute) {
fullyAttributeResult = env;
} else {
try {
MethodHandles.lookup()
.findSpecial(Attr.class, "breakTreeFound", MethodType.methodType(void.class, Env.class, Type.class), NBAttr.class)
.invokeExact(this, env, result);
} catch (Throwable ex) {
sneakyThrows(ex);
}
}
}

private <T extends Throwable> void sneakyThrows(Throwable t) throws T {
throw (T) t;
}
Expand Down
15 changes: 15 additions & 0 deletions platform/openide.text/apichanges.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
<apidef name="text">Text API</apidef>
</apidefs>
<changes>
<change id="ask.on.document.reload">
<api name="text"/>
<summary>Rebrand defaults for Reload Editor Dialog</summary>
<version major="6" minor="80"/>
<date day="22" month="1" year="2021"/>
<author login="dbalek"/>
<compatibility addition="yes" binary="compatible" source="compatible"
semantic="incompatible" deletion="no"
modification="no"/>
<description>
A branding API to disable showing reload externally modified document dialog
- <a href="architecture-summary.html#group-branding">ASK_OnReload</a>.
</description>
<class package="org.openide.text" name="CloneableEditorSupport"/>
</change>
<change id="PositionRef.Position">
<api name="text"/>
<summary>Implement Position interface for compatibility</summary>
Expand Down
7 changes: 7 additions & 0 deletions platform/openide.text/arch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,13 @@ in methods
<code>-J-Dorg.openide.text.CloneableEditor.oldInitialization=true</code>.
This property may be discontiued anytime.
</api>
<api name="org.netbeans.modules.openide.text.ASK_OnReload" group="branding" type="export" category="stable">
Control on reload yes/no dialog in
<a href="@TOP@/org/openide/text/CloneableEditorSupport.html">CloneableEditorSupport</a>
by setting the <code>ASK_OnReload</code> key in
<code>org/netbeans/modules/openide/text/Bundle.properties</code>
to <code>yes</code> or <code>no</code> in a branding file in your application.
</api>
</answer>


Expand Down
2 changes: 1 addition & 1 deletion platform/openide.text/manifest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Manifest-Version: 1.0
OpenIDE-Module: org.openide.text
OpenIDE-Module-Localizing-Bundle: org/openide/text/Bundle.properties
AutoUpdate-Essential-Module: true
OpenIDE-Module-Specification-Version: 6.79
OpenIDE-Module-Specification-Version: 6.80

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.netbeans.modules.openide.text;

import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;

public final class AskEditorQuestions {
private AskEditorQuestions() {
}

public static boolean askReloadDocument(String localizedMessage) {
String ask = NbBundle.getMessage(AskEditorQuestions.class, "ASK_OnReload"); // NOI18N
if ("yes".equals(ask)) { // NOI18N
return true;
}
if ("no".equals(ask)) { // NOI18N
return false;
}
NotifyDescriptor nd = new NotifyDescriptor.Confirmation(localizedMessage, NotifyDescriptor.YES_NO_OPTION);
Object res = DialogDisplayer.getDefault().notify(nd);
if (NotifyDescriptor.OK_OPTION.equals(res)) {
return true;
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

# yes/no/ask
ASK_OnReload=ask
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ FMT_External_change=File {0} was modified externally. Reload it?
FMT_External_change_write=File {0} was modified externally. Overwrite it?



# format to create default display name for a line
# {0} name of the editor support
# {1} line number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import javax.swing.undo.UndoableEdit;
import org.netbeans.api.editor.mimelookup.MimeLookup;
import org.netbeans.api.editor.mimelookup.MimePath;
import org.netbeans.modules.openide.text.AskEditorQuestions;
import org.openide.util.Exceptions;
import org.openide.util.Mutex;
import org.openide.util.Parameters;
Expand Down Expand Up @@ -1710,14 +1711,10 @@ private void checkReload(JEditorPane[] openedPanes, boolean doReload) {
d.getProperty(javax.swing.text.Document.TitleProperty)
);

NotifyDescriptor nd = new NotifyDescriptor.Confirmation(msg, NotifyDescriptor.YES_NO_OPTION);

reloadDialogOpened = true;

try {
Object ret = DialogDisplayer.getDefault().notify(nd);

if (NotifyDescriptor.YES_OPTION.equals(ret)) {
if (AskEditorQuestions.askReloadDocument(msg)) {
doReload = true;
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.netbeans.modules.openide.text;

import java.awt.Dialog;
import java.util.Locale;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import org.netbeans.junit.MockServices;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;

public class AskEditorQuestionsTest {
public AskEditorQuestionsTest() {
}

@Before
public void setUp() {
Locale.setDefault(Locale.ENGLISH);
MockServices.setServices(MockDialogDisplayer.class);
}

@Test
public void testAskReloadDocument() {
try {
boolean result = AskEditorQuestions.askReloadDocument("any.txt");
fail("Expecting dialog not a result: " + result);
} catch (DisplayerException ex) {
assertTrue(ex.descriptor.getMessage().toString().contains("any.txt"));
}
}

@Test
public void testYesReloadDocument() {
Locale.setDefault(new Locale("DA"));
boolean result = AskEditorQuestions.askReloadDocument("any.txt");
assertTrue("Default answer is yes", result);
}

@Test
public void testNoReloadDocument() {
Locale.setDefault(new Locale("NO"));
boolean result = AskEditorQuestions.askReloadDocument("any.txt");
assertFalse("Default answer is no", result);
}

private static final class DisplayerException extends RuntimeException {
final NotifyDescriptor descriptor;

public DisplayerException(NotifyDescriptor descriptor) {
this.descriptor = descriptor;
}
}

public final static class MockDialogDisplayer extends DialogDisplayer {
public MockDialogDisplayer() {
}

@Override
public Object notify(NotifyDescriptor nd) {
throw new DisplayerException(nd);
}

@Override
public Dialog createDialog(DialogDescriptor dd) {
throw new DisplayerException(dd);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

ASK_OnReload=yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

ASK_OnReload=no

0 comments on commit c084119

Please sign in to comment.