Java Code Examples for org.eclipse.jdt.internal.compiler.ast.StringLiteral

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.StringLiteral. These examples are extracted from open source projects. 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 Project: datafu   Source File: EcjMultilineProcessor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
  Set<? extends Element> fields = roundEnv.getElementsAnnotatedWith(Multiline.class);

  for (Element field : fields) {
    String docComment = elementUtils.getDocComment(field);

    if (null != docComment) {
      VariableElementImpl fieldElem = (VariableElementImpl) field;
      FieldBinding biding = (FieldBinding) fieldElem._binding;
      FieldDeclaration decl = biding.sourceField();
      StringLiteral string = new StringLiteral(docComment.toCharArray(), decl.sourceStart, decl.sourceEnd, decl.sourceStart);
      decl.initialization = string;
    }
  }
  return true;
}
 
Example 2
Source Project: EasyMPermission   Source File: HandleConstructor.java    License: MIT License 5 votes vote down vote up
public static Annotation[] createConstructorProperties(ASTNode source, Collection<EclipseNode> fields) {
	if (fields.isEmpty()) return null;
	
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long)pS << 32 | pE;
	long[] poss = new long[3];
	Arrays.fill(poss, p);
	QualifiedTypeReference constructorPropertiesType = new QualifiedTypeReference(JAVA_BEANS_CONSTRUCTORPROPERTIES, poss);
	setGeneratedBy(constructorPropertiesType, source);
	SingleMemberAnnotation ann = new SingleMemberAnnotation(constructorPropertiesType, pS);
	ann.declarationSourceEnd = pE;
	
	ArrayInitializer fieldNames = new ArrayInitializer();
	fieldNames.sourceStart = pS;
	fieldNames.sourceEnd = pE;
	fieldNames.expressions = new Expression[fields.size()];
	
	int ctr = 0;
	for (EclipseNode field : fields) {
		char[] fieldName = removePrefixFromField(field);
		fieldNames.expressions[ctr] = new StringLiteral(fieldName, pS, pE, 0);
		setGeneratedBy(fieldNames.expressions[ctr], source);
		ctr++;
	}
	
	ann.memberValue = fieldNames;
	setGeneratedBy(ann, source);
	setGeneratedBy(ann.memberValue, source);
	return new Annotation[] { ann };
}
 
Example 3
Source Project: EasyMPermission   Source File: HandleUtilityClass.java    License: MIT License 5 votes vote down vote up
private void createPrivateDefaultConstructor(EclipseNode typeNode, EclipseNode sourceNode) {
	ASTNode source = sourceNode.get();
	
	TypeDeclaration typeDeclaration = ((TypeDeclaration) typeNode.get());
	long p = (long) source.sourceStart << 32 | source.sourceEnd;
	
	ConstructorDeclaration constructor = new ConstructorDeclaration(((CompilationUnitDeclaration) typeNode.top().get()).compilationResult);
	
	constructor.modifiers = ClassFileConstants.AccPrivate;
	constructor.selector = typeDeclaration.name;
	constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper);
	constructor.constructorCall.sourceStart = source.sourceStart;
	constructor.constructorCall.sourceEnd = source.sourceEnd;
	constructor.thrownExceptions = null;
	constructor.typeParameters = null;
	constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
	constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;
	constructor.arguments = null;
	
	AllocationExpression exception = new AllocationExpression();
	setGeneratedBy(exception, source);
	long[] ps = new long[JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION.length];
	Arrays.fill(ps, p);
	exception.type = new QualifiedTypeReference(JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION, ps);
	setGeneratedBy(exception.type, source);
	exception.arguments = new Expression[] {
			new StringLiteral(UNSUPPORTED_MESSAGE, source.sourceStart, source.sourceEnd, 0)
	};
	setGeneratedBy(exception.arguments[0], source);
	ThrowStatement throwStatement = new ThrowStatement(exception, source.sourceStart, source.sourceEnd);
	setGeneratedBy(throwStatement, source);
	
	constructor.statements = new Statement[] {throwStatement};
	
	injectMethod(typeNode, constructor);
}
 
