private boolean isWanted(CsmReference ref, CsmFile file) { CsmObject csmObject = ref.getReferencedObject(); return CsmKindUtilities.isFunction(csmObject); } }
private CsmFunction getEnclosingFunction(CsmReference ref){ CsmObject o = ref.getClosestTopLevelObject(); if (CsmKindUtilities.isFunction(o)) { return (CsmFunction) o; } return null; }
private boolean checkDefinitions(CsmObject targetDef, CsmObject referencedObj) { if (targetDef == null) { return false; } if (targetDef.equals(referencedObj)) { return true; } if (CsmKindUtilities.isFunction(referencedObj)) { CsmFunctionDefinition refDef = ((CsmFunction) referencedObj).getDefinition(); return targetDef.equals(refDef); } return false; }
private static CharSequence getName(OffsetableDeclarationBase<?> obj) { if (CsmKindUtilities.isFunction(obj) && obj instanceof FunctionImpl) { FunctionImpl fun = (FunctionImpl) obj; StringBuilder sb = new StringBuilder(fun.getName()); CharSequence signature = fun.getSignatureForUID(); if (signature != null) { sb.append(signature); } return sb.toString(); } return obj.getName(); }
@Override public List<? extends CsmOffsetable> getBlocks(CsmFile csmFile) { Collection<CsmReference> references = CsmReferenceResolver.getDefault().getReferences(csmFile); List<CsmOffsetable> res = new ArrayList<CsmOffsetable>(); for(CsmReference ref : references) { if (CsmKindUtilities.isFunction(ref.getReferencedObject())){ res.add(ref); } } return res; }
/** Get the class or function definition from the known scope */ public CsmOffsetableDeclaration getDefinition(CsmScope scope) { while (CsmKindUtilities.isScopeElement(scope) && (!CsmKindUtilities.isClass(scope) && !CsmKindUtilities.isFunction(scope))) { scope = ((CsmScopeElement) scope).getScope(); } return (CsmKindUtilities.isClass(scope) || CsmKindUtilities.isFunction(scope)) ? (CsmOffsetableDeclaration) scope : null; }
private void rememberObject(CsmObject obj) { if (CsmKindUtilities.isNamespaceDefinition(obj)) { enclosingNS = (CsmNamespaceDefinition) obj; } else if (CsmKindUtilities.isClass(obj)) { enclosingClass = (CsmClass)obj; } else if (CsmKindUtilities.isFunction(obj)) { enclosingFun = (CsmFunction) obj; } }
@Override public boolean canChangeParameters(Lookup lookup) { Collection<? extends Node> nodes = new HashSet<Node>(lookup.lookupAll(Node.class)); if(nodes.size() != 1) { return false; } CsmObject ref = CsmRefactoringUtils.findContextObject(lookup); if (RefactoringActionsProvider.isFromEditor(lookup)) { // if inside function but not in destructor => allow to change it's parameters CsmContext editorContext = CsmContext.create(lookup); if (editorContext != null) { CsmFunction fun = editorContext.getEnclosingFunction(); return fun != null; } return false; } else { return CsmKindUtilities.isFunction(ref); } }
private static boolean isFileLocalElement(CsmObject decl) { assert decl != null; if (CsmBaseUtilities.isDeclarationFromUnnamedNamespace(decl)) { return true; } else if (CsmKindUtilities.isFileLocalVariable(decl)) { return true; } else if (CsmKindUtilities.isFunction(decl)) { return CsmBaseUtilities.isFileLocalFunction(((CsmFunction) decl)); } return false; }
static CsmObject createInstantiation(Context context, CsmTemplate template, CsmCompletionExpression exp, List<CsmType> typeList) { if (exp != null || !typeList.isEmpty() || context.getContextInstantiations() != null) { CsmInstantiationProvider ip = CsmInstantiationProvider.getDefault(); List<CsmSpecializationParameter> params = new ArrayList<CsmSpecializationParameter>(); params.addAll(collectInstantiationParameters(context, template, ip, exp)); if (CsmKindUtilities.isFunction(template)) { params.addAll(collectInstantiationParameters(context, ip, (CsmFunction)template, params.size(), typeList)); } CsmObject instantiation = ip.instantiate(template, params); if (CsmKindUtilities.isTemplate(instantiation)) { List<CsmInstantiation> contextInstantiations = context.getContextInstantiations(); if (contextInstantiations != null && !contextInstantiations.isEmpty()) { ListIterator<CsmInstantiation> iter = contextInstantiations.listIterator(contextInstantiations.size()); while (iter.hasPrevious()) { instantiation = ip.instantiate((CsmTemplate) instantiation, iter.previous()); } } } return instantiation; } return null; }
/** * Checks local statements for function or variable declaration with name */ private boolean isLocalVariableOrFunction(CharSequence name, CsmScope scope) { while(CsmKindUtilities.isStatement(scope)) { scope = ((CsmStatement) scope).getScope(); } if(CsmKindUtilities.isFunction(scope)) { CsmFunction fun = (CsmFunction) scope; for (CsmParameter param : fun.getParameters()) { if (param.getQualifiedName().toString().equals(name)) { return true; } } } return false; }
private void processRefactoredReferences(List<CsmReference> sortedRefs, FileObject fo, CloneableEditorSupport ces, ModificationResult mr, AtomicReference<Problem> outProblem) { for (CsmReference curRef : sortedRefs) { CsmObject encl = CsmRefactoringUtils.getEnclosingElement(curRef); // change in functions, but not in constructors/destructors if (CsmKindUtilities.isFunction(encl)) { if (!CsmKindUtilities.isConstructor(encl) && CsmKindUtilities.isDestructor(encl) && !encl.equals(refactoring.getDefaultGetter()) && !encl.equals(refactoring.getDefaultSetter())) { // FieldAccessInfo fldAccess = prepareFieldAccessInfo(curRef, getDoc(ces)); } } } } // @Override
private CsmScope getDeclarationScope(CsmObject decl) { assert decl != null; CsmObject scopeElem = decl; while (CsmKindUtilities.isScopeElement(scopeElem)) { CsmScope scope = ((CsmScopeElement)scopeElem).getScope(); if (CsmKindUtilities.isFunction(scope)) { return ((CsmFunction)scope); } else if (CsmKindUtilities.isScopeElement(scope)) { scopeElem = ((CsmScopeElement)scope); } else { break; } } return null; }
private static boolean isLocalElement(CsmObject decl) { assert decl != null; CsmObject scopeElem = decl; while (CsmKindUtilities.isScopeElement(scopeElem)) { CsmScope scope = ((CsmScopeElement) scopeElem).getScope(); if (CsmKindUtilities.isFunction(scope)) { return true; } else if (CsmKindUtilities.isScopeElement(scope)) { scopeElem = ((CsmScopeElement) scope); } else { break; } } return false; }
/*package*/ static boolean isLangContainerFeature(CsmObject obj) { assert obj != null; return CsmKindUtilities.isFunction(obj) || CsmKindUtilities.isClass(obj) || CsmKindUtilities.isEnum(obj) || CsmKindUtilities.isNamespaceDefinition(obj) || CsmKindUtilities.isFile(obj); }
private static CsmDeclaration findInnerDeclaration(CsmFile contextFile, CsmDeclaration decl, final CsmContext context, final int offset) { CsmDeclaration innerDecl = null; assert (decl != null) : "can't be null declaration"; if (!CsmKindUtilities.isFunction(decl) || CsmOffsetUtilities.isInFunctionScope((CsmFunction)decl, offset)) { // add declaration scope to context CsmContextUtilities.updateContext(decl, offset, context); // we are inside declaration, but try to search deeper innerDecl = findInnerDeclaration(contextFile, decl, offset, context); } else { context.setLastObject(decl); } innerDecl = innerDecl != null ? innerDecl : decl; // we can break loop, because list of declarations is sorted // by offset and we found already one of container declaration return innerDecl; }
public static CompletionDocumentation getDocumentation(CsmObject obj, CsmFile file) throws IOException { if (CsmKindUtilities.isFunction(obj) && !CsmKindUtilities.isClassMember(obj)) { CsmFunction function = (CsmFunction) obj; return getDoc(function.getQualifiedName().toString(), file); } else if (CsmKindUtilities.isClass(obj)) { CsmClass cls = (CsmClass) obj; return getDoc(cls.getQualifiedName().toString(), file); } else if (CsmKindUtilities.isClassMember(obj)) { CsmScope scope = ((CsmMember) obj).getScope(); if (CsmKindUtilities.isClass(scope)) { CsmClass cls = (CsmClass) scope; return getDoc(cls.getQualifiedName().toString(), file); } } return null; }
FileReferencesContext(CsmScope csmScope){ if (CsmKindUtilities.isFile(csmScope)) { csmFile = (CsmFile) csmScope; } else if (CsmKindUtilities.isFunction(csmScope)) { csmFile = ((CsmFunction)csmScope).getContainingFile(); } else if (CsmKindUtilities.isOffsetable(csmScope)) { csmFile = ((CsmOffsetable)csmScope).getContainingFile(); } //lastOffset = 0; CsmListeners.getDefault().addProgressListener(this); }
public static CsmFunction getFunction(CsmContext context, boolean inScope) { CsmFunction result = null; for (int i = context.size() - 1; 0 <= i; --i) { CsmScope scope = context.get(i).getScope(); int offset = context.getOffset(); // if (CsmKindUtilities.isClass(scope) && CsmOffsetUtilities.isInClassScope((CsmClass)scope, offset)) { // break; // } else if (CsmKindUtilities.isFunction(scope)) { if (!inScope || CsmOffsetUtilities.isInFunctionScope((CsmFunction)scope, offset)) { result = (CsmFunction)scope; if (!CsmKindUtilities.isLambda(scope)) { return result; } } } } return result; }
@Override public CharSequence getQualifiedName() { CsmScope s = getScope(); if (CsmKindUtilities.isFunction(s)) { return CharSequences.create(CharSequenceUtils.concatenate(((CsmFunction)s).getQualifiedName(),"::",name)); // NOI18N } else if (CsmKindUtilities.isClass(s)) { return CharSequences.create(CharSequenceUtils.concatenate(((CsmClass)s).getQualifiedName(),"::",name)); // NOI18N } return name; }