Java Code Examples for org.eclipse.xtext.common.types.JvmField#isFinal()

The following examples show how to use org.eclipse.xtext.common.types.JvmField#isFinal() . 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: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected ITreeAppendable _generateModifier(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    this.generateVisibilityModifier(it, appendable);
    boolean _isStatic = it.isStatic();
    if (_isStatic) {
      appendable.append("static ");
    }
    boolean _isFinal = it.isFinal();
    if (_isFinal) {
      appendable.append("final ");
    }
    boolean _isTransient = it.isTransient();
    if (_isTransient) {
      appendable.append("transient ");
    }
    ITreeAppendable _xifexpression = null;
    boolean _isVolatile = it.isVolatile();
    if (_isVolatile) {
      _xifexpression = appendable.append("volatile ");
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 2
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
protected void checkAssignment(XExpression expression, EStructuralFeature feature, boolean simpleAssignment) {
	if (simpleAssignment && expression instanceof XAbstractFeatureCall) {
		final JvmIdentifiableElement assignmentFeature = ((XAbstractFeatureCall) expression).getFeature();
		if (assignmentFeature instanceof JvmField) {
			final JvmField field = (JvmField) assignmentFeature;
			if (!field.isFinal()) {
				return;
			}
			final JvmIdentifiableElement container = getLogicalContainerProvider().getNearestLogicalContainer(expression);
			if (container != null && container instanceof JvmOperation) {
				final JvmOperation operation = (JvmOperation) container;
				if (operation.isStatic() && field.getDeclaringType() == operation.getDeclaringType()
						&& Utils.STATIC_CONSTRUCTOR_NAME.equals(operation.getSimpleName())) {
					return;
				}
			}
		}
	}
	super.checkAssignment(expression, feature, simpleAssignment);
}
 
Example 3
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void checkAssignment(XExpression expression, EStructuralFeature feature, boolean simpleAssignment) {
	if (!(expression instanceof XAbstractFeatureCall)) {
		error("The left-hand side of an assignment must be a variable", expression, null,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_NO_VARIABLE);
		return;
	}
	XAbstractFeatureCall assignment = (XAbstractFeatureCall) expression;
	JvmIdentifiableElement assignmentFeature = assignment.getFeature();
	if (assignmentFeature instanceof XVariableDeclaration) {
		XVariableDeclaration variableDeclaration = (XVariableDeclaration) assignmentFeature;
		if (variableDeclaration.isWriteable()) {
			return;
		}
		error("Assignment to final variable", expression, feature,
			ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL);
	} else if (assignmentFeature instanceof JvmFormalParameter) {
		error("Assignment to final parameter", expression, feature,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL);
	} else if (assignmentFeature instanceof JvmField) {
		JvmField field = (JvmField) assignmentFeature;
		if (!field.isFinal()) {
			return;
		}
		if (simpleAssignment) {
			JvmIdentifiableElement container = logicalContainerProvider.getNearestLogicalContainer(assignment);
			
			// don't issue an error if it's an assignment of a local final field within a constructor.
			if (container != null && container instanceof JvmConstructor) {
				JvmConstructor constructor = (JvmConstructor) container;
				if (field.getDeclaringType() == constructor.getDeclaringType())
					return;
			}
		}
		error("Assignment to final field", expression, feature,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL);
	} else if (!simpleAssignment) {
		error("The left-hand side of an assignment must be a variable", expression, null,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_NO_VARIABLE);
	}
}
 
Example 4
Source File: JvmDeclaredTypeSignatureHashProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected SignatureHashBuilder appendSignature(JvmField field) {
	appendVisibility(field.getVisibility()).append(" ");
	if (field.isStatic())
		append("static ");
	if (field.isFinal())
		append("final ");
	return appendType(field.getType()).append(" ").append(field.getSimpleName());
}
 
Example 5
Source File: XbaseReferenceProposalCreator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected Image computeImage(JvmFeature feature) {
	int flags = 0;
	int decorator = 0;
	switch(feature.getVisibility()) {
		case PUBLIC: flags = Flags.AccPublic; break;
		case PROTECTED: flags = Flags.AccProtected; break;
		case PRIVATE: flags = Flags.AccPrivate; break;
		case DEFAULT: flags = Flags.AccDefault; break;
	}
	JvmDeclaredType declaringType = feature.getDeclaringType();
	boolean interfaceOrAnnotation = false;
	if (declaringType instanceof JvmGenericType) {
		interfaceOrAnnotation = ((JvmGenericType) declaringType).isInterface();
	} else if (declaringType instanceof JvmAnnotationType) {
		interfaceOrAnnotation = true;
	}
	if (feature instanceof JvmConstructor) {
		decorator = JavaElementImageDescriptor.CONSTRUCTOR;
		if (declaringType.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		return computeConstructorImage(declaringType.getDeclaringType() != null, interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmOperation) {
		JvmOperation operation = (JvmOperation) feature;
		if (operation.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (operation.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		if (operation.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		return computeMethodImage(interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmField) {
		JvmField field = (JvmField) feature;
		if (field.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (field.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		if (declaringType instanceof JvmEnumerationType)
			flags |= Flags.AccEnum;
		return computeFieldImage(interfaceOrAnnotation, flags, decorator);
	} 
	return null;
}