org.eclipse.jdt.internal.compiler.ast.FieldDeclaration Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.FieldDeclaration. 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: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
    Annotation[] annotations = fieldDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        FieldBinding fieldBinding = fieldDeclaration.binding;
        if (fieldBinding == null) {
            return false;
        }

        String fqn = getFqn(scope);
        ClassKind kind = scope.referenceContext instanceof TypeDeclaration ?
                ClassKind.forType((TypeDeclaration) scope.referenceContext) :
                ClassKind.CLASS;
        Item item = FieldItem.create(fqn, kind, fieldBinding);
        if (item != null && fqn != null) {
            addItem(fqn, item);
            addAnnotations(annotations, item);
        }
    }
    return false;
}
 
Example #2
Source File: RecoveredInitializer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public RecoveredElement add(FieldDeclaration newFieldDeclaration, int bracketBalanceValue) {
	resetPendingModifiers();

	/* local variables inside initializer can only be final and non void */
	char[][] fieldTypeName;
	if ((newFieldDeclaration.modifiers & ~ClassFileConstants.AccFinal) != 0 /* local var can only be final */
			|| (newFieldDeclaration.type == null) // initializer
			|| ((fieldTypeName = newFieldDeclaration.type.getTypeName()).length == 1 // non void
				&& CharOperation.equals(fieldTypeName[0], TypeBinding.VOID.sourceName()))){
		if (this.parent == null) return this; // ignore
		this.updateSourceEndIfNecessary(previousAvailableLineEnd(newFieldDeclaration.declarationSourceStart - 1));
		return this.parent.add(newFieldDeclaration, bracketBalanceValue);
	}

	/* default behavior is to delegate recording to parent if any,
	do not consider elements passed the known end (if set)
	it must be belonging to an enclosing element
	*/
	if (this.fieldDeclaration.declarationSourceEnd > 0
			&& newFieldDeclaration.declarationSourceStart > this.fieldDeclaration.declarationSourceEnd){
		if (this.parent == null) return this; // ignore
		return this.parent.add(newFieldDeclaration, bracketBalanceValue);
	}
	// still inside initializer, treat as local variable
	return this; // ignore
}
 
Example #3
Source File: SingletonEclipseHandler.java    From tutorials with MIT License 6 votes vote down vote up
private void addFactoryMethod(EclipseNode singletonClass, TypeDeclaration astNode, TypeReference typeReference, TypeDeclaration innerClass, FieldDeclaration field) {
    MethodDeclaration factoryMethod = new MethodDeclaration(astNode.compilationResult);
    factoryMethod.modifiers = AccStatic | ClassFileConstants.AccPublic;
    factoryMethod.returnType = typeReference;
    factoryMethod.sourceStart = astNode.sourceStart;
    factoryMethod.sourceEnd = astNode.sourceEnd;
    factoryMethod.selector = "getInstance".toCharArray();
    factoryMethod.bits = ECLIPSE_DO_NOT_TOUCH_FLAG;

    long pS = factoryMethod.sourceStart;
    long pE = factoryMethod.sourceEnd;
    long p = (long) pS << 32 | pE;

    FieldReference ref = new FieldReference(field.name, p);
    ref.receiver = new SingleNameReference(innerClass.name, p);

    ReturnStatement statement = new ReturnStatement(ref, astNode.sourceStart, astNode.sourceEnd);

    factoryMethod.statements = new Statement[]{statement};

    EclipseHandlerUtil.injectMethod(singletonClass, factoryMethod);
}
 
Example #4
Source File: Eclipse.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * Searches the given field node for annotations and returns each one that matches the provided regular expression pattern.
 * 
 * Only the simple name is checked - the package and any containing class are ignored.
 */
public static Annotation[] findAnnotations(FieldDeclaration field, Pattern namePattern) {
	List<Annotation> result = new ArrayList<Annotation>();
	if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY;
	for (Annotation annotation : field.annotations) {
		TypeReference typeRef = annotation.type;
		if (typeRef != null && typeRef.getTypeName() != null) {
			char[][] typeName = typeRef.getTypeName();
			String suspect = new String(typeName[typeName.length - 1]);
			if (namePattern.matcher(suspect).matches()) {
				result.add(annotation);
			}
		}
	}	
	return result.toArray(EMPTY_ANNOTATIONS_ARRAY);
}
 
