Skip to content

Commit

Permalink
Extract unescapedUnicode() method into a util class
Browse files Browse the repository at this point in the history
  • Loading branch information
pubudu91 committed Mar 7, 2022
1 parent 82d1138 commit 147e4a2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.ballerina.compiler.api.symbols.SymbolKind;
import io.ballerina.compiler.api.symbols.TypeDescKind;
import io.ballerina.compiler.api.symbols.TypeSymbol;
import io.ballerina.identifier.Utils;
import io.ballerina.tools.diagnostics.Location;
import org.wso2.ballerinalang.compiler.semantics.analyzer.Types;
import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType;
Expand All @@ -34,6 +33,8 @@
import java.util.List;
import java.util.Optional;

import static io.ballerina.compiler.api.impl.util.SymbolUtils.unescapeUnicode;

/**
* Represents a Ballerina Type Descriptor.
*
Expand Down Expand Up @@ -119,7 +120,7 @@ public boolean nameEquals(String name) {
if (name.equals(symName)) {
return true;
}
return unescapedUnicode(name).equals(unescapedUnicode(symName));
return unescapeUnicode(name).equals(unescapeUnicode(symName));
}

@Override
Expand Down Expand Up @@ -191,11 +192,4 @@ private BType getTargetBType(TypeSymbol typeSymbol) {

return ((BallerinaClassSymbol) typeSymbol).getBType();
}

private String unescapedUnicode(String value) {
if (value.startsWith("'")) {
return Utils.unescapeUnicodeCodepoints(value.substring(1));
}
return Utils.unescapeUnicodeCodepoints(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.Optional;
import java.util.StringJoiner;

import static io.ballerina.compiler.api.impl.util.SymbolUtils.unescapeUnicode;
import static io.ballerina.compiler.api.symbols.SymbolKind.SERVICE_DECLARATION;

/**
Expand Down Expand Up @@ -247,6 +248,6 @@ private boolean isInternalSymbolNameEquals(String name) {
if (name.equals(symbolName)) {
return true;
}
return unescapedUnicode(name).equals(unescapedUnicode(symbolName));
return unescapeUnicode(name).equals(unescapeUnicode(symbolName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
*/
package io.ballerina.compiler.api.impl.symbols;

import io.ballerina.compiler.api.impl.BallerinaKeywordsProvider;
import io.ballerina.compiler.api.impl.SymbolFactory;
import io.ballerina.compiler.api.symbols.Documentation;
import io.ballerina.compiler.api.symbols.ModuleSymbol;
import io.ballerina.compiler.api.symbols.Symbol;
import io.ballerina.compiler.api.symbols.SymbolKind;
import io.ballerina.identifier.Utils;
import io.ballerina.tools.diagnostics.Location;
import io.ballerina.tools.text.LineRange;
import io.ballerina.tools.text.TextRange;
Expand All @@ -35,6 +33,8 @@
import java.util.Objects;
import java.util.Optional;

import static io.ballerina.compiler.api.impl.util.SymbolUtils.unescapeUnicode;

/**
* Represents the implementation of a Compiled Ballerina Symbol.
*
Expand Down Expand Up @@ -128,7 +128,7 @@ public boolean nameEquals(String name) {
if (name.equals(symName)) {
return true;
}
return unescapedUnicode(name).equals(unescapedUnicode(symName));
return unescapeUnicode(name).equals(unescapeUnicode(symName));
}

@Override
Expand Down Expand Up @@ -179,25 +179,6 @@ protected boolean isSameLocation(Optional<Location> loc1, Optional<Location> loc
return loc1.get().lineRange().equals(loc2.get().lineRange());
}

protected String unescapedUnicode(String value) {
if (value.startsWith("'")) {
return Utils.unescapeUnicodeCodepoints(value.substring(1));
}
return Utils.unescapeUnicodeCodepoints(value);
}

public boolean isReservedKeyword(String value) {
return BallerinaKeywordsProvider.BALLERINA_KEYWORDS.contains(value);
}

public String escapeReservedKeyword(String value) {
if (BallerinaKeywordsProvider.BALLERINA_KEYWORDS.contains(value)) {
return "'" + value;
}

return value;
}

/**
* Represents Ballerina Symbol Builder.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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 io.ballerina.compiler.api.impl.util;

import io.ballerina.identifier.Utils;

public class SymbolUtils {

public static String unescapeUnicode(String value) {
if (value.startsWith("'")) {
return Utils.unescapeUnicodeCodepoints(value.substring(1));
}
return Utils.unescapeUnicodeCodepoints(value);
}
}

0 comments on commit 147e4a2

Please sign in to comment.