Example 4
Source Project: EasyMPermission   Source File: EclipseHandlerUtil.java    License: MIT License 5 votes vote down vote up
public static Annotation[] addSuppressWarningsAll(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) {
	Annotation[] anns = addAnnotation(source, originalAnnotationArray, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, new StringLiteral(ALL, 0, 0, 0));
	
	if (Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS))) {
		MemberValuePair mvp = new MemberValuePair(JUSTIFICATION, 0, 0, new StringLiteral(GENERATED_CODE, 0, 0, 0));
		anns = addAnnotation(source, anns, EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS, mvp);
	}
	
	return anns;
}
 
Example 5
Source Project: EasyMPermission   Source File: EclipseHandlerUtil.java    License: MIT License 4 votes vote down vote up
public static Annotation[] addGenerated(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) {
	if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS))) return originalAnnotationArray;
	return addAnnotation(source, originalAnnotationArray, JAVAX_ANNOTATION_GENERATED, new StringLiteral(LOMBOK, 0, 0, 0));
}
 
Example 6
Source Project: EasyMPermission   Source File: EclipseHandlerUtil.java    License: MIT License 4 votes vote down vote up
/**
 * Generates a new statement that checks if the given variable is null, and if so, throws a specified exception with the
 * variable name as message.
 * 
 * @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}.
 */
public static Statement generateNullCheck(AbstractVariableDeclaration variable, EclipseNode sourceNode) {
	NullCheckExceptionType exceptionType = sourceNode.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE);
	if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION;
	
	ASTNode source = sourceNode.get();
	
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long)pS << 32 | pE;
	
	if (isPrimitive(variable.type)) return null;
	AllocationExpression exception = new AllocationExpression();
	setGeneratedBy(exception, source);
	int partCount = 1;
	String exceptionTypeStr = exceptionType.getExceptionType();
	for (int i = 0; i < exceptionTypeStr.length(); i++) if (exceptionTypeStr.charAt(i) == '.') partCount++;
	long[] ps = new long[partCount];
	Arrays.fill(ps, 0L);
	exception.type = new QualifiedTypeReference(fromQualifiedName(exceptionTypeStr), ps);
	setGeneratedBy(exception.type, source);
	exception.arguments = new Expression[] {
			new StringLiteral(exceptionType.toExceptionMessage(new String(variable.name)).toCharArray(), pS, pE, 0)
	};
	setGeneratedBy(exception.arguments[0], source);
	ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE);
	setGeneratedBy(throwStatement, source);
	
	SingleNameReference varName = new SingleNameReference(variable.name, p);
	setGeneratedBy(varName, source);
	NullLiteral nullLiteral = new NullLiteral(pS, pE);
	setGeneratedBy(nullLiteral, source);
	EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.EQUAL_EQUAL);
	equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE;
	setGeneratedBy(equalExpression, source);
	Block throwBlock = new Block(0);
	throwBlock.statements = new Statement[] {throwStatement};
	throwBlock.sourceStart = pS; throwBlock.sourceEnd = pE;
	setGeneratedBy(throwBlock, source);
	IfStatement ifStatement = new IfStatement(equalExpression, throwBlock, 0, 0);
	setGeneratedBy(ifStatement, source);
	return ifStatement;
}
 
Example 7
Source Project: EasyMPermission   Source File: SetGeneratedByVisitor.java    License: MIT License 4 votes vote down vote up
@Override public boolean visit(StringLiteral node, BlockScope scope) {
	fixPositions(setGeneratedBy(node, source));
	return super.visit(node, scope);
}
 
Example 8
public boolean visit(StringLiteral stringLiteral, BlockScope scope) {
	addRealFragment(stringLiteral);
	return false;
}