Example #5
Source File: EclipseAST.java    From EasyMPermission with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
	switch (kind) {
	case COMPILATION_UNIT:
		return buildCompilationUnit((CompilationUnitDeclaration) node);
	case TYPE:
		return buildType((TypeDeclaration) node);
	case FIELD:
		return buildField((FieldDeclaration) node);
	case INITIALIZER:
		return buildInitializer((Initializer) node);
	case METHOD:
		return buildMethod((AbstractMethodDeclaration) node);
	case ARGUMENT:
		return buildLocal((Argument) node, kind);
	case LOCAL:
		return buildLocal((LocalDeclaration) node, kind);
	case STATEMENT:
		return buildStatement((Statement) node);
	case ANNOTATION:
		return buildAnnotation((Annotation) node, false);
	default:
		throw new AssertionError("Did not expect to arrive here: " + kind);
	}
}
 
Example #6
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void removeFields(TypeDeclaration typeDeclaration) {
	int start = typeDeclaration.declarationSourceStart;
	int end = typeDeclaration.declarationSourceEnd;

	FieldDeclaration[] fieldDeclarations = typeDeclaration.fields;
	if (fieldDeclarations != null) {
		for (int i = 0; i < fieldDeclarations.length; i++) {
			int j = indexOfFisrtNameAfter(start);
			done : while (j != -1) {
				int nameStart = this.potentialVariableNameStarts[j];
				if (start <= nameStart && nameStart <= end) {
					if (CharOperation.equals(this.potentialVariableNames[j], fieldDeclarations[i].name, false)) {
						removeNameAt(j);
					}
				}

				if (end < nameStart) break done;
				j = indexOfNextName(j);
			}
		}
	}
}
 
Example #7
Source File: RecoveredBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public RecoveredElement add(FieldDeclaration fieldDeclaration, int bracketBalanceValue) {
	resetPendingModifiers();

	/* local variables inside method can only be final and non void */
	char[][] fieldTypeName;
	if ((fieldDeclaration.modifiers & ~ClassFileConstants.AccFinal) != 0 // local var can only be final
		|| (fieldDeclaration.type == null) // initializer
		|| ((fieldTypeName = fieldDeclaration.type.getTypeName()).length == 1 // non void
			&& CharOperation.equals(fieldTypeName[0], TypeBinding.VOID.sourceName()))){
		this.updateSourceEndIfNecessary(previousAvailableLineEnd(fieldDeclaration.declarationSourceStart - 1));
		return this.parent.add(fieldDeclaration, bracketBalanceValue);
	}

	/* do not consider a local variable starting passed the block end (if set)
		it must be belonging to an enclosing block */
	if (this.blockDeclaration.sourceEnd != 0
		&& fieldDeclaration.declarationSourceStart > this.blockDeclaration.sourceEnd){
		return this.parent.add(fieldDeclaration, bracketBalanceValue);
	}

	// ignore the added field, since indicates a local variable behind recovery point
	// which thus got parsed as a field reference. This can happen if restarting after
	// having reduced an assistNode to get the following context (see 1GEK7SG)
	return this;
}
 
Example #8
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private ASTNode getEnclosingDeclaration() {
	int i = this.parentsPtr;
	while (i > -1) {
		ASTNode parent = this.parents[i];
		if (parent instanceof AbstractMethodDeclaration) {
			return parent;
		} else if (parent instanceof Initializer) {
			return parent;
		} else if (parent instanceof FieldDeclaration) {
			return parent;
		} else if (parent instanceof TypeDeclaration) {
			return parent;
		}
		i--;
	}
	return null;
}
 
Example #9
Source File: SingletonEclipseHandler.java    From tutorials with MIT License 6 votes vote down vote up
private FieldDeclaration addInstanceVar(ConstructorDeclaration constructor, TypeReference typeReference, TypeDeclaration innerClass) {
    FieldDeclaration field = new FieldDeclaration();
    field.modifiers = AccPrivate | AccStatic | AccFinal;
    field.name = "INSTANCE".toCharArray();

    field.type = typeReference;

    AllocationExpression exp = new AllocationExpression();
    exp.type = typeReference;
    exp.binding = constructor.binding;
    exp.sourceStart = innerClass.sourceStart;
    exp.sourceEnd = innerClass.sourceEnd;

    field.initialization = exp;
    return field;
}
 
