Skip to content

Commit

Permalink
Fix NullPointerException and make getFileTypes return non null values
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves B. <PyvesDev@gmail.com>
  • Loading branch information
PyvesB authored and mickaelistria committed Sep 5, 2019
1 parent b12cba8 commit 48b7b17
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015-2017 Angelo ZERR.
* Copyright (c) 2015-2019 Angelo ZERR.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -8,6 +8,7 @@
*
* Contributors:
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
* Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes
*/
package org.eclipse.tm4e.core.internal.grammar.parser;

Expand Down Expand Up @@ -242,12 +243,15 @@ public String getScopeName() {
public Collection<String> getFileTypes() {
if(fileTypes==null) {
List<String> list=new ArrayList<>();
for(Object o: (Collection<?>) super.get("fileTypes")) {
String str=o.toString();
// #202
if(str.startsWith("."))
str=str.substring(1);
list.add(str);
Collection<?> unparsedFileTypes = (Collection<?>) super.get("fileTypes");
if (unparsedFileTypes != null) {
for(Object o: unparsedFileTypes) {
String str=o.toString();
// #202
if(str.startsWith("."))
str=str.substring(1);
list.add(str);
}
}
fileTypes=list;
}
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015-2017 Angelo ZERR.
* Copyright (c) 2015-2019 Angelo ZERR.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -8,6 +8,7 @@
*
* Contributors:
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
* Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes
*/
package org.eclipse.tm4e.registry.internal;

Expand Down Expand Up @@ -112,7 +113,7 @@ public IGrammar getGrammarForFileType(String fileType) {
IGrammar grammar = getGrammarForScope(definition.getScopeName());
if (grammar != null) {
Collection<String> fileTypes = grammar.getFileTypes();
if (fileTypes != null && fileTypes.contains(fileType)) {
if (fileTypes.contains(fileType)) {
return grammar;
}
}
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015-2017 Angelo ZERR.
* Copyright (c) 2015-2019 Angelo ZERR.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -8,6 +8,7 @@
*
* Contributors:
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
* Pierre-Yves B. - Issue #221 NullPointerException when retrieving fileTypes
*/
package org.eclipse.tm4e.ui.internal.widgets;

Expand Down Expand Up @@ -82,8 +83,7 @@ public void refresh(IGrammar grammar) {
String scope = grammar.getScopeName();
scopeNameText.setText(scope != null ? scope : "");
Collection<String> fileTypes = grammar.getFileTypes();
String types = fileTypes != null ? fileTypes.stream().map(Object::toString).collect(Collectors.joining(","))
: "";
String types = fileTypes.stream().map(Object::toString).collect(Collectors.joining(","));
fileTypesText.setText(types);
}
}
Expand Down

0 comments on commit 48b7b17

Please sign in to comment.