当前位置: 首页>>代码示例>>Java>>正文


Java CtField类代码示例

本文整理汇总了Java中spoon.reflect.declaration.CtField的典型用法代码示例。如果您正苦于以下问题:Java CtField类的具体用法?Java CtField怎么用?Java CtField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CtField类属于spoon.reflect.declaration包,在下文中一共展示了CtField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fieldAccess

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
private <T> CtMethod<T> fieldAccess(CtField<T> field) {
    @SuppressWarnings("unchecked")
    Map<CtField<T>, CtMethod<T>> fields = (Map<CtField<T>, CtMethod<T>>) (Map) this.fields;
    return fields.compute(field, (f, proxy) -> {
        if (proxy == null) {
            proxy = createSimpleMethod(f.getType(), f.getSimpleName());
        } else if (proxy.hasModifier(ABSTRACT)) {
            proxy.setBody(f().Core().createBlock());
            proxy.removeModifier(ABSTRACT);
        } else {
            return proxy;
        }
        addGuardingPrologue(proxy);
        CtReturn<T> ret = f().Core().createReturn();
        ret.setReturnedExpression(f().Code().createVariableRead(f.getReference(), false));
        proxy.getBody().addStatement(ret);
        cxt.bindAccessMethod(proxy, StageModel.this);
        return proxy;
    });
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:21,代码来源:StageModel.java

示例2: getAssignedField

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
/**
 * Get all assigned fields in this block
 */
public Set<CtVariable<?>> getAssignedField(BasicBlock block) {
	Set<CtVariable<?>> res = new HashSet<>();

	for (CtCodeElement line : block.getElements()) {

		if (line instanceof CtAssignment) {
			// CtAssignment<?,?> assignment = (CtAssignment<?,?>) line;
			CtExpression<?> leftPart = ((CtAssignment<?, ?>) line).getAssigned();
			if (leftPart instanceof CtFieldAccess) {
				CtField<?> field = ((CtFieldAccess<?>) leftPart).getVariable().getDeclaration();
				res.add(field);
			}
		}

	}

	return res;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:22,代码来源:DefUse.java

示例3: replaceRegistrationParameter

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
private <T> void replaceRegistrationParameter(final @NotNull CtExpression<T> elt,
											  final @NotNull CtAbstractInvocation<?> regInvok,
											  final @NotNull Set<CtAbstractInvocation<?>> unregInvoks,
											  final int regPos, final String widgetName) {
	final Factory fac = regInvok.getFactory();

	if(asField && cmd.getExecutable() instanceof CtMethod<?> || !unregInvoks.isEmpty()) {
		final CtField<T> newField = fac.Core().createField();
		newField.setSimpleName(widgetName + "Cmd");
		newField.addModifier(ModifierKind.FINAL);
		newField.setVisibility(ModifierKind.PRIVATE);
		newField.setType(elt.getType().clone());
		newField.setAssignment(elt);
		cmd.getExecutable().getParent(CtClass.class).addFieldAtTop(newField);
		regInvok.getArguments().get(regPos).replace(SpoonHelper.INSTANCE.createField(fac, newField));
		unregInvoks.forEach(unreg -> getListenerRegPositionInInvok(unreg).ifPresent(pos ->
			unreg.getArguments().get(pos).replace(SpoonHelper.INSTANCE.createField(fac, newField))));
	}else {
		regInvok.getArguments().get(regPos).replace(elt);
	}

	collectRefactoredType(regInvok);
	unregInvoks.forEach(unreg -> collectRefactoredType(unreg));
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:25,代码来源:ListenerCommandRefactor.java

示例4: nbLinkExistence

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
public long nbLinkExistence(Class cl) {

        if(CtField.class.isAssignableFrom(cl))
            return inputProgram.getAllElement(CtField.class).size();

        if(CtClass.class.isAssignableFrom(cl) && !cl.equals(CtEnumImpl.class)) {
            long m = 0;
            List<CtElement> classes = inputProgram.getAllElement(CtClass.class);
            for (CtElement el : classes) {
                CtClass c = (CtClass) el;
                if (cl.getSuperclass() != null)
                    m = m + 1 + c.getSuperInterfaces().size();
                else
                    m = m + c.getSuperInterfaces().size();
            }
            return m;
        }
        return 0;
    }
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:20,代码来源:CVLMetric.java

示例5: nbLinkSubstitution

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
public long nbLinkSubstitution(Class cl) {
    if(CtField.class.isAssignableFrom(cl)) {
        int tmp = inputProgram.getAllElement(CtField.class).size();
        return tmp * tmp;
    }
    if(CtClass.class.isAssignableFrom(cl) && !cl.equals(CtEnumImpl.class)) {
        long m = 0;
        List<CtElement> classes = inputProgram.getAllElement(CtClass.class);
        for (CtElement el : classes) {
            CtClass c = (CtClass) el;
            if (cl.getSuperclass() != null)
                m = m + (1 + c.getSuperInterfaces().size()) * classes.size();
            else
                m = m + c.getSuperInterfaces().size() * classes.size();
        }
        return m;
    }
    return 0;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:20,代码来源:CVLMetric.java

示例6: accessibleFieldsFrom

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
public static Collection<CtField<?>> accessibleFieldsFrom(CtTypeReference<?> accessingType, CtTypeReference<?> accessedType) {
    Collection<CtField<?>> accessibleFields = MetaList.newLinkedList();
    try {
        Collection<CtFieldReference<?>> allFields = accessedType.getAllFields();
        for (CtFieldReference<?> field : allFields) {
            CtField<?> actualField = field.getDeclaration();
            if (actualField != null && isVisibleFrom(accessingType, actualField, field.getDeclaringType(), accessedType)) {
                accessibleFields.add(actualField);
            }
        }
    } catch (Throwable e) {
        logWarning(logger(), e.toString());
    }
    return accessibleFields;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:16,代码来源:SpoonReferenceLibrary.java

示例7: process

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
public void process(CtElement element) {
	if (element instanceof CtNamedElement || element instanceof CtField || element instanceof CtExecutable) {
		if (((CtModifiable) element).getModifiers().contains(ModifierKind.PUBLIC) || ((CtModifiable) element).getModifiers().contains(ModifierKind.PROTECTED)) {
			if (element.getDocComment() == null || element.getDocComment().equals("")) {
				undocumentedElements.add(element);
			}
		}
	}
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:10,代码来源:DocProcessor.java

示例8: getUseField

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
private static CtAnnotation<?> getUseField(CtTypeReference<?> clazz, String fieldName) {
    CtType<?> type = clazz.getDeclaration();
    if (type == null) {
        return null;
    }

    CtField<?> field = type.getField(fieldName);
    if (field != null) {
        return EventImplGenTask.getAnnotation(field, "org.spongepowered.api.util.annotation.eventgen.UseField");
    }
    return null;
}
 
开发者ID:SpongePowered,项目名称:event-impl-gen,代码行数:13,代码来源:ClassGenerator.java

示例9: getField

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
public static CtField<?> getField(CtTypeReference<?> clazz, String fieldName) {
    CtField<?> field;
    CtType<?> type = clazz.getDeclaration();
    while (type != null) {
        field = type.getField(fieldName);
        if (field != null) {
            return field;
        }

        type = type.getSuperclass() == null ? null : type.getSuperclass().getDeclaration();
    }
    return null;
}
 
开发者ID:SpongePowered,项目名称:event-impl-gen,代码行数:14,代码来源:ClassGenerator.java

示例10: contributeField

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
private void contributeField(ClassWriter classWriter, CtTypeReference<?> parentType, Property property) {
    if (property.isLeastSpecificType()) {
        CtField<?> field = getField(parentType, property.getName());
        if (field == null || EventImplGenTask.getAnnotation(field, "org.spongepowered.api.util.annotation.eventgen.UseField") == null) {
            generateField(classWriter, property);
        } else if (field.getModifiers().contains(ModifierKind.PRIVATE)) {
            throw new RuntimeException("You've annotated the field " + property.getName() + " with @SetField, "
                    + "but it's private. This just won't work.");
        } else if (!property.getType().isSubtypeOf(field.getType())) {
            throw new RuntimeException(String.format("In event %s with parent %s - you've specified field '%s' of type %s"
                    + " but the property has the type of %s", property.getAccessor().getDeclaringType().getQualifiedName(), parentType.getQualifiedName(), field.getSimpleName(), field.getType().getQualifiedName(), property.getType().getQualifiedName()));
        }
    }
}
 
开发者ID:SpongePowered,项目名称:event-impl-gen,代码行数:15,代码来源:ClassGenerator.java

示例11: chainToAccess

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static CtFieldAccess<?> chainToAccess(List<CtField<?>> chain, AccessType accessType) {
    CtFieldAccess<?> access = null;
    for (int i = chain.size() - 1; i >= 0; i--) {
        CtField<?> field = chain.get(i);
        CoreFactory coreFactory = field.getFactory().Core();
        CtFieldAccess acc = accessType == AccessType.Read ? coreFactory.createFieldRead() :
                coreFactory.createFieldWrite();
        acc.setVariable(field.getReference());
        acc.setType(field.getType());
        acc.setTarget(access);
        access = acc;
    }
    return access;
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:16,代码来源:FieldAccessChains.java

示例12: accessPath

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
List<CtField<?>> accessPath(CompilationNode target) {
    int equalUntil = 0;
    int maxLen = min(rootAccessPath.size(), target.rootAccessPath.size());
    while (equalUntil < maxLen &&
            rootAccessPath.get(equalUntil) == target.rootAccessPath.get(equalUntil)) {
        equalUntil++;
    }
    return target.rootAccessPath.subList(equalUntil,target.rootAccessPath.size());
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:10,代码来源:CompilationNode.java

示例13: isControlledBy

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
/**
 * Must return true if the field is used in @action's conditionals and not
 * defined in the @action's method
 */
public boolean isControlledBy(Action action, CtAssignment<?, ?> fieldAssignment) {// TODO:
																					// move
																					// to
																					// Action

	CtField<?> field = null;
	CtExpression<?> leftPart = fieldAssignment.getAssigned();
	if (leftPart instanceof CtFieldAccess) {
		field = ((CtFieldAccess<?>) leftPart).getVariable().getDeclaration();
	}

	for (CtExpression<?> cond : action.getConditions()) {
		List<CtVariableAccess<?>> usedVars = defuse.findUsedVar(cond);
		for (CtVariableAccess<?> usedVar : usedVars) {

			// if(field != null && field ==
			// usedVar.getVariable().getDeclaration()){
			// Set<CtCodeElement> lastDef = defuse.getReachingDef(usedVar);
			// if(lastDef == null) return true;
			// }

			Set<CtVariable<?>> allDep = defuse.getDeepDef(usedVar);
			if (field != null && allDep.contains(field))
				return true;
		}
	}

	return false;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:34,代码来源:MethodSummary.java

示例14: getControllers

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
/**
 * Return conditions that use @field
 */
public List<CtExpression<?>> getControllers(Action action, CtField<?> field) {// TODO:
																				// move
																				// to
																				// Action

	List<CtExpression<?>> res = new ArrayList<>();

	for (CtExpression<?> cond : action.getConditions()) {
		if (defuse.getDeepDef(cond).contains(field))
			res.add(cond);
	}

	return res;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:18,代码来源:MethodSummary.java

示例15: process

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
@Override
public void process(final @NotNull CtAnnotation<?> element) {
	CtElement elt = element.getAnnotatedElement();

	if(elt instanceof CtField<?>) {
		fieldAnnotations.add((CtField<?>) elt);
	}else if(elt instanceof CtMethod) {
		methodAnnotations.add((CtMethod<?>) elt);
	}
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:11,代码来源:FXMLAnnotationProcessor.java


注:本文中的spoon.reflect.declaration.CtField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。