Java Code Examples for org.eclipse.jdt.core.compiler.ITerminalSymbols#TokenNameEOF

The following examples show how to use org.eclipse.jdt.core.compiler.ITerminalSymbols#TokenNameEOF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static boolean isJustWhitespaceOrComment(int start, int end, IBuffer buffer) {
	if (start == end) {
		return true;
	}
	Assert.isTrue(start <= end);
	String trimmedText = buffer.getText(start, end - start).trim();
	if (0 == trimmedText.length()) {
		return true;
	} else {
		IScanner scanner = ToolFactory.createScanner(false, false, false, null);
		scanner.setSource(trimmedText.toCharArray());
		try {
			return scanner.getNextToken() == ITerminalSymbols.TokenNameEOF;
		} catch (InvalidInputException e) {
			return false;
		}
	}
}
 
Example 2
Source File: RefactoringScanner.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private void doScan() {
	try{
		int token = fScanner.getNextToken();
		while (token != ITerminalSymbols.TokenNameEOF) {
			switch (token) {
				case ITerminalSymbols.TokenNameStringLiteral :
				case ITerminalSymbols.TokenNameCOMMENT_JAVADOC :
				case ITerminalSymbols.TokenNameCOMMENT_LINE :
				case ITerminalSymbols.TokenNameCOMMENT_BLOCK :
					parseCurrentToken();
			}
			token = fScanner.getNextToken();
		}
	} catch (InvalidInputException e){
		//ignore
	}
}
 