Example #10
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * Given a list of field names and a node referring to a type, finds each name in the list that does not match a field within the type.
 */
public static List<Integer> createListOfNonExistentFields(List<String> list, EclipseNode type, boolean excludeStandard, boolean excludeTransient) {
	boolean[] matched = new boolean[list.size()];
	
	for (EclipseNode child : type.down()) {
		if (list.isEmpty()) break;
		if (child.getKind() != Kind.FIELD) continue;
		if (excludeStandard) {
			if ((((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccStatic) != 0) continue;
			if (child.getName().startsWith("$")) continue;
		}
		if (excludeTransient && (((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccTransient) != 0) continue;
		int idx = list.indexOf(child.getName());
		if (idx > -1) matched[idx] = true;
	}
	
	List<Integer> problematic = new ArrayList<Integer>();
	for (int i = 0 ; i < list.size() ; i++) {
		if (!matched[i]) problematic.add(i);
	}
	
	return problematic;
}
 
Example #11
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * Checks if there is a field with the provided name.
 * 
 * @param fieldName the field name to check for.
 * @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
 */
public static MemberExistsResult fieldExists(String fieldName, EclipseNode node) {
	while (node != null && !(node.get() instanceof TypeDeclaration)) {
		node = node.up();
	}
	
	if (node != null && node.get() instanceof TypeDeclaration) {
		TypeDeclaration typeDecl = (TypeDeclaration)node.get();
		if (typeDecl.fields != null) for (FieldDeclaration def : typeDecl.fields) {
			char[] fName = def.name;
			if (fName == null) continue;
			if (fieldName.equals(new String(fName))) {
				return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
			}
		}
	}
	
	return MemberExistsResult.NOT_EXISTS;
}
 
Example #12
Source File: HandleFieldDefaults.java    From EasyMPermission with MIT License 6 votes vote down vote up
public void setFieldDefaultsForField(EclipseNode fieldNode, ASTNode pos, AccessLevel level, boolean makeFinal) {
	FieldDeclaration field = (FieldDeclaration) fieldNode.get();
	if (level != null && level != AccessLevel.NONE) {
		if ((field.modifiers & (ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected)) == 0) {
			if (!hasAnnotation(PackagePrivate.class, fieldNode)) {
				field.modifiers |= EclipseHandlerUtil.toEclipseModifier(level);
			}
		}
	}
	
	if (makeFinal && (field.modifiers & ClassFileConstants.AccFinal) == 0) {
		if (!hasAnnotation(NonFinal.class, fieldNode)) {
			field.modifiers |= ClassFileConstants.AccFinal;
		}
	}
	
	fieldNode.rebuild();
}
 
Example #13
Source File: EcjMultilineProcessor.java    From datafu with Apache License 2.0 6 votes vote down vote up
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
  Set<? extends Element> fields = roundEnv.getElementsAnnotatedWith(Multiline.class);

  for (Element field : fields) {
    String docComment = elementUtils.getDocComment(field);

    if (null != docComment) {
      VariableElementImpl fieldElem = (VariableElementImpl) field;
      FieldBinding biding = (FieldBinding) fieldElem._binding;
      FieldDeclaration decl = biding.sourceField();
      StringLiteral string = new StringLiteral(docComment.toCharArray(), decl.sourceStart, decl.sourceEnd, decl.sourceStart);
      decl.initialization = string;
    }
  }
  return true;
}
 
Example #14
Source File: EclipseNode.java    From EasyMPermission with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override public String getName() {
	final char[] n;
	if (node instanceof TypeDeclaration) n = ((TypeDeclaration)node).name;
	else if (node instanceof FieldDeclaration) n = ((FieldDeclaration)node).name;
	else if (node instanceof AbstractMethodDeclaration) n = ((AbstractMethodDeclaration)node).selector;
	else if (node instanceof LocalDeclaration) n = ((LocalDeclaration)node).name;
	else n = null;
	
	return n == null ? null : new String(n);
}
 
Example #15
Source File: EclipseNode.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override protected boolean fieldContainsAnnotation(ASTNode field, ASTNode annotation) {
	if (!(field instanceof FieldDeclaration)) return false;
	FieldDeclaration f = (FieldDeclaration) field;
	if (f.annotations == null) return false;
	for (Annotation childAnnotation : f.annotations) {
		if (childAnnotation == annotation) return true;
	}
	return false;
}
 
Example #16
Source File: EclipseNode.java    From EasyMPermission with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected boolean calculateIsStructurallySignificant(ASTNode parent) {
	if (node instanceof TypeDeclaration) return true;
	if (node instanceof AbstractMethodDeclaration) return true;
	if (node instanceof FieldDeclaration) return true;
	if (node instanceof LocalDeclaration) return true;
	if (node instanceof CompilationUnitDeclaration) return true;
	return false;
}
 
Example #17
Source File: NodeSearcher.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(
	FieldDeclaration fieldDeclaration,
	MethodScope scope) {
		if (fieldDeclaration.declarationSourceStart <= this.position
			&& this.position <= fieldDeclaration.declarationSourceEnd) {
				this.found = fieldDeclaration;
				return false;
		}
		return true;
}
 
Example #18
Source File: SourceElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void visitIfNeeded(FieldDeclaration field, TypeDeclaration declaringType) {
	if (this.localDeclarationVisitor != null
		&& (field.bits & ASTNode.HasLocalType) != 0) {
			if (field.initialization != null) {
				try {
					this.localDeclarationVisitor.pushDeclaringType(declaringType);
					field.initialization.traverse(this.localDeclarationVisitor, (MethodScope) null);
				} finally {
					this.localDeclarationVisitor.popDeclaringType();
				}
			}
	}
}
 
Example #19
Source File: BinaryTypeConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private FieldDeclaration convert(IField field, IType type) throws JavaModelException {
	TypeReference typeReference = createTypeReference(field.getTypeSignature());
	if (typeReference == null) return null;
	FieldDeclaration fieldDeclaration = new FieldDeclaration();

	fieldDeclaration.name = field.getElementName().toCharArray();
	fieldDeclaration.type = typeReference;
	fieldDeclaration.modifiers = field.getFlags();

	return fieldDeclaration;
}
 
Example #20
Source File: OrLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int match(FieldDeclaration node, MatchingNodeSet nodeSet) {
	int level = IMPOSSIBLE_MATCH;
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
		int newLevel = this.patternLocators[i].match(node, nodeSet);
		if (newLevel > level) {
			if (newLevel == ACCURATE_MATCH) return ACCURATE_MATCH;
			level = newLevel;
		}
	}
	return level;
}
 
Example #21
Source File: RecoveredUnit.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RecoveredElement add(FieldDeclaration fieldDeclaration, int bracketBalanceValue) {

	/* attach it to last type - if any */
	if (this.typeCount > 0){
		RecoveredType type = this.types[this.typeCount -1];
		type.bodyEnd = 0; // reset position
		type.typeDeclaration.declarationSourceEnd = 0; // reset position
		type.typeDeclaration.bodyEnd = 0;

		resetPendingModifiers();

		return type.add(fieldDeclaration, bracketBalanceValue);
	}
	return this; // ignore
}
 
Example #22
Source File: EclipseSingularsRecipes.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void setGeneratedByRecursive(ASTNode target) {
	SetGeneratedByVisitor visitor = new SetGeneratedByVisitor(source);
	
	if (target instanceof AbstractMethodDeclaration) {
		((AbstractMethodDeclaration) target).traverse(visitor, (ClassScope) null);
	} else if (target instanceof FieldDeclaration) {
		((FieldDeclaration) target).traverse(visitor, (MethodScope) null);
	} else {
		target.traverse(visitor, null);
	}
}
 
Example #23
Source File: HandleSynchronized.java    From EasyMPermission with MIT License 5 votes vote down vote up
public char[] createLockField(AnnotationValues<Synchronized> annotation, EclipseNode annotationNode, boolean isStatic, boolean reportErrors) {
	char[] lockName = annotation.getInstance().value().toCharArray();
	Annotation source = (Annotation) annotationNode.get();
	boolean autoMake = false;
	if (lockName.length == 0) {
		autoMake = true;
		lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
	}
	
	if (fieldExists(new String(lockName), annotationNode) == MemberExistsResult.NOT_EXISTS) {
		if (!autoMake) {
			if (reportErrors) annotationNode.addError(String.format("The field %s does not exist.", new String(lockName)));
			return null;
		}
		FieldDeclaration fieldDecl = new FieldDeclaration(lockName, 0, -1);
		setGeneratedBy(fieldDecl, source);
		fieldDecl.declarationSourceEnd = -1;
		
		fieldDecl.modifiers = (isStatic ? Modifier.STATIC : 0) | Modifier.FINAL | Modifier.PRIVATE;
		
		//We use 'new Object[0];' because unlike 'new Object();', empty arrays *ARE* serializable!
		ArrayAllocationExpression arrayAlloc = new ArrayAllocationExpression();
		setGeneratedBy(arrayAlloc, source);
		arrayAlloc.dimensions = new Expression[] { makeIntLiteral("0".toCharArray(), source) };
		arrayAlloc.type = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { 0, 0, 0 });
		setGeneratedBy(arrayAlloc.type, source);
		fieldDecl.type = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { 0, 0, 0 });
		setGeneratedBy(fieldDecl.type, source);
		fieldDecl.initialization = arrayAlloc;
		// TODO temporary workaround for issue 217. http://code.google.com/p/projectlombok/issues/detail?id=217
		// injectFieldSuppressWarnings(annotationNode.up().up(), fieldDecl);
		injectField(annotationNode.up().up(), fieldDecl);
	}
	
	return lockName;
}
 
