Skip to content

Commit b8dca25

Browse files
committed
Some warning fixes
1 parent 03ccaab commit b8dca25

File tree

4 files changed

+76
-90
lines changed

4 files changed

+76
-90
lines changed

org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestAngular.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static void enableLogging() {
111111
}
112112

113113
@Test
114-
public void testAngularTs() throws Exception {
114+
void testAngularTs() throws Exception {
115115
IFile appComponentFile = appFolder.getFile("app.component.ts");
116116
TextEditor editor = (TextEditor) IDE
117117
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile);
@@ -137,7 +137,7 @@ protected boolean condition() {
137137
}
138138

139139
@Test
140-
public void testAngularHtml() throws Exception {
140+
void testAngularHtml() throws Exception {
141141
TextEditor editor = (TextEditor) IDE.openEditor(
142142
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
143143
appFolder.getFile("app.componentWithHtml.ts"));

org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/autoclose/XMLAutoCloseTagReconciler.java

Lines changed: 69 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -50,75 +50,6 @@ public class XMLAutoCloseTagReconciler implements IReconciler {
5050

5151
private Listener listener;
5252

53-
private void autoInsert(DocumentEvent event) {
54-
if (!isEnabled()) {
55-
return;
56-
}
57-
if (event == null || viewer == null) {
58-
return;
59-
}
60-
IDocument document = event.getDocument();
61-
if (document == null || event == null || event.getLength() != 0 || event.getText().length() != 1) {
62-
return;
63-
}
64-
65-
int offset = event.getOffset() + 1;
66-
char c = event.getText().charAt(0);
67-
if (c != '>' && c != '/') {
68-
return;
69-
}
70-
URI uri = LSPEclipseUtils.toUri(document);
71-
if (uri == null) {
72-
return;
73-
}
74-
75-
TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri.toString());
76-
Optional<LSPDocumentInfo> info = LanguageServiceAccessor
77-
.getLSPDocumentInfosFor(document, (capabilities) -> true).stream()
78-
.filter(doc -> (doc.getLanguageClient() instanceof XMLLanguageServerAPI)).findAny();
79-
if (!info.isEmpty()) {
80-
// The document is bound with XML language server, consumes the xml/closeTag
81-
final Display display = viewer.getTextWidget().getDisplay();
82-
CompletableFuture.supplyAsync(() -> {
83-
try {
84-
// Wait for textDocument/didChange
85-
Thread.sleep(100);
86-
} catch (InterruptedException ex) {
87-
Thread.interrupted();
88-
}
89-
try {
90-
TextDocumentPositionParams params = LSPEclipseUtils.toTextDocumentPosistionParams(uri, offset,
91-
document);
92-
// consumes xml/closeTag from XML language server
93-
((XMLLanguageServerAPI) info.get().getLanguageClient()).closeTag(params).thenAccept(r -> {
94-
if (r != null) {
95-
display.asyncExec(() -> {
96-
try {
97-
// we receive a text like
98-
// $0</foo>
99-
// $0 should be used for set the cursor.
100-
String text = r.snippet.replace("$0", "");
101-
int replaceLength = getReplaceLength(r.range, document);
102-
document.replace(offset, replaceLength, text);
103-
} catch (BadLocationException e) {
104-
// Do nothing
105-
}
106-
});
107-
108-
}
109-
});
110-
} catch (BadLocationException e) {
111-
// Do nothing
112-
}
113-
return null;
114-
});
115-
}
116-
}
117-
118-
private boolean isEnabled() {
119-
return Activator.getDefault().getPreferenceStore().getBoolean(XML_PREFERENCES_COMPLETION_AUTO_CLOSE_TAGS);
120-
}
121-
12253
private static int getReplaceLength(Range range, IDocument document) throws BadLocationException {
12354
if (range == null) {
12455
return 0;
@@ -138,24 +69,15 @@ private static int getReplaceLength(Range range, IDocument document) throws BadL
13869
*/
13970
class Listener implements IDocumentListener, ITextInputListener {
14071

141-
/*
142-
* @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
143-
*/
14472
@Override
14573
public void documentAboutToBeChanged(DocumentEvent e) {
14674
}
14775

148-
/*
149-
* @see IDocumentListener#documentChanged(DocumentEvent)
150-
*/
15176
@Override
15277
public void documentChanged(DocumentEvent e) {
15378
autoInsert(e);
15479
}
15580

156-
/*
157-
* @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument, IDocument)
158-
*/
15981
@Override
16082
public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
16183
if (oldInput == document) {
@@ -166,9 +88,6 @@ public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput
16688
}
16789
}
16890

169-
/*
170-
* @see ITextInputListener#inputDocumentChanged(IDocument, IDocument)
171-
*/
17291
@Override
17392
public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
17493
document = newInput;
@@ -177,6 +96,75 @@ public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
17796
}
17897
document.addDocumentListener(this);
17998
}
99+
100+
private void autoInsert(DocumentEvent event) {
101+
if (!isEnabled()) {
102+
return;
103+
}
104+
if (event == null || viewer == null) {
105+
return;
106+
}
107+
IDocument document = event.getDocument();
108+
if (document == null || event == null || event.getLength() != 0 || event.getText().length() != 1) {
109+
return;
110+
}
111+
112+
int offset = event.getOffset() + 1;
113+
char c = event.getText().charAt(0);
114+
if (c != '>' && c != '/') {
115+
return;
116+
}
117+
URI uri = LSPEclipseUtils.toUri(document);
118+
if (uri == null) {
119+
return;
120+
}
121+
122+
TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri.toString());
123+
Optional<LSPDocumentInfo> info = LanguageServiceAccessor
124+
.getLSPDocumentInfosFor(document, capabilities -> true).stream()
125+
.filter(doc -> (doc.getLanguageClient() instanceof XMLLanguageServerAPI)).findAny();
126+
if (!info.isEmpty()) {
127+
// The document is bound with XML language server, consumes the xml/closeTag
128+
final Display display = viewer.getTextWidget().getDisplay();
129+
CompletableFuture.supplyAsync(() -> {
130+
try {
131+
// Wait for textDocument/didChange
132+
Thread.sleep(100);
133+
} catch (InterruptedException ex) {
134+
Thread.interrupted();
135+
}
136+
try {
137+
TextDocumentPositionParams params = LSPEclipseUtils.toTextDocumentPosistionParams(uri, offset,
138+
document);
139+
// consumes xml/closeTag from XML language server
140+
((XMLLanguageServerAPI) info.get().getLanguageClient()).closeTag(params).thenAccept(r -> {
141+
if (r != null) {
142+
display.asyncExec(() -> {
143+
try {
144+
// we receive a text like
145+
// $0</foo>
146+
// $0 should be used for set the cursor.
147+
String text = r.snippet.replace("$0", "");
148+
int replaceLength = getReplaceLength(r.range, document);
149+
document.replace(offset, replaceLength, text);
150+
} catch (BadLocationException e) {
151+
// Do nothing
152+
}
153+
});
154+
155+
}
156+
});
157+
} catch (BadLocationException e) {
158+
// Do nothing
159+
}
160+
return null;
161+
});
162+
}
163+
}
164+
165+
private boolean isEnabled() {
166+
return Activator.getDefault().getPreferenceStore().getBoolean(XML_PREFERENCES_COMPLETION_AUTO_CLOSE_TAGS);
167+
}
180168

181169
}
182170

org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/MessageUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static int showBrowserLocationsConfigurationError(Shell parentShell, ILau
6464
IStatus errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, title);
6565
Activator.getDefault().getLog().log(errorStatus);
6666

67-
int result[] = {Window.CANCEL};
67+
int[] result = {Window.CANCEL};
6868
Display.getDefault().syncExec(() -> {
6969
int response = suggestEditLaunch ?
7070
MessageDialog.open(MessageDialog.ERROR, parentShell, title, message, SWT.NONE,

org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/node/NodeRunDAPDebugDelegate.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private boolean configureAdditionalParameters(Map<String, Object> param) {
168168

169169
if (errorMessage == null) {
170170
Object option = co.get("sourceMap");
171-
boolean sourceMap = option instanceof Boolean b ? b.booleanValue() : false;
171+
boolean sourceMap = option instanceof Boolean b && b.booleanValue();
172172
if (!sourceMap) {
173173
errorMessage = Messages.NodeDebug_TSConfirError_SourceMapIsNotEnabled;
174174
}
@@ -264,11 +264,9 @@ private IFile createNewEmptyFile(String tsConfigPath) {
264264

265265
void createContainers(IResource resource) throws CoreException {
266266
IContainer container= resource.getParent();
267-
if (container instanceof IFolder parent) {
268-
if (parent != null && !parent.exists()) {
269-
createContainers(parent);
270-
parent.create(false, true, null);
271-
}
267+
if (container instanceof IFolder parent && !parent.exists()) {
268+
createContainers(parent);
269+
parent.create(false, true, null);
272270
}
273271
}
274272
});

0 commit comments

Comments
 (0)