Example 3
Source File: JavaWhitespaceTokenizer.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public List<String> tokenListFromCode(final char[] code) {
	final List<String> tokens = Lists.newArrayList();
	tokens.add(SENTENCE_START);
	final PublicScanner scanner = prepareScanner(code);
	do {
		try {
			final int token = scanner.getNextToken();
			if (token == ITerminalSymbols.TokenNameEOF) {
				break;
			}
			tokens.addAll(getConvertedToken(scanner, token));
		} catch (final InvalidInputException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	} while (!scanner.atEnd());
	tokens.add(SENTENCE_END);
	return tokens;
}
 
Example 4
Source File: JavaWhitespaceTokenizer.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public List<FullToken> getTokenListFromCode(final char[] code) {
	final List<FullToken> tokens = Lists.newArrayList();
	tokens.add(new FullToken(SENTENCE_START, SENTENCE_START));
	final PublicScanner scanner = prepareScanner(code);
	do {
		try {
			final int token = scanner.getNextToken();
			if (token == ITerminalSymbols.TokenNameEOF) {
				break;
			}
			for (final String cToken : getConvertedToken(scanner, token)) {
				tokens.add(new FullToken(cToken, ""));
			}
		} catch (final InvalidInputException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	} while (!scanner.atEnd());
	tokens.add(new FullToken(SENTENCE_END, SENTENCE_END));
	return tokens;
}
 
Example 5
Source File: MarkerUtil.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @param source
 *            must be not null
 * @param range
 *            can be null
 * @return may return null, otherwise an initialized scanner which may
 *         answer which source offset index belongs to which source line
 * @throws JavaModelException
 */
private static IScanner initScanner(IType source, ISourceRange range) throws JavaModelException {
    if (range == null) {
        return null;
    }
    char[] charContent = getContent(source);
    if (charContent == null) {
        return null;
    }
    IScanner scanner = ToolFactory.createScanner(false, false, false, true);
    scanner.setSource(charContent);
    int offset = range.getOffset();
    try {
        while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) {
            // do nothing, just wait for the end of stream
            if (offset <= scanner.getCurrentTokenEndPosition()) {
                break;
            }
        }
    } catch (InvalidInputException e) {
        FindbugsPlugin.getDefault().logException(e, "Could not init scanner for type: " + source);
    }
    return scanner;
}
 
Example 6
Source File: JavaWhitespaceTokenizer.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<FullToken> getTokenListFromCode(final char[] code) {
	final List<FullToken> tokens = Lists.newArrayList();
	tokens.add(new FullToken(SENTENCE_START, SENTENCE_START));
	final PublicScanner scanner = prepareScanner(code);
	do {
		try {
			final int token = scanner.getNextToken();
			if (token == ITerminalSymbols.TokenNameEOF) {
				break;
			}
			for (final String cToken : getConvertedToken(scanner, token)) {
				tokens.add(new FullToken(cToken, ""));
			}
		} catch (final InvalidInputException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	} while (!scanner.atEnd());
	tokens.add(new FullToken(SENTENCE_END, SENTENCE_END));
	return tokens;
}
 
Example 7
Source File: JavaTokenizer.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code) {
	// TODO Duplicate Code
	final PublicScanner scanner = prepareScanner();
	final SortedMap<Integer, FullToken> tokens = Maps.newTreeMap();
	tokens.put(-1, new FullToken(SENTENCE_START, SENTENCE_START));
	tokens.put(Integer.MAX_VALUE, new FullToken(SENTENCE_END, SENTENCE_END));
	scanner.setSource(code);
	while (!scanner.atEnd()) {
		do {
			try {
				final int token = scanner.getNextToken();
				if (token == ITerminalSymbols.TokenNameEOF) {
					break;
				}
				final String nxtToken = transformToken(token,
						scanner.getCurrentTokenString());
				final int position = scanner.getCurrentTokenStartPosition();
				tokens.put(position,
						new FullToken(nxtToken, Integer.toString(token)));
			} catch (final InvalidInputException e) {
				LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
			}
		} while (!scanner.atEnd());

	}
	return tokens;
}
 
Example 8
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isValidComment(String template) {
	IScanner scanner= ToolFactory.createScanner(true, false, false, false);
	scanner.setSource(template.toCharArray());
	try {
		int next= scanner.getNextToken();
		while (TokenScanner.isComment(next)) {
			next= scanner.getNextToken();
		}
		return next == ITerminalSymbols.TokenNameEOF;
	} catch (InvalidInputException e) {
	}
	return false;
}
 
Example 9
Source File: JavaWhitespaceTokenizer.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SortedMap<Integer, String> tokenListWithPos(final char[] code) {
	final SortedMap<Integer, String> tokens = Maps.newTreeMap();
	tokens.put(-1, SENTENCE_START);
	tokens.put(Integer.MAX_VALUE, SENTENCE_END);
	final PublicScanner scanner = prepareScanner(code);

	while (!scanner.atEnd()) {
		do {
			try {
				final int token = scanner.getNextToken();
				final int position = scanner
						.getCurrentTokenStartPosition();
				if (token == ITerminalSymbols.TokenNameEOF) {
					break;
				}
				int i = 0;
				final List<String> cTokens = getConvertedToken(scanner,
						token);
				for (final String cToken : cTokens) {
					tokens.put(position + i, cToken);
					i++;
				}
			} catch (final InvalidInputException e) {
				LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
			}
		} while (!scanner.atEnd());
	}
	return tokens;
}
 
Example 10
Source File: JavaTokenTypeTokenizer.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public List<FullToken> getTokenListFromCode(final char[] code) {
	final List<FullToken> tokens = Lists.newArrayList();
	tokens.add(new FullToken(SENTENCE_START, SENTENCE_START));
	final PublicScanner scanner = createScanner();
	scanner.setSource(code);
	do {
		try {
			final int token = scanner.getNextToken();
			if (token == ITerminalSymbols.TokenNameEOF) {
				break;
			} else if (token == ITerminalSymbols.TokenNameIdentifier) {
				tokens.add(new FullToken(IDENTIFIER_TOKEN, ""));
			} else if (isLiteralToken(token)) {
				tokens.add(new FullToken(LITERAL_TOKEN, ""));
			} else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) {
				tokens.add(new FullToken(COMMENT_BLOCK, ""));
			} else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) {
				tokens.add(new FullToken(COMMENT_JAVADOC, ""));
			} else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) {
				tokens.add(new FullToken(COMMENT_LINE, ""));
			} else {
				tokens.add(new FullToken(scanner.getCurrentTokenString(),
						""));
			}

		} catch (final InvalidInputException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	} while (!scanner.atEnd());
	tokens.add(new FullToken(SENTENCE_END, SENTENCE_END));
	return tokens;
}
 
Example 11
Source File: TokenScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Evaluates the start offset of comments directly ahead of a token specified by its start offset
 *
 * @param lastPos An offset to before the node start offset. Can be 0 but better is the end location of the previous node.
 * @param nodeStart Start offset of the node to find the comments for.
 * @return Returns the start offset of comments directly ahead of a token.
 * @exception CoreException Thrown when a lexical error was detected while scanning (code LEXICAL_ERROR)
 */