Example #24
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void fixPositions(FieldDeclaration node) {
	node.sourceEnd = sourceEnd;
	node.sourceStart = sourceStart;
	node.declarationEnd = sourceEnd;
	node.declarationSourceEnd = sourceEnd;
	node.declarationSourceStart = sourceStart;
	node.modifiersSourceStart = sourceStart;
	node.endPart1Position = sourceEnd;
	node.endPart2Position = sourceEnd;
}
 
Example #25
Source File: HandleBuilder.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void generateBuilderFields(EclipseNode builderType, List<BuilderFieldData> builderFields, ASTNode source) {
	List<EclipseNode> existing = new ArrayList<EclipseNode>();
	for (EclipseNode child : builderType.down()) {
		if (child.getKind() == Kind.FIELD) existing.add(child);
	}
	
	top:
	for (BuilderFieldData bfd : builderFields) {
		if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
			bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType));
		} else {
			for (EclipseNode exists : existing) {
				char[] n = ((FieldDeclaration) exists.get()).name;
				if (Arrays.equals(n, bfd.name)) {
					bfd.createdFields.add(exists);
					continue top;
				}
			}
			
			FieldDeclaration fd = new FieldDeclaration(bfd.name, 0, 0);
			fd.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
			fd.modifiers = ClassFileConstants.AccPrivate;
			fd.type = copyType(bfd.type);
			fd.traverse(new SetGeneratedByVisitor(source), (MethodScope) null);
			bfd.createdFields.add(injectFieldAndMarkGenerated(builderType, fd));
		}
	}
}
 
