本文整理汇总了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;
});
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
示例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;
}
示例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()));
}
}
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
}