public int getTokenCommentStart(int lastPos, int nodeStart) throws CoreException {
	setOffset(lastPos);

	int prevEndPos= lastPos;
	int prevEndLine= prevEndPos > 0 ? getLineOfOffset(prevEndPos - 1) : 0;
	int nodeLine= getLineOfOffset(nodeStart);

	int res= -1;

	int curr= readNextWithEOF(false);
	int currStartPos= getCurrentStartOffset();
	int currStartLine= getLineOfOffset(currStartPos);
	while (curr != ITerminalSymbols.TokenNameEOF && nodeStart > currStartPos) {
		if (TokenScanner.isComment(curr)) {
			int linesDifference= currStartLine - prevEndLine;
			if ((linesDifference > 1) || (res == -1 && (linesDifference != 0 || nodeLine == currStartLine))) {
				res= currStartPos; // begin new
			}
		} else {
			res= -1;
		}

		if (curr == ITerminalSymbols.TokenNameCOMMENT_LINE) {
			prevEndLine= currStartLine;
		} else {
			prevEndLine= getLineOfOffset(getCurrentEndOffset() - 1);
		}
		curr= readNextWithEOF(false);
		currStartPos= getCurrentStartOffset();
		currStartLine= getLineOfOffset(currStartPos);
	}
	if (res == -1 || curr == ITerminalSymbols.TokenNameEOF) {
		return nodeStart;
	}
	if (currStartLine - prevEndLine > 1) {
		return nodeStart;
	}
	return res;
}
 
Example 12
Source File: JavaTokenTypeTokenizer.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SortedMap<Integer, String> tokenListWithPos(final char[] code) {
	final SortedMap<Integer, String> tokens = Maps.newTreeMap();
	tokens.put(-1, SENTENCE_START);
	tokens.put(Integer.MAX_VALUE, SENTENCE_END);
	final PublicScanner scanner = createScanner();
	scanner.setSource(code);
	while (!scanner.atEnd()) {
		do {
			try {
				final int token = scanner.getNextToken();
				final int position = scanner.getCurrentTokenStartPosition();

				if (token == ITerminalSymbols.TokenNameEOF) {
					break;
				} else if (token == ITerminalSymbols.TokenNameIdentifier) {
					tokens.put(position, IDENTIFIER_TOKEN);
				} else if (isLiteralToken(token)) {
					tokens.put(position, LITERAL_TOKEN);
				} else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) {
					tokens.put(position, COMMENT_BLOCK);
				} else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) {
					tokens.put(position, COMMENT_JAVADOC);
				} else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) {
					tokens.put(position, COMMENT_LINE);
				} else {
					tokens.put(position, scanner.getCurrentTokenString());
				}

			} catch (final InvalidInputException e) {
				LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
			}
		} while (!scanner.atEnd());

	}
	return tokens;
}
 
Example 13
Source File: JavaWhitespaceTokenizer.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public SortedMap<Integer, String> tokenListWithPos(final char[] code) {
	final SortedMap<Integer, String> tokens = Maps.newTreeMap();
	tokens.put(-1, SENTENCE_START);
	tokens.put(Integer.MAX_VALUE, SENTENCE_END);
	final PublicScanner scanner = prepareScanner(code);

	while (!scanner.atEnd()) {
		do {
			try {
				final int token = scanner.getNextToken();
				final int position = scanner
						.getCurrentTokenStartPosition();
				if (token == ITerminalSymbols.TokenNameEOF) {
					break;
				}
				int i = 0;
				final List<String> cTokens = getConvertedToken(scanner,
						token);
				for (final String cToken : cTokens) {
					tokens.put(position + i, cToken);
					i++;
				}
			} catch (final InvalidInputException e) {
				LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
			}
		} while (!scanner.atEnd());
	}
	return tokens;
}
 
Example 14
Source File: JavaTokenTypeTokenizer.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code) {
	final SortedMap<Integer, FullToken> tokens = Maps.newTreeMap();
	tokens.put(-1, new FullToken(SENTENCE_START, SENTENCE_START));
	tokens.put(Integer.MAX_VALUE, new FullToken(SENTENCE_END, SENTENCE_END));
	final PublicScanner scanner = createScanner();
	scanner.setSource(code);
	while (!scanner.atEnd()) {
		do {
			try {
				final int token = scanner.getNextToken();
				final int position = scanner.getCurrentTokenStartPosition();

				if (token == ITerminalSymbols.TokenNameEOF) {
					break;
				} else if (token == ITerminalSymbols.TokenNameIdentifier) {
					tokens.put(position,
							new FullToken(IDENTIFIER_TOKEN, ""));
				} else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) {
					tokens.put(position, new FullToken(COMMENT_BLOCK, ""));
				} else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) {
					tokens.put(position, new FullToken(COMMENT_JAVADOC, ""));
				} else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) {
					tokens.put(position, new FullToken(COMMENT_LINE, ""));
				} else if (isLiteralToken(token)) {
					tokens.put(position, new FullToken(LITERAL_TOKEN, ""));
				} else {
					tokens.put(position,
							new FullToken(scanner.getCurrentTokenString(),
									""));
				}

			} catch (final InvalidInputException e) {
				LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
			}
		} while (!scanner.atEnd());

	}
	return tokens;
}
 