Example #26
Source File: FieldBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Compute the tagbits for standard annotations. For source types, these could require
 * lazily resolving corresponding annotation nodes, in case of forward references.
 * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits()
 */
public long getAnnotationTagBits() {
	FieldBinding originalField = original();
	if ((originalField.tagBits & TagBits.AnnotationResolved) == 0 && originalField.declaringClass instanceof SourceTypeBinding) {
		ClassScope scope = ((SourceTypeBinding) originalField.declaringClass).scope;
		if (scope == null) { // synthetic fields do not have a scope nor any annotations
			this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
			return 0;
		}
		TypeDeclaration typeDecl = scope.referenceContext;
		FieldDeclaration fieldDecl = typeDecl.declarationOf(originalField);
		if (fieldDecl != null) {
			MethodScope initializationScope = isStatic() ? typeDecl.staticInitializerScope : typeDecl.initializerScope;
			FieldBinding previousField = initializationScope.initializedField;
			int previousFieldID = initializationScope.lastVisibleFieldID;
			try {
				initializationScope.initializedField = originalField;
				initializationScope.lastVisibleFieldID = originalField.id;
				ASTNode.resolveAnnotations(initializationScope, fieldDecl.annotations, originalField);
			} finally {
				initializationScope.initializedField = previousField;
				initializationScope.lastVisibleFieldID = previousFieldID;
			}
		}
	}
	return originalField.tagBits;
}
 
