use of org.develnext.jphp.core.tokenizer.token.CommentToken in project jphp by jphp-compiler.
the class TokenizerTest method testComments.
@Test
public void testComments() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("/** FOO BAR \n\r100500 */"));
Token token = tokenizer.nextToken();
assertTrue(token instanceof CommentToken);
assertEquals(CommentToken.Kind.DOCTYPE, ((CommentToken) token).getKind());
assertEquals("FOO BAR\n\n100500", ((CommentToken) token).getComment());
// simple
tokenizer = new Tokenizer(new Context("// foobar \n $x"));
token = tokenizer.nextToken();
assertTrue(token instanceof CommentToken);
assertEquals(CommentToken.Kind.SIMPLE, ((CommentToken) token).getKind());
assertEquals(" foobar ", ((CommentToken) token).getComment());
assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
assertNull(tokenizer.nextToken());
tokenizer = new Tokenizer(new Context("# // foobar \n $x"));
token = tokenizer.nextToken();
assertTrue(token instanceof CommentToken);
assertEquals(CommentToken.Kind.SIMPLE, ((CommentToken) token).getKind());
assertEquals(" // foobar ", ((CommentToken) token).getComment());
assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
assertNull(tokenizer.nextToken());
// block
tokenizer = new Tokenizer(new Context("/* foobar \n */"));
token = tokenizer.nextToken();
assertTrue(token instanceof CommentToken);
assertEquals(CommentToken.Kind.BLOCK, ((CommentToken) token).getKind());
}
use of org.develnext.jphp.core.tokenizer.token.CommentToken in project jphp by jphp-compiler.
the class ClassGenerator method processDefine.
@SuppressWarnings("unchecked")
protected ClassStmtToken processDefine(Token current, ListIterator<Token> iterator) {
ClassStmtToken result = null;
if (isTokenClass(current, FinalStmtToken.class, AbstractStmtToken.class)) {
Token next = nextToken(iterator);
if (next instanceof ClassStmtToken) {
result = (ClassStmtToken) next;
result.setInterface(false);
result.setAbstract(current instanceof AbstractStmtToken);
result.setFinal(current instanceof FinalStmtToken);
//return result;
} else if (next instanceof InterfaceStmtToken || next instanceof TraitStmtToken) {
unexpectedToken(current);
} else if (next instanceof AbstractStmtToken || next instanceof FinalStmtToken) {
unexpectedToken(next);
} else {
iterator.previous();
}
}
if (current instanceof ClassStmtToken)
result = (ClassStmtToken) current;
else if (current instanceof InterfaceStmtToken) {
result = new ClassStmtToken(current.getMeta());
result.setInterface(true);
} else if (current instanceof TraitStmtToken) {
result = new ClassStmtToken(current.getMeta());
result.setClassType(ClassEntity.Type.TRAIT);
}
if (result != null) {
iterator.previous();
if (result.isFinal() || result.isAbstract())
iterator.previous();
if (iterator.hasPrevious()) {
Token tk = iterator.previous();
if (tk instanceof CommentToken) {
result.setDocComment((CommentToken) tk);
}
iterator.next();
}
if (result.isFinal() || result.isAbstract())
iterator.next();
iterator.next();
}
return result;
}
use of org.develnext.jphp.core.tokenizer.token.CommentToken in project jphp by jphp-compiler.
the class CommentsTest method testBug154.
@Test
public void testBug154() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("/*// */"));
Token token = tokenizer.nextToken();
assertTrue(token instanceof CommentToken);
assertEquals(CommentToken.Kind.BLOCK, ((CommentToken) token).getKind());
assertEquals("// ", ((CommentToken) token).getComment());
}
Aggregations