Example 15
Source File: JavaTokenTypeTokenizer.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public List<String> tokenListFromCode(final char[] code) {
	final List<String> tokens = Lists.newArrayList();
	tokens.add(SENTENCE_START);
	final PublicScanner scanner = createScanner();
	scanner.setSource(code);
	do {
		try {
			final int token = scanner.getNextToken();
			if (token == ITerminalSymbols.TokenNameEOF) {
				break;
			} else if (token == ITerminalSymbols.TokenNameIdentifier) {
				tokens.add(IDENTIFIER_TOKEN);
			} else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) {
				tokens.add(COMMENT_BLOCK);
			} else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) {
				tokens.add(COMMENT_LINE);
			} else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) {
				tokens.add(COMMENT_JAVADOC);
			} else if (isLiteralToken(token)) {
				tokens.add(LITERAL_TOKEN);
			} else {
				tokens.add(scanner.getCurrentTokenString());
			}

		} catch (final InvalidInputException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	} while (!scanner.atEnd());
	tokens.add(SENTENCE_END);
	return tokens;
}
 
Example 16
Source File: CommentAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void check(RefactoringStatus result, Selection selection, IScanner scanner, int start, int end) {
	char[] characters= scanner.getSource();
	selection= adjustSelection(characters, selection, end);
	scanner.resetTo(start, end);

	int token= 0;
	try {
		loop: while (token != ITerminalSymbols.TokenNameEOF) {
			token= scanner.getNextToken();
			switch(token) {
				case ITerminalSymbols.TokenNameCOMMENT_LINE:
				case ITerminalSymbols.TokenNameCOMMENT_BLOCK:
				case ITerminalSymbols.TokenNameCOMMENT_JAVADOC:
					if (checkStart(scanner, selection.getOffset())) {
						result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_starts_inside_comment);
						break loop;
					}
					if (checkEnd(scanner, selection.getInclusiveEnd())) {
						result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_ends_inside_comment);
						break loop;
					}
					break;
			}
		}
	} catch (InvalidInputException e) {
		result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_internal_error);
	}
}
 
Example 17
Source File: CodeTemplateContextType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isValidComment(String template) {
	IScanner scanner= ToolFactory.createScanner(true, false, false, false);
	scanner.setSource(template.toCharArray());
	try {
		int next= scanner.getNextToken();
		while (TokenScanner.isComment(next)) {
			next= scanner.getNextToken();
		}
		return next == ITerminalSymbols.TokenNameEOF;
	} catch (InvalidInputException e) {
	}
	return false;
}
 
Example 18
Source File: TypeOccurrenceCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public SearchMatch acceptSearchMatch2(ICompilationUnit unit, SearchMatch match) throws CoreException {
	int start= match.getOffset();
	int length= match.getLength();

	//unqualified:
	String matchText= unit.getBuffer().getText(start, length);
	if (fOldName.equals(matchText)) {
		return match;
	}

	//(partially) qualified:
	if (fOldQualifiedName.endsWith(matchText)) {
		//e.g. rename B and p.A.B ends with match A.B
		int simpleNameLenght= fOldName.length();
		match.setOffset(start + length - simpleNameLenght);
		match.setLength(simpleNameLenght);
		return match;
	}

	//Not a standard reference -- use scanner to find last identifier token:
	IScanner scanner= getScanner(unit);
	scanner.setSource(matchText.toCharArray());
	int simpleNameStart= -1;
	int simpleNameEnd= -1;
	try {
		int token = scanner.getNextToken();
		while (token != ITerminalSymbols.TokenNameEOF) {
			if (token == ITerminalSymbols.TokenNameIdentifier) {
				simpleNameStart= scanner.getCurrentTokenStartPosition();
				simpleNameEnd= scanner.getCurrentTokenEndPosition();
			}
			token = scanner.getNextToken();
		}
	} catch (InvalidInputException e){
		//ignore
	}
	if (simpleNameStart != -1) {
		match.setOffset(start + simpleNameStart);
		match.setLength(simpleNameEnd + 1 - simpleNameStart);
	}
	return match;
}
 
