• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CtField类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: isStaticAndInit

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
protected boolean isStaticAndInit(CtFieldAccess fieldAccess) {
    CtField field = fieldAccess.getVariable().getDeclaration();
    try {
        if (field != null) {
            return field.getModifiers().contains(ModifierKind.STATIC) && field.getAssignment() != null;
        } else {
            return Modifier.isStatic(fieldAccess.getVariable().getActualField().getModifiers());
        }
    } catch (Exception e) {
        return false;
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:13,代码来源:FieldUsedInstrumenter.java


示例17: canBeAppliedToPoint

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
@Override
public boolean canBeAppliedToPoint(ModificationPoint point) {
	if (!(point.getCodeElement() instanceof CtStatement))
		return false;
	//Do not remove local declaration 
	if (point.getCodeElement() instanceof CtLocalVariable) {
		CtLocalVariable lv = (CtLocalVariable) point.getCodeElement();
		boolean shadow = false;
		CtClass parentC = point.getCodeElement().getParent(CtClass.class);
		List<CtField> ff = parentC.getFields();
		for (CtField<?> f : ff) {
			if (f.getSimpleName().equals(lv.getSimpleName()))
				shadow = true;
		}
		if (!shadow)
			return false;
	}
	//do not remove the last statement
	CtMethod parentMethd = point.getCodeElement().getParent(CtMethod.class);
	if(point.getCodeElement() instanceof CtReturn  
			&& parentMethd.getBody().getLastStatement().equals(point.getCodeElement())){
		return false;
	}
	
	
	//Otherwise, accept the element
	return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:RemoveOp.java


示例18: stageName

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
private static String stageName(CtField<?> field) {
    if (field.getAnnotation(Stage.class) != null)
        return getStageName(field);
    return capitalize(field.getSimpleName());
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:6,代码来源:StageModel.java


示例19: reassignDefault

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
public static <T> CtAssignment<T, T> reassignDefault(CtField<T> field) {
    Factory f = field.getFactory();
    return f.Code().createVariableAssignment(
            field.getReference(), false, f.Core().clone(field.getDefaultExpression()));
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:6,代码来源:SpoonUtils.java


示例20: getDeepDef

import spoon.reflect.declaration.CtField; //导入依赖的package包/类
/**
 * Get attributes & methods parameters dependences for this variable access
 */
public Set<CtVariable<?>> getDeepDef(CtVariableAccess<?> var) {
	Set<CtVariable<?>> res = new HashSet<>();

	Set<CtCodeElement> defs = getReachingDef(var);
	if (defs != null) {
		for (CtCodeElement def : defs) {
			List<CtVariableAccess<?>> topVars = getUsedVariables(def);
			if (topVars != null) {
				for (CtVariableAccess<?> topVar : topVars) {
					res.addAll(getDeepDef(topVar));
				}
			}
		}
	} else {
		CtVariable<?> decl = var.getVariable().getDeclaration();
		if (decl instanceof CtField || decl instanceof CtParameter) {
			res.add(decl);
		}

		/*
		 * Workaround to fix a bug found in Spoon: Getting declaration from
		 * a anonymous
		 */
		if (decl == null) {
			if (var.getVariable() instanceof CtParameterReference) {
				CtParameterReference<?> p = (CtParameterReference<?>) var.getVariable();
				// String name = p.getDeclaringExecutable().getSimpleName();
				String decType = p.getDeclaringExecutable().getDeclaringType().getSimpleName();

				if (decType.length() == 0) {
					CtExecutable<?> exec = getDeclaringMethod(var);
					if (exec != null) {
						List<CtParameter<?>> params = exec.getParameters();
						for (CtParameter<?> param : params) {
							if (var.getVariable().getSimpleName().equals(param.getSimpleName())) {
								res.add(param);
								break;
							}
						}
					}
				}
			}
			// else if (var.getVariable() instanceof CtFieldReference){
			// FIXME get declaration for variable found in this kind of
			// expression: java.awt.event.KeyEvent.VK_ESCAPE
			// }
		}

	}

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DatabaseDriver类代码示例发布时间:2022-05-23
下一篇:
Java Criteria类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap