Java Code Examples for org.eclipse.jdt.core.dom.FieldDeclaration#modifiers()

The following examples show how to use org.eclipse.jdt.core.dom.FieldDeclaration#modifiers() . 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: PlantUmlPreCompiler.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(FieldDeclaration decl) {
	boolean isLifeline = SharedUtils.typeIsAssignableFrom(decl.getType().resolveBinding(), Proxy.class)
			|| SharedUtils.typeIsAssignableFrom(decl.getType().resolveBinding(),
					hu.elte.txtuml.api.model.seqdiag.Lifeline.class);

	if (isLifeline) {
		List<?> modifiers = decl.modifiers();
		Optional<Integer> position = modifiers.stream().filter(modifier -> modifier instanceof Annotation)
				.map(modifier -> (Annotation) modifier)
				.filter(annot -> annot.getTypeName().getFullyQualifiedName().equals("Position"))
				.map(annot -> (int) ((SingleMemberAnnotation) annot).getValue().resolveConstantExpressionValue())
				.findFirst();

		if (position.isPresent()) {
			addLifeline(position.get(), decl);
		} else {
			addLifeline(-1, decl);
		}
	}
	return true;
}
 
Example 2
Source File: ClassFieldCollector.java    From SparkBuilderGenerator with MIT License 5 votes vote down vote up
private boolean isStatic(FieldDeclaration field) {
    List<IExtendedModifier> fieldModifiers = field.modifiers();
    return fieldModifiers.stream()
            .filter(modifier -> modifier instanceof Modifier)
            .filter(modifer -> ((Modifier) modifer).getKeyword().equals(ModifierKeyword.STATIC_KEYWORD))
            .findFirst()
            .isPresent();
}
 
Example 3
Source File: TestQ20.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(FieldDeclaration node) {
	for (Object m : node.modifiers()) {
		if (((org.eclipse.jdt.core.dom.Modifier) m).isTransient()) {
			transientKW++;
			transient2++;
		}
		if (((org.eclipse.jdt.core.dom.Modifier) m).isVolatile()) {
			volatileKW++;
			volatile2++;
		}
	}
	return false;
}
 
Example 4
Source File: TestQ21.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(FieldDeclaration node) {
	for (Object m : node.modifiers()) {
		if (((org.eclipse.jdt.core.dom.Modifier) m).isStatic()) {
			fields++;
			fieds2++;
		}
	}
	return false;
}
 
Example 5
Source File: ElementTypeTeller.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isFinal(FieldDeclaration node) {
	for (Object modifier : node.modifiers()) {
		if (modifier instanceof Modifier && ((Modifier) modifier).isFinal()) {
			return true;
		}
	}
	return false;
}
 
Example 6
Source File: ExtractClassRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
		public void fieldCreated(CompilationUnitRewrite cuRewrite, FieldDeclaration field, ParameterInfo pi) {
			FieldInfo fieldInfo= getFieldInfo(pi.getOldName());
			FieldDeclaration parent= (FieldDeclaration) fieldInfo.declaration.getParent();
			List<IExtendedModifier> modifiers= parent.modifiers();
			ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(field, FieldDeclaration.MODIFIERS2_PROPERTY);
			for (Iterator<IExtendedModifier> iterator= modifiers.iterator(); iterator.hasNext();) {
				IExtendedModifier mod= iterator.next();
				//Temporarily disabled until initialization of final fields is handled correctly
//				if (mod.isModifier()) {
//					Modifier modifier= (Modifier) mod;
//					if (modifier.isFinal())
//						listRewrite.insertLast(moveNode(cuRewrite, modifier), null);
//				}
				if (mod.isAnnotation()) {
					listRewrite.insertFirst(moveNode(cuRewrite, (ASTNode) mod), null);
				}
			}
			if (fieldInfo.initializer != null && fieldInfo.hasFieldReference()) {
				List<VariableDeclarationFragment> fragments= field.fragments();
				for (Iterator<VariableDeclarationFragment> iterator= fragments.iterator(); iterator.hasNext();) {
					VariableDeclarationFragment vdf= iterator.next();
					vdf.setInitializer((Expression) moveNode(cuRewrite, fieldInfo.initializer));
				}
			}
			if (parent.getJavadoc() != null) {
				field.setJavadoc((Javadoc) moveNode(cuRewrite, parent.getJavadoc()));
			}
		}
 
Example 7
Source File: TypeVisitor.java    From repositoryminer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean visit(FieldDeclaration node) {
	List<AbstractField> fields2 = new ArrayList<>();
	ITypeBinding bind = node.getType().resolveBinding();
	
	String type = "";
	boolean primitive = false;
	
	if (bind != null) {
		type = bind.getQualifiedName();
		primitive = bind.isPrimitive();
	}
	
	List<String> modifiers = new ArrayList<String>();
	for (Object modifier : node.modifiers()) {
		modifiers.add(modifier.toString());
	}

	boolean builtIn = type.startsWith("java.") || type.startsWith("javax.") ? true : false;
	
	for (VariableDeclarationFragment vdf : (List<VariableDeclarationFragment>) node.fragments()) {
		fields2.add(new AbstractField(vdf.getName().getIdentifier(), type, modifiers, primitive, builtIn));
	}

	fields.addAll(fields2);
	return true;
}
 
Example 8
Source File: FieldDeclarationWriter.java    From juniversal with MIT License 5 votes vote down vote up
@Override
public void write(FieldDeclaration fieldDeclaration) {
    boolean isFinal = isFinal(fieldDeclaration);
    boolean isStatic = isStatic(fieldDeclaration);

    List<?> modifiers = fieldDeclaration.modifiers();

    writeAccessModifier(modifiers);

    if (isStatic)
        writeStaticModifier();

    // TODO: Consider checking if value is fixed at compile time and marking const instead of readonly
    if (isFinal)
        writeReadonlyModifier();

    // Skip the modifiers
    skipModifiers(modifiers);
    skipSpaceAndComments();

    // Write the type
    writeNode(fieldDeclaration.getType());

    writeCommaDelimitedNodes(fieldDeclaration.fragments());

    copySpaceAndComments();
    matchAndWrite(";");
}