Example 19
Source File: TypeOccurrenceCollector.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public SearchMatch acceptSearchMatch2(ICompilationUnit unit, SearchMatch match) throws CoreException {
	int start= match.getOffset();
	int length= match.getLength();

	//unqualified:
	String matchText= unit.getBuffer().getText(start, length);
	if (fOldName.equals(matchText)) {
		return match;
	}

	//(partially) qualified:
	if (fOldQualifiedName.endsWith(matchText)) {
		//e.g. rename B and p.A.B ends with match A.B
		int simpleNameLenght= fOldName.length();
		match.setOffset(start + length - simpleNameLenght);
		match.setLength(simpleNameLenght);
		return match;
	}

	//Not a standard reference -- use scanner to find last identifier token:
	IScanner scanner= getScanner(unit);
	scanner.setSource(matchText.toCharArray());
	int simpleNameStart= -1;
	int simpleNameEnd= -1;
	try {
		int token = scanner.getNextToken();
		while (token != ITerminalSymbols.TokenNameEOF) {
			if (token == ITerminalSymbols.TokenNameIdentifier) { // type reference can occur in module-info.java and collide with a restricted keyword.
				simpleNameStart= scanner.getCurrentTokenStartPosition();
				simpleNameEnd= scanner.getCurrentTokenEndPosition();
			}
			token = scanner.getNextToken();
		}
	} catch (InvalidInputException e){
		//ignore
	}
	if (simpleNameStart != -1) {
		match.setOffset(start + simpleNameStart);
		match.setLength(simpleNameEnd + 1 - simpleNameStart);
	}
	return match;
}
 
Example 20
Source File: JavaLexer.java    From SLP-Core with MIT License 4 votes vote down vote up
public List<List<String>> tokenizeLines(String text) {
	IScanner scanner = ToolFactory.createScanner(false, false, true, "1.8");
	scanner.setSource(text.toCharArray());
	List<List<String>> lineTokens = new ArrayList<>();
	List<String> tokens = new ArrayList<>();
	lineTokens.add(new ArrayList<>());
	int nextToken = 0;
	int line = 1;
	while (true) {
		try {
			nextToken = scanner.getNextToken();
			int ln = scanner.getLineNumber(scanner.getCurrentTokenStartPosition());
			if (ln > line) {
				for (int i = line + 1; i <= ln; i++) lineTokens.add(new ArrayList<>());
				line = ln;
			}
			if (nextToken == ITerminalSymbols.TokenNameEOF) break;
		} catch (InvalidInputException e) {
			continue;
		}
		String val = new String(scanner.getCurrentTokenSource());
		if (val.startsWith("\"") && val.endsWith("\"") && val.length() > 2) {
			if (val.length() >= 15) {
				val = "\"\"";
			}
			else {
				String body = val.substring(1, val.length() - 1);
				body = body.replaceAll("\\\\", "\\\\\\\\");
				body = body.replaceAll("\"", "\\\\\"");
				body = body.replaceAll("\n", "\\n");
				body = body.replaceAll("\r", "\\r");
				body = body.replaceAll("\t", "\\t");
				val = "\"" + body + "\"";
			}
		}
		else if (val.startsWith("\'") && val.endsWith("\'")) {
			val = val.replaceAll("\n", "\\n");
			val = val.replaceAll("\r", "\\r");
			val = val.replaceAll("\t", "\\t");
		}
		// For Java, we have to add heuristic check regarding breaking up >>
		else if (val.matches(">>+")) {
			boolean split = false;
			for (int i = tokens.size() - 1; i >= 0; i--) {
				String token = tokens.get(i);
				if (token.matches("[,\\.\\?\\[\\]]") || Character.isUpperCase(token.charAt(0))
						|| token.equals("extends") || token.equals("super")
						|| token.matches("(byte|short|int|long|float|double)")) {
					continue;
				}
				else if (token.matches("(<|>)+")) {
					split = true;
					break;
				}
				else {
					break;
				}
			}
			if (split) {
				for (int i = 0; i < val.length(); i++) {
					tokens.add(">");
					lineTokens.get(lineTokens.size() - 1).add(">");
				}
				continue;
			}
		}
		tokens.add(val);
		lineTokens.get(lineTokens.size() - 1).add(val);
	}
	return lineTokens;
}