Example #27
Source File: RecoveredElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RecoveredElement add(FieldDeclaration fieldDeclaration, int bracketBalanceValue) {

	/* default behavior is to delegate recording to parent if any */
	resetPendingModifiers();
	if (this.parent == null) return this; // ignore
	this.updateSourceEndIfNecessary(previousAvailableLineEnd(fieldDeclaration.declarationSourceStart - 1));
	return this.parent.add(fieldDeclaration, bracketBalanceValue);
}
 
Example #28
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
public static boolean filterField(FieldDeclaration declaration, boolean skipStatic) {
	// Skip the fake fields that represent enum constants.
	if (declaration.initialization instanceof AllocationExpression &&
			((AllocationExpression)declaration.initialization).enumConstant != null) return false;
	
	if (declaration.type == null) return false;
	
	// Skip fields that start with $
	if (declaration.name.length > 0 && declaration.name[0] == '$') return false;
	
	// Skip static fields.
	if (skipStatic && (declaration.modifiers & ClassFileConstants.AccStatic) != 0) return false;
	
	return true;
}
 
Example #29
Source File: RecoveredMethod.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RecoveredElement add(FieldDeclaration fieldDeclaration, int bracketBalanceValue) {
	resetPendingModifiers();

	/* local variables inside method can only be final and non void */
	char[][] fieldTypeName;
	if ((fieldDeclaration.modifiers & ~ClassFileConstants.AccFinal) != 0 // local var can only be final
		|| (fieldDeclaration.type == null) // initializer
		|| ((fieldTypeName = fieldDeclaration.type.getTypeName()).length == 1 // non void
			&& CharOperation.equals(fieldTypeName[0], TypeBinding.VOID.sourceName()))){
		if (this.parent == null){
			return this; // ignore
		} else {
			this.updateSourceEndIfNecessary(previousAvailableLineEnd(fieldDeclaration.declarationSourceStart - 1));
			return this.parent.add(fieldDeclaration, bracketBalanceValue);
		}
	}
	/* default behavior is to delegate recording to parent if any,
	do not consider elements passed the known end (if set)
	it must be belonging to an enclosing element
	*/
	if (this.methodDeclaration.declarationSourceEnd > 0
		&& fieldDeclaration.declarationSourceStart
			> this.methodDeclaration.declarationSourceEnd){
		if (this.parent == null){
			return this; // ignore
		} else {
			return this.parent.add(fieldDeclaration, bracketBalanceValue);
		}
	}
	/* consider that if the opening brace was not found, it is there */
	if (!this.foundOpeningBrace){
		this.foundOpeningBrace = true;
		this.bracketBalance++;
	}
	// still inside method, treat as local variable
	return this; // ignore
}
 
Example #30
Source File: EclipseGuavaSingularizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public List<EclipseNode> generateFields(SingularData data, EclipseNode builderType) {
	char[][] tokenizedName = makeGuavaTypeName(getSimpleTargetTypeName(data), true);
	TypeReference type = new QualifiedTypeReference(tokenizedName, NULL_POSS);
	type = addTypeArgs(isMap() ? 2 : 1, false, builderType, type, data.getTypeArgs());
	
	FieldDeclaration buildField = new FieldDeclaration(data.getPluralName(), 0, -1);
	buildField.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	buildField.modifiers = ClassFileConstants.AccPrivate;
	buildField.declarationSourceEnd = -1;
	buildField.type = type;
	data.setGeneratedByRecursive(buildField);
	return Collections.singletonList(injectFieldAndMarkGenerated(builderType, buildField));
}